31 #include <sys/types.h>
41 typedef unsigned char byte;
49 template <
class T,
int size = 256>
53 inline bool get(
uchar c);
56 bool CalculateValue(
uchar c);
58 inline CacheEntry() : code_point_(0), value_(0) { }
59 inline CacheEntry(
uchar code_point,
bool value)
60 : code_point_(code_point),
62 uchar code_point_ : 21;
65 static const int kSize = size;
66 static const int kMask = kSize - 1;
67 CacheEntry entries_[kSize];
74 template <
class T,
int size = 256>
83 inline CacheEntry() : code_point_(kNoChar), offset_(0) { }
84 inline CacheEntry(
uchar code_point,
signed offset)
85 : code_point_(code_point),
89 static const int kNoChar = (1 << 21) - 1;
91 static const int kSize = size;
92 static const int kMask = kSize - 1;
93 CacheEntry entries_[kSize];
99 static int GetByteCount();
100 static const uchar kMaxCodePoint;
105 template <
typename Data>
109 inline Buffer() : data_(0), length_(0) { }
122 return (code & 0xfc00) == 0xd800;
126 return (code & 0xfc00) == 0xdc00;
130 return 0x10000 + ((lead & 0x3ff) << 10) + (trail & 0x3ff);
144 return 0xd800 + (((char_code - 0x10000) >> 10) & 0x3ff);
147 return 0xdc00 + (char_code & 0x3ff);
155 static inline unsigned Encode(
156 char* out,
uchar c,
int previous);
158 unsigned capacity,
unsigned* chars_read,
unsigned* offset);
177 static inline uchar ValueOf(
const byte* str,
189 virtual void Seek(
unsigned);
196 unsigned capacity,
unsigned& offset);
198 unsigned capacity,
unsigned& offset);
200 virtual void Rewind() = 0;
220 template <
class Reader,
class Input = Reader*,
unsigned kSize = 256>
224 inline void Reset(Input input);
225 void Seek(
unsigned position);
226 inline void Reset(
unsigned position, Input input);
246 template <
unsigned s = 256>
251 inline void Reset(
const char* data,
unsigned length) {
290 bool* allow_caching_ptr);
297 bool* allow_caching_ptr);
304 bool* allow_caching_ptr);
311 bool* allow_caching_ptr);
318 bool* allow_caching_ptr);
323 #endif // V8_UNICODE_H_
static uchar TrailSurrogate(int char_code)
static int CombineSurrogatePair(uchar lead, uchar trail)
static const unsigned kSizeOfUnmatchedSurrogate
static uchar LeadSurrogate(int char_code)
static int Convert(uchar c, uchar n, uchar *result, bool *allow_caching_ptr)
static const unsigned kMaxTwoByteChar
static bool EncodeNonAsciiCharacter(uchar c, byte *buffer, unsigned capacity, unsigned &offset)
static uchar DecodeCharacter(const byte *buffer, unsigned *offset)
const int kMaxMappingSize
static const int kMaxWidth
static int Convert(uchar c, uchar n, uchar *result, bool *allow_caching_ptr)
static const int kMaxExtraUtf8BytesForOneUtf16CodeUnit
static uchar CalculateValue(const byte *str, unsigned length, unsigned *cursor)
static int Convert(uchar c, uchar n, uchar *result, bool *allow_caching_ptr)
static const unsigned kMaxEncodedSize
static uchar Length(uchar chr, int previous)
static int Convert(uchar c, uchar n, uchar *result, bool *allow_caching_ptr)
virtual void Seek(unsigned)
static const uchar kMaxNonSurrogateCharCode
static const int kMaxWidth
Buffer(Data data, unsigned length)
static const int kUtf8BytesToCodeASurrogate
static unsigned Encode(char *out, uchar c, int previous)
static const int kMaxWidth
static const unsigned kMaxFourByteChar
virtual void FillBuffer()=0
static int Convert(uchar c, uchar n, uchar *result, bool *allow_caching_ptr)
static const int kMaxWidth
static const unsigned kBytesSavedByCombiningSurrogates
static const uchar kBadChar
static const byte * ReadBlock(Buffer< const char * > str, byte *buffer, unsigned capacity, unsigned *chars_read, unsigned *offset)
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 const int kMaxWidth
virtual ~CharacterStream()
static bool EncodeCharacter(uchar c, byte *buffer, unsigned capacity, unsigned &offset)
static const int kNoPreviousCharacter