Flutter Engine
The Flutter Engine
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
dart::BaseTextBuffer Class Referenceabstract

#include <text_buffer.h>

Inheritance diagram for dart::BaseTextBuffer:
dart::ValueObject dart::BufferFormatter dart::TextBuffer dart::ZoneTextBuffer

Public Member Functions

 BaseTextBuffer ()
 
 BaseTextBuffer (char *buffer, intptr_t capacity)
 
virtual ~BaseTextBuffer ()
 
intptr_t Printf (const char *format,...) PRINTF_ATTRIBUTE(2
 
intptr_t intptr_t VPrintf (const char *format, va_list args)
 
void AddChar (char ch)
 
void AddString (const char *s)
 
void AddRaw (const uint8_t *buffer, intptr_t buffer_length)
 
void AddEscapedString (const char *s)
 
void AddEscapedUTF8 (const char *s, intptr_t len)
 
void AddEscapedLatin1 (const uint8_t *code_units, intptr_t len)
 
void AddEscapedUTF16 (const uint16_t *code_units, intptr_t len)
 
char * buffer () const
 
intptr_t length () const
 
virtual void Clear ()=0
 
- Public Member Functions inherited from dart::ValueObject
 ValueObject ()
 
 ~ValueObject ()
 

Protected Member Functions

virtual bool EnsureCapacity (intptr_t len)=0
 
 DISALLOW_COPY_AND_ASSIGN (BaseTextBuffer)
 

Protected Attributes

char * buffer_
 
intptr_t capacity_
 
intptr_t length_
 

Detailed Description

Definition at line 15 of file text_buffer.h.

Constructor & Destructor Documentation

◆ BaseTextBuffer() [1/2]

dart::BaseTextBuffer::BaseTextBuffer ( )
inline

Definition at line 17 of file text_buffer.h.

17: buffer_(nullptr), capacity_(0), length_(0) {}

◆ BaseTextBuffer() [2/2]

dart::BaseTextBuffer::BaseTextBuffer ( char *  buffer,
intptr_t  capacity 
)
inline

Definition at line 18 of file text_buffer.h.

19 : buffer_(buffer), capacity_(capacity), length_(0) {}
char * buffer() const
Definition: text_buffer.h:35

◆ ~BaseTextBuffer()

virtual dart::BaseTextBuffer::~BaseTextBuffer ( )
inlinevirtual

Definition at line 20 of file text_buffer.h.

20{}

Member Function Documentation

◆ AddChar()

void dart::BaseTextBuffer::AddChar ( char  ch)

Definition at line 49 of file text_buffer.cc.

49 {
50 if (!EnsureCapacity(sizeof(ch))) return;
51 buffer_[length_] = ch;
52 length_++;
53 buffer_[length_] = '\0';
54}
virtual bool EnsureCapacity(intptr_t len)=0

◆ AddEscapedLatin1()

void dart::BaseTextBuffer::AddEscapedLatin1 ( const uint8_t *  code_units,
intptr_t  len 
)

Definition at line 94 of file text_buffer.cc.

94 {
95 const uint8_t* cursor = s;
96 const uint8_t* end = cursor + len;
97
98 intptr_t needed = 0;
99 while (cursor < end) {
100 needed += EscapedCodeUnitLength(*cursor++);
101 }
102
103 if (!EnsureCapacity(needed)) return;
104
105 cursor = s;
106 while (cursor < end) {
107 EscapeAndAddCodeUnit(*cursor++);
108 }
109 buffer_[length_] = '\0';
110}
struct MyStruct s
glong glong end

◆ AddEscapedString()

void dart::BaseTextBuffer::AddEscapedString ( const char *  s)

Definition at line 267 of file text_buffer.cc.

267 {
268 AddEscapedUTF8(s, strlen(s));
269}
void AddEscapedUTF8(const char *s, intptr_t len)
Definition: text_buffer.cc:66

◆ AddEscapedUTF16()

void dart::BaseTextBuffer::AddEscapedUTF16 ( const uint16_t *  code_units,
intptr_t  len 
)

Definition at line 112 of file text_buffer.cc.

112 {
113 for (const uint16_t* end = s + len; s < end; s++) {
114 if (!EnsureCapacity(6)) return;
115
116 uint16_t code_unit = *s;
117 if (Utf16::IsTrailSurrogate(code_unit)) {
118 EscapeAndAddUTF16CodeUnit(code_unit);
119 } else if (Utf16::IsLeadSurrogate(code_unit)) {
120 if (s + 1 == end) {
121 EscapeAndAddUTF16CodeUnit(code_unit);
122 } else {
123 uint16_t next_code_unit = *(s + 1);
124 if (Utf16::IsTrailSurrogate(next_code_unit)) {
125 uint32_t decoded = Utf16::Decode(code_unit, next_code_unit);
126 EscapeAndAddCodeUnit(decoded);
127 s++;
128 } else {
129 EscapeAndAddUTF16CodeUnit(code_unit);
130 }
131 }
132 } else {
133 EscapeAndAddCodeUnit(code_unit);
134 }
135 }
136 buffer_[length_] = '\0';
137}
static int32_t Decode(uint16_t lead, uint16_t trail)
Definition: unicode.h:151
static bool IsLeadSurrogate(uint32_t ch)
Definition: unicode.h:126
static bool IsTrailSurrogate(uint32_t ch)
Definition: unicode.h:131

◆ AddEscapedUTF8()

void dart::BaseTextBuffer::AddEscapedUTF8 ( const char *  s,
intptr_t  len 
)

Definition at line 66 of file text_buffer.cc.

66 {
67 const uint8_t* cursor = reinterpret_cast<const uint8_t*>(s);
68 const uint8_t* end = cursor + len;
69
70 intptr_t needed = 0;
71 while (cursor < end) {
72 uint8_t codeunit = *cursor++;
73 if (codeunit >= 0x80) {
74 needed += 1;
75 } else {
76 needed += EscapedCodeUnitLength(codeunit);
77 }
78 }
79
80 if (!EnsureCapacity(needed)) return;
81
82 cursor = reinterpret_cast<const uint8_t*>(s);
83 while (cursor < end) {
84 uint8_t codeunit = *cursor++;
85 if (codeunit >= 0x80) {
86 buffer_[length_++] = codeunit;
87 } else {
88 EscapeAndAddCodeUnit(codeunit);
89 }
90 }
91 buffer_[length_] = '\0';
92}

◆ AddRaw()

void dart::BaseTextBuffer::AddRaw ( const uint8_t *  buffer,
intptr_t  buffer_length 
)

Definition at line 56 of file text_buffer.cc.

56 {
57 ASSERT(buffer != nullptr);
58 if (!EnsureCapacity(buffer_length)) {
59 buffer_length = capacity_ - length_ - 1; // Copy what fits.
60 }
61 memmove(&buffer_[length_], buffer, buffer_length);
62 length_ += buffer_length;
63 buffer_[length_] = '\0';
64}
#define ASSERT(E)

◆ AddString()

void dart::BaseTextBuffer::AddString ( const char *  s)

Definition at line 263 of file text_buffer.cc.

263 {
264 AddRaw(reinterpret_cast<const uint8_t*>(s), strlen(s));
265}
void AddRaw(const uint8_t *buffer, intptr_t buffer_length)
Definition: text_buffer.cc:56

◆ buffer()

char * dart::BaseTextBuffer::buffer ( ) const
inline

Definition at line 35 of file text_buffer.h.

35{ return buffer_; }

◆ Clear()

virtual void dart::BaseTextBuffer::Clear ( )
pure virtual

◆ DISALLOW_COPY_AND_ASSIGN()

dart::BaseTextBuffer::DISALLOW_COPY_AND_ASSIGN ( BaseTextBuffer  )
protected

◆ EnsureCapacity()

virtual bool dart::BaseTextBuffer::EnsureCapacity ( intptr_t  len)
protectedpure virtual

◆ length()

intptr_t dart::BaseTextBuffer::length ( ) const
inline

Definition at line 36 of file text_buffer.h.

36{ return length_; }

◆ Printf()

intptr_t dart::BaseTextBuffer::Printf ( const char *  format,
  ... 
)

Definition at line 14 of file text_buffer.cc.

14 {
15 va_list args;
17 intptr_t len = VPrintf(format, args);
18 va_end(args);
19 return len;
20}
intptr_t intptr_t VPrintf(const char *format, va_list args)
Definition: text_buffer.cc:22
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
uint32_t uint32_t * format
va_start(args, format)
va_end(args)

◆ VPrintf()

intptr_t dart::BaseTextBuffer::VPrintf ( const char *  format,
va_list  args 
)

Definition at line 22 of file text_buffer.cc.

22 {
23 va_list args1;
24 va_copy(args1, args);
25 intptr_t remaining = capacity_ - length_;
26 ASSERT(remaining >= 0);
27 intptr_t len = Utils::VSNPrint(buffer_ + length_, remaining, format, args1);
28 va_end(args1);
29 if (len >= remaining) {
30 if (!EnsureCapacity(len)) {
31 length_ = capacity_ - 1;
32 buffer_[length_] = '\0';
33 return remaining - 1;
34 }
35 remaining = capacity_ - length_;
36 ASSERT(remaining > len);
37 va_list args2;
38 va_copy(args2, args);
39 intptr_t len2 =
40 Utils::VSNPrint(buffer_ + length_, remaining, format, args2);
41 va_end(args2);
42 ASSERT(len == len2);
43 }
44 length_ += len;
45 buffer_[length_] = '\0';
46 return len;
47}
static int static int VSNPrint(char *str, size_t size, const char *format, va_list args)

Member Data Documentation

◆ buffer_

char* dart::BaseTextBuffer::buffer_
protected

Definition at line 50 of file text_buffer.h.

◆ capacity_

intptr_t dart::BaseTextBuffer::capacity_
protected

Definition at line 51 of file text_buffer.h.

◆ length_

intptr_t dart::BaseTextBuffer::length_
protected

Definition at line 52 of file text_buffer.h.


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