V8 Project
v8::internal::Utf8ToUtf16CharacterStream Class Reference

#include <scanner-character-streams.h>

+ Inheritance diagram for v8::internal::Utf8ToUtf16CharacterStream:
+ Collaboration diagram for v8::internal::Utf8ToUtf16CharacterStream:

Public Member Functions

 Utf8ToUtf16CharacterStream (const byte *data, unsigned length)
 
virtual ~Utf8ToUtf16CharacterStream ()
 
- Public Member Functions inherited from v8::internal::BufferedUtf16CharacterStream
 BufferedUtf16CharacterStream ()
 
virtual ~BufferedUtf16CharacterStream ()
 
virtual void PushBack (uc32 character)
 
- Public Member Functions inherited from v8::internal::Utf16CharacterStream
 Utf16CharacterStream ()
 
virtual ~Utf16CharacterStream ()
 
uc32 Advance ()
 
unsigned pos () const
 
unsigned SeekForward (unsigned code_unit_count)
 

Static Public Member Functions

static unsigned CopyChars (uint16_t *dest, unsigned length, const byte *src, unsigned *src_pos, unsigned src_length)
 

Protected Member Functions

virtual unsigned BufferSeekForward (unsigned delta)
 
virtual unsigned FillBuffer (unsigned char_position)
 
void SetRawPosition (unsigned char_position)
 
- Protected Member Functions inherited from v8::internal::BufferedUtf16CharacterStream
virtual unsigned SlowSeekForward (unsigned delta)
 
virtual bool ReadBlock ()
 
virtual void SlowPushBack (uc16 character)
 

Protected Attributes

const byteraw_data_
 
unsigned raw_data_length_
 
unsigned raw_data_pos_
 
unsigned raw_character_position_
 
- Protected Attributes inherited from v8::internal::BufferedUtf16CharacterStream
const uc16pushback_limit_
 
uc16 buffer_ [kBufferSize]
 
- Protected Attributes inherited from v8::internal::Utf16CharacterStream
const uint16_t * buffer_cursor_
 
const uint16_t * buffer_end_
 
unsigned pos_
 

Additional Inherited Members

- Static Protected Attributes inherited from v8::internal::BufferedUtf16CharacterStream
static const unsigned kBufferSize = 512
 
static const unsigned kPushBackStepSize = 16
 
- Static Protected Attributes inherited from v8::internal::Utf16CharacterStream
static const uc32 kEndOfInput = -1
 

Detailed Description

Definition at line 57 of file scanner-character-streams.h.

Constructor & Destructor Documentation

◆ Utf8ToUtf16CharacterStream()

v8::internal::Utf8ToUtf16CharacterStream::Utf8ToUtf16CharacterStream ( const byte data,
unsigned  length 
)

Definition at line 162 of file scanner-character-streams.cc.

References v8::internal::BufferedUtf16CharacterStream::ReadBlock().

+ Here is the call graph for this function:

◆ ~Utf8ToUtf16CharacterStream()

v8::internal::Utf8ToUtf16CharacterStream::~Utf8ToUtf16CharacterStream ( )
virtual

Definition at line 173 of file scanner-character-streams.cc.

173 { }

Member Function Documentation

◆ BufferSeekForward()

unsigned v8::internal::Utf8ToUtf16CharacterStream::BufferSeekForward ( unsigned  delta)
protectedvirtual

Implements v8::internal::BufferedUtf16CharacterStream.

Definition at line 205 of file scanner-character-streams.cc.

205  {
206  unsigned old_pos = pos_;
207  unsigned target_pos = pos_ + delta;
208  SetRawPosition(target_pos);
210  ReadBlock();
211  return pos_ - old_pos;
212 }

References v8::internal::Utf16CharacterStream::pos_, raw_character_position_, v8::internal::BufferedUtf16CharacterStream::ReadBlock(), and SetRawPosition().

+ Here is the call graph for this function:

◆ CopyChars()

unsigned v8::internal::Utf8ToUtf16CharacterStream::CopyChars ( uint16_t *  dest,
unsigned  length,
const byte src,
unsigned *  src_pos,
unsigned  src_length 
)
static

Definition at line 176 of file scanner-character-streams.cc.

