5#ifndef V8_STRINGS_UNICODE_INL_H_
6#define V8_STRINGS_UNICODE_INL_H_
16#ifndef V8_INTL_SUPPORT
17template <
class T,
int s>
21 return CalculateValue(code_point);
24template <
class T,
int s>
26 bool result = T::Is(code_point);
31template <
class T,
int s>
42 return CalculateValue(c, n,
result);
46template <
class T,
int s>
48 bool allow_caching =
true;
49 int length = T::Convert(c, n,
result, &allow_caching);
66 const int code_unit = code_units[
i];
70 if (
i == length - 1)
return true;
90 uint8_t next = **cursor;
95 return static_cast<uchar>(next);
100 Utf8DfaDecoder::Decode(next, state, buffer);
103 case State::kAccept: {
110 *state = State::kAccept;
119 if (old_state != State::kAccept) {
132 static const int kMask = ~(1 << 6);
137 str[0] = 0xC0 | (c >> 6);
138 str[1] = 0x80 | (c & kMask);
148 static const int kMask = ~(1 << 6);
153 str[0] = 0xC0 | (c >> 6);
154 str[1] = 0x80 | (c & kMask);
160 return Encode(str - kUnmatchedSize,
164 }
else if (replace_invalid &&
168 str[0] = 0xE0 | (c >> 12);
169 str[1] = 0x80 | ((c >> 6) & kMask);
170 str[2] = 0x80 | (c & kMask);
173 str[0] = 0xF0 | (c >> 18);
174 str[1] = 0x80 | ((c >> 12) & kMask);
175 str[2] = 0x80 | ((c >> 6) & kMask);
176 str[3] = 0x80 | (c & kMask);
183 uint8_t first = bytes[0];
217 return c < 0xD800u || (c >= 0xE000u && c < 0xFDD0u) ||
218 (c > 0xFDEFu && c <= 0x10FFFFu && (c & 0xFFFEu) != 0xFFFEu &&
222template <
typename Char>
224 char* buffer,
size_t capacity,
225 bool write_null,
bool replace_invalid_utf8) {
226 constexpr bool kSourceIsOneByte =
sizeof(Char) == 1;
228 if constexpr (kSourceIsOneByte) {
230 replace_invalid_utf8 =
false;
233 size_t write_index = 0;
234 const Char* characters =
string.begin();
235 size_t content_capacity = capacity - write_null;
236 CHECK_LE(content_capacity, capacity);
238 size_t read_index = 0;
239 for (; read_index <
string.size(); read_index++) {
240 Char character = characters[read_index];
242 size_t required_capacity;
243 if constexpr (kSourceIsOneByte) {
248 size_t remaining_capacity = content_capacity - write_index;
249 if (remaining_capacity < required_capacity) {
262 if constexpr (kSourceIsOneByte) {
266 if ((read_index + 1 <
string.
size()) &&
270 write_index +=
Utf8::Encode(buffer + write_index, character, last,
271 replace_invalid_utf8);
281 buffer[write_index++] =
'\0';
284 size_t bytes_written = write_index;
285 size_t characters_processed = read_index;
286 return {bytes_written, characters_processed};
int CalculateValue(uchar c, uchar n, uchar *result)
int get(uchar c, uchar n, uchar *result)
bool CalculateValue(uchar c)
static const int kNoPreviousCharacter
static bool IsSurrogatePair(int lead, int trail)
static int CombineSurrogatePair(uchar lead, uchar trail)
static bool IsTrailSurrogate(int code)
static bool HasUnpairedSurrogate(const uint16_t *code_units, size_t length)
static bool IsLeadSurrogate(int code)
static uchar ValueOf(const uint8_t *str, size_t length, size_t *cursor)
static const unsigned kMaxThreeByteChar
static const unsigned kMaxOneByteChar
uint32_t Utf8IncrementalBuffer
static const uchar kBadChar
static unsigned Length(uchar chr, int previous)
static uchar CalculateValue(const uint8_t *str, size_t length, size_t *cursor)
static const uchar kIncomplete
static unsigned EncodeOneByte(char *out, uint8_t c)
static bool IsValidCharacter(uchar c)
static unsigned LengthOneByte(uint8_t chr)
static const unsigned kMaxTwoByteChar
static unsigned Encode(char *out, uchar c, int previous, bool replace_invalid=false)
static const unsigned kBytesSavedByCombiningSurrogates
static const unsigned kSizeOfUnmatchedSurrogate
Utf8DfaDecoder::State State
static uchar ValueOfIncremental(const uint8_t **cursor, State *state, Utf8IncrementalBuffer *buffer)
ZoneVector< RpoNumber > & result
std::vector< EntryBuilder > entries_
LiftoffAssembler::CacheState state
#define DCHECK_LE(v1, v2)
#define CHECK_LE(lhs, rhs)
#define DCHECK_NOT_NULL(val)
#define DCHECK_NE(v1, v2)
#define DCHECK_GE(v1, v2)
#define DCHECK(condition)
#define DCHECK_LT(v1, v2)
#define DCHECK_EQ(v1, v2)
#define V8_LIKELY(condition)