9 #include "src/globals.h" 10 #include "src/third_party/utf8-decoder/utf8-decoder.h" 11 #include "src/utils.h" 19 typedef unsigned int uchar;
20 typedef unsigned char byte;
28 template <
class T,
int size = 256>
32 inline bool get(uchar c);
36 bool CalculateValue(uchar c);
40 : bit_field_(CodePointField::encode(0) | ValueField::encode(0)) {}
41 inline CacheEntry(uchar code_point,
bool value)
43 CodePointField::encode(CodePointField::kMask & code_point) |
44 ValueField::encode(value)) {
45 DCHECK_IMPLIES((CodePointField::kMask & code_point) != code_point,
46 code_point == static_cast<uchar>(-1));
49 uchar code_point()
const {
return CodePointField::decode(bit_field_); }
50 bool value()
const {
return ValueField::decode(bit_field_); }
58 static const int kSize = size;
59 static const int kMask = kSize - 1;
60 CacheEntry entries_[kSize];
68 template <
class T,
int size = 256>
72 inline int get(uchar c, uchar n, uchar* result);
75 int CalculateValue(uchar c, uchar n, uchar* result);
77 inline CacheEntry() : code_point_(kNoChar), offset_(0) { }
78 inline CacheEntry(uchar code_point,
signed offset)
79 : code_point_(code_point),
83 static const int kNoChar = (1 << 21) - 1;
85 static const int kSize = size;
86 static const int kMask = kSize - 1;
87 CacheEntry entries_[kSize];
94 static int GetByteCount();
95 static const uchar kMaxCodePoint;
101 static const int kNoPreviousCharacter = -1;
102 static inline bool IsSurrogatePair(
int lead,
int trail) {
103 return IsLeadSurrogate(lead) && IsTrailSurrogate(trail);
105 static inline bool IsLeadSurrogate(
int code) {
106 return (code & 0xfc00) == 0xd800;
108 static inline bool IsTrailSurrogate(
int code) {
109 return (code & 0xfc00) == 0xdc00;
112 static inline int CombineSurrogatePair(uchar lead, uchar trail) {
113 return 0x10000 + ((lead & 0x3ff) << 10) + (trail & 0x3ff);
115 static const uchar kMaxNonSurrogateCharCode = 0xffff;
121 static const int kMaxExtraUtf8BytesForOneUtf16CodeUnit = 3;
124 static const int kUtf8BytesToCodeASurrogate = 3;
125 static inline uint16_t LeadSurrogate(
uint32_t char_code) {
126 return 0xd800 + (((char_code - 0x10000) >> 10) & 0x3ff);
128 static inline uint16_t TrailSurrogate(
uint32_t char_code) {
129 return 0xdc00 + (char_code & 0x3ff);
135 using State = Utf8DfaDecoder::State;
137 static inline uchar Length(uchar chr,
int previous);
138 static inline unsigned EncodeOneByte(
char* out, uint8_t c);
139 static inline unsigned Encode(
char* out,
142 bool replace_invalid =
false);
143 static uchar CalculateValue(
const byte* str,
size_t length,
size_t* cursor);
147 static const uchar kBadChar = 0xFFFD;
148 static const uchar kBufferEmpty = 0x0;
149 static const uchar kIncomplete = 0xFFFFFFFC;
150 static const unsigned kMaxEncodedSize = 4;
151 static const unsigned kMaxOneByteChar = 0x7f;
152 static const unsigned kMaxTwoByteChar = 0x7ff;
153 static const unsigned kMaxThreeByteChar = 0xffff;
154 static const unsigned kMaxFourByteChar = 0x1fffff;
158 static const unsigned kBytesSavedByCombiningSurrogates = 2;
159 static const unsigned kSizeOfUnmatchedSurrogate = 3;
162 static const unsigned kMax16BitCodeUnitSize = 3;
163 static inline uchar ValueOf(
const byte* str,
size_t length,
size_t* cursor);
166 static uchar ValueOfIncremental(byte next_byte,
size_t* cursor, State* state,
168 static uchar ValueOfIncrementalFinish(State* state);
171 static inline bool IsValidCharacter(uchar c);
181 static bool ValidateEncoding(
const byte* str,
size_t length);
185 static bool Is(uchar c);
188 static bool Is(uchar c);
190 #ifndef V8_INTL_SUPPORT 192 static bool Is(uchar c);
195 static bool Is(uchar c);
198 static bool Is(uchar c);
200 #endif // !V8_INTL_SUPPORT 205 V8_INLINE
bool IsLineTerminator(uchar c) {
206 return c == 0x000A || c == 0x000D || c == 0x2028 || c == 0x2029;
209 V8_INLINE
bool IsStringLiteralLineTerminator(uchar c) {
210 return c == 0x000A || c == 0x000D;
213 #ifndef V8_INTL_SUPPORT 215 static const int kMaxWidth = 3;
216 static const bool kIsToLower =
true;
217 static int Convert(uchar c,
220 bool* allow_caching_ptr);
223 static const int kMaxWidth = 3;
224 static const bool kIsToLower =
false;
225 static int Convert(uchar c,
228 bool* allow_caching_ptr);
232 static const int kMaxWidth = 1;
233 static int Convert(uchar c,
236 bool* allow_caching_ptr);
239 static const int kMaxWidth = 4;
240 static int Convert(uchar c,
243 bool* allow_caching_ptr);
246 static const int kMaxWidth = 1;
247 static int Convert(uchar c,
250 bool* allow_caching_ptr);
255 #endif // V8_UNICODE_H_
const int kMaxMappingSize