V8 Project
v8::internal::SimpleStringBuilder Class Reference

#include <utils.h>

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

Public Member Functions

 SimpleStringBuilder (int size)
 
 SimpleStringBuilder (char *buffer, int size)
 
 ~SimpleStringBuilder ()
 
int size () const
 
int position () const
 
void Reset ()
 
void AddCharacter (char c)
 
void AddString (const char *s)
 
void AddSubstring (const char *s, int n)
 
void AddPadding (char c, int count)
 
void AddDecimalInteger (int value)
 
char * Finalize ()
 

Protected Member Functions

bool is_finalized () const
 

Protected Attributes

Vector< char > buffer_
 
int position_
 

Private Member Functions

 DISALLOW_IMPLICIT_CONSTRUCTORS (SimpleStringBuilder)
 

Detailed Description

Definition at line 783 of file utils.h.

Constructor & Destructor Documentation

◆ SimpleStringBuilder() [1/2]

v8::internal::SimpleStringBuilder::SimpleStringBuilder ( int  size)
explicit

Definition at line 18 of file utils.cc.

18  {
20  position_ = 0;
21 }
static Vector< T > New(int length)
Definition: vector.h:27

References buffer_, v8::internal::Vector< T >::New(), position_, and size().

+ Here is the call graph for this function:

◆ SimpleStringBuilder() [2/2]

v8::internal::SimpleStringBuilder::SimpleStringBuilder ( char *  buffer,
int  size 
)
inline

Definition at line 790 of file utils.h.

791  : buffer_(buffer, size), position_(0) { }

◆ ~SimpleStringBuilder()

v8::internal::SimpleStringBuilder::~SimpleStringBuilder ( )
inline

Definition at line 793 of file utils.h.

793 { if (!is_finalized()) Finalize(); }

References Finalize(), and is_finalized().

+ Here is the call graph for this function:

Member Function Documentation

◆ AddCharacter()

void v8::internal::SimpleStringBuilder::AddCharacter ( char  c)
inline

Definition at line 809 of file utils.h.

809  {
810  DCHECK(c != '\0');
812  buffer_[position_++] = c;
813  }
int length() const
Definition: vector.h:41
#define DCHECK(condition)
Definition: logging.h:205

References buffer_, DCHECK, is_finalized(), v8::internal::Vector< T >::length(), and position_.

Referenced by AddDecimalInteger(), AddPadding(), v8::internal::CreateExponentialRepresentation(), v8::internal::Logger::DebugEvent(), v8::internal::DoubleToCString(), v8::internal::DoubleToFixedCString(), v8::internal::DoubleToPrecisionCString(), and v8::internal::DoubleToRadixCString().

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

◆ AddDecimalInteger()

void v8::internal::SimpleStringBuilder::AddDecimalInteger ( int  value)

Definition at line 44 of file utils.cc.

44  {
45  uint32_t number = static_cast<uint32_t>(value);
46  if (value < 0) {
47  AddCharacter('-');
48  number = static_cast<uint32_t>(-value);
49  }
50  int digits = 1;
51  for (uint32_t factor = 10; digits < 10; digits++, factor *= 10) {
52  if (factor > number) break;
53  }
54  position_ += digits;
55  for (int i = 1; i <= digits; i++) {
56  buffer_[position_ - i] = '0' + static_cast<char>(number % 10);
57  number /= 10;
58  }
59 }

References AddCharacter(), buffer_, and position_.

Referenced by v8::internal::CreateExponentialRepresentation(), and v8::internal::DoubleToCString().

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

◆ AddPadding()

void v8::internal::SimpleStringBuilder::AddPadding ( char  c,
int  count 
)

Definition at line 37 of file utils.cc.

37  {
38  for (int i = 0; i < count; i++) {
39  AddCharacter(c);
40  }
41 }

References AddCharacter().

Referenced by v8::internal::CreateExponentialRepresentation(), v8::internal::DoubleToCString(), v8::internal::DoubleToFixedCString(), and v8::internal::DoubleToPrecisionCString().

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

◆ AddString()

void v8::internal::SimpleStringBuilder::AddString ( const char *  s)

