5#ifndef V8_STRINGS_UNICODE_H_
6#define V8_STRINGS_UNICODE_H_
13#include "third_party/utf8-decoder/utf8-decoder.h"
29#ifndef V8_INTL_SUPPORT
30template <
class T,
int size = 256>
69template <
class T,
int size = 256>
107 return (code & 0x1ffc00) == 0xd800;
110 return (code & 0x1ffc00) == 0xdc00;
114 return 0x10000 + ((lead & 0x3ff) << 10) + (trail & 0x3ff);
127 return 0xd800 + (((char_code - 0x10000) >> 10) & 0x3ff);
130 return 0xdc00 + (char_code & 0x3ff);
146#if V8_ENABLE_WEBASSEMBLY
163 using State = Utf8DfaDecoder::State;
165 static inline unsigned LengthOneByte(uint8_t chr);
167 static inline unsigned EncodeOneByte(
char* out, uint8_t c);
168 static inline unsigned Encode(
char* out,
uchar c,
int previous,
169 bool replace_invalid =
false);
170 static uchar CalculateValue(
const uint8_t* str,
size_t length,
175 static const uchar kBadChar = 0xFFFD;
176 static const uchar kBufferEmpty = 0x0;
177 static const uchar kIncomplete = 0xFFFFFFFC;
178 static const unsigned kMaxEncodedSize = 4;
179 static const unsigned kMaxOneByteChar = 0x7f;
180 static const unsigned kMaxTwoByteChar = 0x7ff;
181 static const unsigned kMaxThreeByteChar = 0xffff;
182 static const unsigned kMaxFourByteChar = 0x1fffff;
186 static const unsigned kBytesSavedByCombiningSurrogates = 2;
187 static const unsigned kSizeOfUnmatchedSurrogate = 3;
190 static const unsigned kMax16BitCodeUnitSize = 3;
193 static const unsigned kMax8BitCodeUnitSize = 2;
194 static inline uchar ValueOf(
const uint8_t* str,
size_t length,
198 static inline uchar ValueOfIncremental(
const uint8_t** cursor,
State* state,
200 static uchar ValueOfIncrementalFinish(
State* state);
203 static inline bool IsValidCharacter(
uchar c);
213 static bool ValidateEncoding(
const uint8_t* str,
size_t length);
220 template <
typename Char>
222 char* buffer,
size_t capacity,
bool write_null,
223 bool replace_invalid_utf8);
226#if V8_ENABLE_WEBASSEMBLY
239 static bool ValidateEncoding(
const uint8_t* str,
size_t length);
242 std::vector<size_t>* surrogate_offsets);
252#ifndef V8_INTL_SUPPORT
254 static bool Is(
uchar c);
257 static bool Is(
uchar c);
260 static bool Is(
uchar c);
268 return c == 0x000A || c == 0x000D || c == 0x2028 || c == 0x2029;
272 return c == 0x000A || c == 0x000D;
275#ifdef V8_INTL_SUPPORT
277 static const bool kIsToLower =
true;
280 static const bool kIsToLower =
false;
284 static const int kMaxWidth = 3;
285 static const bool kIsToLower =
true;
289 static const int kMaxWidth = 3;
290 static const bool kIsToLower =
false;
294 static const int kMaxWidth = 1;
298 static const int kMaxWidth = 4;
302 static const int kMaxWidth = 1;
static const uint16_t kMaxChar
int CalculateValue(uchar c, uchar n, uchar *result)
CacheEntry entries_[kSize]
int get(uchar c, uchar n, uchar *result)
CacheEntry(uchar code_point, bool value)
bool CalculateValue(uchar c)
CacheEntry entries_[kSize]
static const uchar kMaxCodePoint
static int GetByteCount()
static uint16_t LeadSurrogate(uint32_t char_code)
static const int kNoPreviousCharacter
static const uchar kMaxNonSurrogateCharCode
static const int kMaxExtraUtf8BytesForOneUtf16CodeUnit
static uint16_t TrailSurrogate(uint32_t char_code)
static bool IsSurrogatePair(int lead, int trail)
static void ReplaceUnpairedSurrogates(const uint16_t *source_code_units, uint16_t *dest_code_units, size_t length)
static int CombineSurrogatePair(uchar lead, uchar trail)
static bool IsTrailSurrogate(int code)
static bool HasUnpairedSurrogate(const uint16_t *code_units, size_t length)
static const int kUtf8BytesToCodeASurrogate
static bool IsLeadSurrogate(int code)
uint32_t Utf8IncrementalBuffer
Utf8DfaDecoder::State State
static constexpr T decode(U value)
ZoneVector< RpoNumber > & result
const int kMaxMappingSize
V8_INLINE bool IsStringLiteralLineTerminator(uchar c)
V8_INLINE bool IsLineTerminator(uchar c)
#define DCHECK_IMPLIES(v1, v2)
#define V8_EXPORT_PRIVATE
CacheEntry(uchar code_point, signed offset)
size_t characters_processed