179  {
180  static const unibrow::uchar kMaxUtf16Character = 0xffff;
181  unsigned i = 0;
182  // Because of the UTF-16 lead and trail surrogates, we stop filling the buffer
183  // one character early (in the normal case), because we need to have at least
184  // two free spaces in the buffer to be sure that the next character will fit.
185  while (i < length - 1) {
186  if (*src_pos == src_length) break;
187  unibrow::uchar c = src[*src_pos];
189  *src_pos = *src_pos + 1;
190  } else {
191  c = unibrow::Utf8::CalculateValue(src + *src_pos, src_length - *src_pos,
192  src_pos);
193  }
194  if (c > kMaxUtf16Character) {
195  dest[i++] = unibrow::Utf16::LeadSurrogate(c);
196  dest[i++] = unibrow::Utf16::TrailSurrogate(c);
197  } else {
198  dest[i++] = static_cast<uc16>(c);
199  }
200  }
201  return i;
202 }
static uint16_t LeadSurrogate(uint32_t char_code)
Definition: unicode.h:108
static uint16_t TrailSurrogate(uint32_t char_code)
Definition: unicode.h:111
static const unsigned kMaxOneByteChar
Definition: unicode.h:141
static uchar CalculateValue(const byte *str, unsigned length, unsigned *cursor)
Definition: unicode.cc:191
unsigned int uchar
Definition: unicode.h:17
uint16_t uc16
Definition: globals.h:184

References unibrow::Utf8::CalculateValue(), unibrow::Utf8::kMaxOneByteChar, unibrow::Utf16::LeadSurrogate(), and unibrow::Utf16::TrailSurrogate().

Referenced by v8::internal::anonymous_namespace{scanner-character-streams.cc}::CopyCharsHelper(), and FillBuffer().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FillBuffer()

unsigned v8::internal::Utf8ToUtf16CharacterStream::FillBuffer ( unsigned  char_position)
protectedvirtual

Implements v8::internal::BufferedUtf16CharacterStream.

Definition at line 215 of file scanner-character-streams.cc.

215  {
216  SetRawPosition(char_position);
217  if (raw_character_position_ != char_position) {
218  // char_position was not a valid position in the stream (hit the end
219  // while spooling to it).
220  return 0u;
221  }
224  raw_character_position_ = char_position + i;
225  return i;
226 }
static unsigned CopyChars(uint16_t *dest, unsigned length, const byte *src, unsigned *src_pos, unsigned src_length)

References v8::internal::BufferedUtf16CharacterStream::buffer_, CopyChars(), v8::internal::BufferedUtf16CharacterStream::kBufferSize, raw_character_position_, raw_data_, raw_data_length_, raw_data_pos_, and SetRawPosition().

+ Here is the call graph for this function:

◆ SetRawPosition()

void v8::internal::Utf8ToUtf16CharacterStream::SetRawPosition ( unsigned  char_position)
protected

Definition at line 290 of file scanner-character-streams.cc.

290  {
291  if (raw_character_position_ > target_position) {
292  // Spool backwards in utf8 buffer.
293  do {
294  int old_pos = raw_data_pos_;
297  DCHECK(old_pos - raw_data_pos_ <= 4);
298  // Step back over both code units for surrogate pairs.
299  if (old_pos - raw_data_pos_ == 4) raw_character_position_--;
300  } while (raw_character_position_ > target_position);
301  // No surrogate pair splitting.
302  DCHECK(raw_character_position_ == target_position);
303  return;
304  }
305  // Spool forwards in the utf8 buffer.
306  while (raw_character_position_ < target_position) {
307  if (raw_data_pos_ == raw_data_length_) return;
308  int old_pos = raw_data_pos_;
311  DCHECK(raw_data_pos_ - old_pos <= 4);
312  if (raw_data_pos_ - old_pos == 4) raw_character_position_++;
313  }
314  // No surrogate pair splitting.
315  DCHECK(raw_character_position_ == target_position);
316 }
#define DCHECK(condition)
Definition: logging.h:205
static void Utf8CharacterBack(const byte *buffer, unsigned *cursor)
static void Utf8CharacterForward(const byte *buffer, unsigned *cursor)

References DCHECK, raw_character_position_, raw_data_, raw_data_length_, raw_data_pos_, v8::internal::Utf8CharacterBack(), and v8::internal::Utf8CharacterForward().

Referenced by BufferSeekForward(), and FillBuffer().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ raw_character_position_

unsigned v8::internal::Utf8ToUtf16CharacterStream::raw_character_position_
protected

Definition at line 75 of file scanner-character-streams.h.

Referenced by BufferSeekForward(), FillBuffer(), and SetRawPosition().

◆ raw_data_

const byte* v8::internal::Utf8ToUtf16CharacterStream::raw_data_
protected

Definition at line 70 of file scanner-character-streams.h.

Referenced by FillBuffer(), and SetRawPosition().

◆ raw_data_length_

unsigned v8::internal::Utf8ToUtf16CharacterStream::raw_data_length_
protected

Definition at line 71 of file scanner-character-streams.h.

Referenced by FillBuffer(), and SetRawPosition().

◆ raw_data_pos_

unsigned v8::internal::Utf8ToUtf16CharacterStream::raw_data_pos_
protected

Definition at line 72 of file scanner-character-streams.h.

Referenced by FillBuffer(), and SetRawPosition().


The documentation for this class was generated from the following files: