28 #ifndef V8_UNICODE_INL_H_
29 #define V8_UNICODE_INL_H_
36 CacheEntry entry = entries_[code_point & kMask];
37 if (entry.code_point_ == code_point)
return entry.value_;
38 return CalculateValue(code_point);
43 bool result = T::Is(code_point);
44 entries_[code_point & kMask] = CacheEntry(code_point, result);
50 CacheEntry entry = entries_[c & kMask];
51 if (entry.code_point_ == c) {
52 if (entry.offset_ == 0) {
55 result[0] = c + entry.offset_;
59 return CalculateValue(c, n, result);
65 bool allow_caching =
true;
66 int length = T::Convert(c, n, result, &allow_caching);
69 entries_[c & kMask] = CacheEntry(c, result[0] - c);
72 entries_[c & kMask] = CacheEntry(c, 0);
82 static const int kMask = ~(1 << 6);
87 str[0] = 0xC0 | (c >> 6);
88 str[1] = 0x80 | (c & kMask);
94 return Encode(str - kUnmatchedSize,
98 str[0] = 0xE0 | (c >> 12);
99 str[1] = 0x80 | ((c >> 6) & kMask);
100 str[2] = 0x80 | (c & kMask);
103 str[0] = 0xF0 | (c >> 18);
104 str[1] = 0x80 | ((c >> 12) & kMask);
105 str[2] = 0x80 | ((c >> 6) & kMask);
106 str[3] = 0x80 | (c & kMask);
112 uchar Utf8::ValueOf(
const byte* bytes,
unsigned length,
unsigned* cursor) {
114 byte first = bytes[0];
150 #if __BYTE_ORDER == __LITTLE_ENDIAN
151 #define IF_LITTLE(expr) expr
152 #define IF_BIG(expr) ((void) 0)
153 #elif __BYTE_ORDER == __BIG_ENDIAN
154 #define IF_LITTLE(expr) ((void) 0)
155 #define IF_BIG(expr) expr
157 #warning Unknown byte ordering
161 unsigned capacity,
unsigned& offset) {
162 if (offset >= capacity)
return false;
169 unsigned capacity,
unsigned& offset) {
170 unsigned aligned = (offset + 0x3) & ~0x3;
171 if ((aligned +
sizeof(
uchar)) > capacity)
173 if (offset == aligned) {
174 IF_LITTLE(*reinterpret_cast<uchar*>(buffer + aligned) = (c << 8) | 0x80);
175 IF_BIG(*reinterpret_cast<uchar*>(buffer + aligned) = c | (1 << 31));
177 buffer[offset] = 0x80;
178 IF_LITTLE(*reinterpret_cast<uchar*>(buffer + aligned) = c << 8);
179 IF_BIG(*reinterpret_cast<uchar*>(buffer + aligned) = c);
181 offset = aligned +
sizeof(
uchar);
195 byte b = buffer[*offset];
200 unsigned aligned = (*offset + 0x3) & ~0x3;
201 *offset = aligned +
sizeof(
uchar);
202 IF_LITTLE(
return *reinterpret_cast<const uchar*>(buffer + aligned) >> 8);
203 IF_BIG(
return *reinterpret_cast<const uchar*>(buffer + aligned) &
211 template <
class R,
class I,
unsigned s>
213 buffer_ = R::ReadBlock(input_, util_buffer_, s, &remaining_, &offset_);
216 template <
class R,
class I,
unsigned s>
221 template <
class R,
class I,
unsigned s>
227 buffer_ = R::ReadBlock(input_, util_buffer_, s, &remaining_, &offset_);
230 template <
class R,
class I,
unsigned s>
235 template <
class R,
class I,
unsigned s>
238 buffer_ = R::ReadBlock(input_, util_buffer_, s, &remaining_, &offset_);
241 template <
unsigned s>
249 #endif // V8_UNICODE_INL_H_
static int CombineSurrogatePair(uchar lead, uchar trail)
static const unsigned kSizeOfUnmatchedSurrogate
#define I(name, number_of_args, result_size)
static const unsigned kMaxTwoByteChar
static bool EncodeNonAsciiCharacter(uchar c, byte *buffer, unsigned capacity, unsigned &offset)
static uchar DecodeCharacter(const byte *buffer, unsigned *offset)
static uchar CalculateValue(const byte *str, unsigned length, unsigned *cursor)
StringInputBuffer *const buffer_
int get(uchar c, uchar n, uchar *result)
static uchar Length(uchar chr, int previous)
static unsigned Encode(char *out, uchar c, int previous)
virtual void FillBuffer()=0
static const unsigned kBytesSavedByCombiningSurrogates
static const uchar kBadChar
static const unsigned kMaxThreeByteChar
static const unsigned kMaxOneByteChar
static bool IsLeadSurrogate(int code)
static bool IsTrailSurrogate(int code)
static bool EncodeAsciiCharacter(uchar c, byte *buffer, unsigned capacity, unsigned &offset)
static bool EncodeCharacter(uchar c, byte *buffer, unsigned capacity, unsigned &offset)
static const int kNoPreviousCharacter