Definition at line 24 of file utils.cc.

24  {
25  AddSubstring(s, StrLength(s));
26 }
void AddSubstring(const char *s, int n)
Definition: utils.cc:29
int StrLength(const char *string)
Definition: vector.h:147

References AddSubstring(), and v8::internal::StrLength().

Referenced by v8::internal::CreateExponentialRepresentation(), v8::internal::DoubleToCString(), v8::internal::DoubleToFixedCString(), and v8::internal::DoubleToPrecisionCString().

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

◆ AddSubstring()

void v8::internal::SimpleStringBuilder::AddSubstring ( const char *  s,
int  n 
)

Definition at line 29 of file utils.cc.

29  {
30  DCHECK(!is_finalized() && position_ + n <= buffer_.length());
31  DCHECK(static_cast<size_t>(n) <= strlen(s));
33  position_ += n;
34 }
const int kCharSize
Definition: globals.h:122
void MemCopy(void *dest, const void *src, size_t size)
Definition: utils.h:350

References buffer_, DCHECK, is_finalized(), v8::internal::kCharSize, v8::internal::Vector< T >::length(), v8::internal::MemCopy(), and position_.

Referenced by AddString(), v8::internal::DoubleToCString(), v8::internal::DoubleToFixedCString(), v8::internal::DoubleToPrecisionCString(), and v8::internal::DoubleToRadixCString().

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

◆ DISALLOW_IMPLICIT_CONSTRUCTORS()

v8::internal::SimpleStringBuilder::DISALLOW_IMPLICIT_CONSTRUCTORS ( SimpleStringBuilder  )
private

◆ Finalize()

char * v8::internal::SimpleStringBuilder::Finalize ( )

Definition at line 62 of file utils.cc.

62  {
64  // If there is no space for null termination, overwrite last character.
65  if (position_ == buffer_.length()) {
66  position_--;
67  // Print ellipsis.
68  for (int i = 3; i > 0 && position_ > i; --i) buffer_[position_ - i] = '.';
69  }
70  buffer_[position_] = '\0';
71  // Make sure nobody managed to add a 0-character to the
72  // buffer while building the string.
73  DCHECK(strlen(buffer_.start()) == static_cast<size_t>(position_));
74  position_ = -1;
76  return buffer_.start();
77 }
T * start() const
Definition: vector.h:47

References buffer_, DCHECK, is_finalized(), v8::internal::Vector< T >::length(), position_, and v8::internal::Vector< T >::start().

Referenced by v8::internal::CreateExponentialRepresentation(), v8::internal::Logger::DebugEvent(), v8::internal::DoubleToCString(), v8::internal::DoubleToFixedCString(), v8::internal::DoubleToPrecisionCString(), v8::internal::DoubleToRadixCString(), and ~SimpleStringBuilder().

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

◆ is_finalized()

bool v8::internal::SimpleStringBuilder::is_finalized ( ) const
inlineprotected

Definition at line 837 of file utils.h.

837 { return position_ < 0; }

References position_.

Referenced by AddCharacter(), v8::internal::StringBuilder::AddFormattedList(), AddSubstring(), Finalize(), position(), and ~SimpleStringBuilder().

+ Here is the caller graph for this function:

◆ position()

int v8::internal::SimpleStringBuilder::position ( ) const
inline

Definition at line 798 of file utils.h.

798  {
799  DCHECK(!is_finalized());
800  return position_;
801  }

References DCHECK, is_finalized(), and position_.

Referenced by v8::internal::DoubleToPrecisionCString().

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

◆ Reset()

void v8::internal::SimpleStringBuilder::Reset ( )
inline

Definition at line 804 of file utils.h.

804 { position_ = 0; }

References position_.

◆ size()

int v8::internal::SimpleStringBuilder::size ( ) const
inline

Definition at line 795 of file utils.h.

795 { return buffer_.length(); }

References buffer_, and v8::internal::Vector< T >::length().

Referenced by SimpleStringBuilder().

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

Member Data Documentation

◆ buffer_

Vector<char> v8::internal::SimpleStringBuilder::buffer_
protected

◆ position_

int v8::internal::SimpleStringBuilder::position_
protected

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