5 #ifndef V8_UNICODE_DECODER_H_ 6 #define V8_UNICODE_DECODER_H_ 10 #include "src/globals.h" 12 #include "src/utils.h" 13 #include "src/vector.h" 28 DCHECK_LE(offset, stream.length());
36 DCHECK_GT(char_, Utf16::kMaxNonSurrogateCharCode);
44 bool Trailing() {
return trailing_; }
45 size_t Offset() {
return offset_; }
61 inline size_t Utf16Length()
const {
return utf16_length_; }
66 void Reset(uint16_t* buffer,
size_t buffer_length,
68 static void WriteUtf16Slow(uint16_t* data,
size_t length,
70 size_t offset,
bool trailing);
73 size_t chars_written_;
81 template <
size_t kBufferSize>
87 inline size_t WriteUtf16(
88 uint16_t* data,
size_t length,
92 uint16_t buffer_[kBufferSize];
95 Utf8DecoderBase::Utf8DecoderBase()
96 : bytes_read_(0), chars_written_(0), utf16_length_(0), trailing_(false) {}
98 Utf8DecoderBase::Utf8DecoderBase(
99 uint16_t* buffer,
size_t buffer_length,
101 Reset(buffer, buffer_length, stream);
104 template <
size_t kBufferSize>
105 Utf8Decoder<kBufferSize>::Utf8Decoder(
107 : Utf8DecoderBase(buffer_, kBufferSize, stream) {}
109 template <
size_t kBufferSize>
110 void Utf8Decoder<kBufferSize>::Reset(
112 Utf8DecoderBase::Reset(buffer_, kBufferSize, stream);
115 template <
size_t kBufferSize>
116 size_t Utf8Decoder<kBufferSize>::WriteUtf16(
117 uint16_t* data,
size_t data_length,
119 DCHECK_GT(data_length, 0);
120 data_length = std::min(data_length, utf16_length_);
123 size_t memcpy_length = std::min(data_length, chars_written_);
124 v8::internal::MemCopy(data, buffer_, memcpy_length *
sizeof(uint16_t));
126 if (data_length <= chars_written_)
return data_length;
129 WriteUtf16Slow(data + chars_written_, data_length - chars_written_, stream,
130 bytes_read_, trailing_);
136 static const unsigned kMaxChar = 0xff;
138 static inline uint16_t TryConvertToLatin1(uint16_t);
141 uint16_t Latin1::TryConvertToLatin1(uint16_t c) {
158 #endif // V8_UNICODE_DECODER_H_