|
Click
|
Efficiently build up Strings from pieces. More...
Public Types | |
| typedef const char * | const_iterator |
| typedef char * | iterator |
| typedef int(StringAccum::* | unspecified_bool_type) () const |
Public Member Functions | |
| StringAccum () | |
| Construct an empty StringAccum (with length 0). | |
| StringAccum (int capacity) | |
| Construct a StringAccum with room for at least capacity characters. | |
| StringAccum (const String &str) | |
| Construct a StringAccum containing the characters in str. | |
| StringAccum (const StringAccum &x) | |
| Construct a StringAccum containing a copy of x. | |
| ~StringAccum () | |
| Destroy a StringAccum, freeing its memory. | |
| StringAccum & | operator= (const StringAccum &x) |
| Assign this StringAccum to x. | |
| const char * | data () const |
| Return the contents of the StringAccum. | |
| char * | data () |
| int | length () const |
| Return the length of the StringAccum. | |
| int | capacity () const |
| Return the StringAccum's current capacity. | |
| const char * | c_str () |
| Null-terminate this StringAccum and return its data. | |
| operator unspecified_bool_type () const | |
| Test if the StringAccum contains characters. | |
| bool | empty () const |
| Test if the StringAccum is empty. | |
| bool | operator! () const |
| Test if the StringAccum is empty. | |
| const_iterator | begin () const |
| Return an iterator for the first character in the StringAccum. | |
| iterator | begin () |
| const_iterator | end () const |
| Return an iterator for the end of the StringAccum. | |
| iterator | end () |
| char | operator[] (int i) const |
| Return the ith character in the string. | |
| char & | operator[] (int i) |
| Return a reference to the ith character in the string. | |
| char | front () const |
| Return the first character in the string. | |
| char & | front () |
| Return a reference to the first character in the string. | |
| char | back () const |
| Return the last character in the string. | |
| char & | back () |
| Return a reference to the last character in the string. | |
| bool | out_of_memory () const |
| Test if the StringAccum is out-of-memory. | |
| void | assign_out_of_memory () |
| Change this StringAccum into an out-of-memory StringAccum. | |
| void | clear () |
| Clear the StringAccum's comments. | |
| char * | reserve (int n) |
| Reserve space for at least n characters. | |
| void | set_length (int len) |
| Set the StringAccum's length to len. | |
| int | resize (int len) |
| Set the StringAccum's length to len. | |
| void | adjust_length (int delta) |
| Adjust the StringAccum's length. | |
| char * | extend (int nadjust, int nreserve=0) |
| Reserve space and adjust length in one operation. | |
| void | pop_back (int n=1) |
| Remove characters from the end of the StringAccum. | |
| void | append (char c) |
| Append character c to the StringAccum. | |
| void | append (unsigned char c) |
| bool | append_utf8 (int ch) |
| Append Unicode character ch encoded in UTF-8. | |
| void | append (const char *cstr) |
| Append the null-terminated C string s to this StringAccum. | |
| void | append (const char *s, int len) |
| Append the first len characters of s to this StringAccum. | |
| void | append (const unsigned char *s, int len) |
| void | append (const char *first, const char *last) |
| Append the data from first to last to the end of this StringAccum. | |
| void | append (const unsigned char *first, const unsigned char *last) |
| void | append_fill (int c, int len) |
| Append len copies of character c to the StringAccum. | |
| void | append_numeric (String::intmax_t x, int base=10, bool uppercase=true) |
| Append string representation of x to this StringAccum. | |
| void | append_numeric (String::uintmax_t x, int base=10, bool uppercase=true) |
| StringAccum & | snprintf (int n, const char *format,...) CLICK_SNPRINTF_ATTR |
| Append result of snprintf() to this StringAccum. | |
| String | take_string () |
| Return a String object with this StringAccum's contents. | |
| void | swap (StringAccum &x) |
| Swap this StringAccum's contents with x. | |
| void | forward (int delta) |
Related Symbols | |
(Note that these are not member symbols.) | |
| StringAccum & | operator<< (StringAccum &sa, char c) |
| Append character c to StringAccum sa. | |
| StringAccum & | operator<< (StringAccum &sa, unsigned char c) |
| Append character c to StringAccum sa. | |
| StringAccum & | operator<< (StringAccum &sa, const char *cstr) |
| Append null-terminated C string cstr to StringAccum sa. | |
| StringAccum & | operator<< (StringAccum &sa, bool x) |
| Append "true" or "false" to sa, depending on x. | |
| StringAccum & | operator<< (StringAccum &sa, short x) |
| Append decimal representation of x to sa. | |
| StringAccum & | operator<< (StringAccum &sa, const String &str) |
| Append the contents of str to sa. | |
| StringAccum & | operator<< (StringAccum &sa, const StringAccum &x) |
| Append the contents of x to sa. | |
| StringAccum & | operator<< (StringAccum &sa, long i) |
| Append decimal representation of i to sa. | |
| StringAccum & | operator<< (StringAccum &sa, unsigned long u) |
| Append decimal representation of u to sa. | |
| StringAccum & | operator<< (StringAccum &sa, double d) |
| Append decimal representation of d to sa. | |
| StringAccum & | operator<< (StringAccum &sa, const void *ptr) |
| Append hexadecimal representation of ptr's value to sa. | |
Efficiently build up Strings from pieces.
Like the String class, StringAccum represents a string of characters. However, unlike a String, a StringAccum is inherently mutable, and efficiently supports building up a large string from many smaller pieces.
StringAccum objects support operator<<() operations for most fundamental data types. A StringAccum is generally built up by operator<<(), and then turned into a String by the take_string() method. Extracting the String from a StringAccum does no memory allocation or copying; the StringAccum's memory is donated to the String.
When there is not enough memory to add requested characters to a StringAccum object, the object becomes a special "out-of-memory" StringAccum. Out-of-memory objects are contagious: the result of any concatenation operation involving an out-of-memory StringAccum is another out-of-memory StringAccum. Calling take_string() on an out-of-memory StringAccum returns an out-of-memory String.
Note that appending an out-of-memory String to a StringAccum does not make the StringAccum out-of-memory.
|
inline |
Construct an empty StringAccum (with length 0).
|
inlineexplicit |
Construct a StringAccum with room for at least capacity characters.
| capacity | initial capacity |
If capacity == 0, the StringAccum is created empty. If capacity is too large (so that capacity bytes of memory can't be allocated), the StringAccum falls back to a smaller capacity (possibly zero).
|
inline |
Construct a StringAccum containing the characters in str.
|
inline |
Construct a StringAccum containing a copy of x.
|
inline |
Destroy a StringAccum, freeing its memory.
|
inline |
Assign this StringAccum to x.
|
inline |
Return the contents of the StringAccum.
The returned data() value points to length() bytes of writable memory (unless the StringAccum itself is const).
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inline |
Return the length of the StringAccum.
|
inline |
Return the StringAccum's current capacity.
The capacity is the maximum length the StringAccum can hold without incurring a memory allocation. Returns -1 for out-of-memory StringAccums.
| const char * StringAccum::c_str | ( | ) |
Null-terminate this StringAccum and return its data.
Note that the null character does not contribute to the StringAccum's length(), and later append() and similar operations can overwrite it. If appending the null character fails, the StringAccum becomes out-of-memory and the returned value is a null string.
|
inline |
Test if the StringAccum contains characters.
|
inline |
Test if the StringAccum is empty.
|
inline |
Test if the StringAccum is empty.
Returns true iff length() == 0.
|
inline |
Return an iterator for the first character in the StringAccum.
StringAccum iterators are simply pointers into string data, so they are quite efficient.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inline |
Return an iterator for the end of the StringAccum.
The return value points one character beyond the last character in the StringAccum.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inline |
|
inline |
Return a reference to the ith character in the string.
| i | character index |
|
inline |
Return the first character in the string.
|
inline |
Return a reference to the first character in the string.
|
inline |
Return the last character in the string.
|
inline |
Return a reference to the last character in the string.
|
inline |
Test if the StringAccum is out-of-memory.
| void StringAccum::assign_out_of_memory | ( | ) |
Change this StringAccum into an out-of-memory StringAccum.
|
inline |
Clear the StringAccum's comments.
All characters in the StringAccum are erased. Also resets the StringAccum's out-of-memory status.
|
inline |
Reserve space for at least n characters.
reserve() does not change the string's length(), only its capacity(). In a frequent usage pattern, code calls reserve(), passing an upper bound on the characters that could be written by a series of operations. After writing into the returned buffer, adjust_length() is called to account for the number of characters actually written.
|
inline |
Set the StringAccum's length to len.
| len | new length in characters |
| int StringAccum::resize | ( | int | len | ) |
|
inline |
Adjust the StringAccum's length.
| delta | length adjustment |
The StringAccum's length after adjust_length(delta) equals its old length plus delta. Generally adjust_length() is used after a call to reserve().
|
inline |
Reserve space and adjust length in one operation.
| nadjust | number of characters to reserve and adjust length |
| nreserve | additional characters to reserve |
This operation combines the effects of reserve(nadjust + nreserve) and adjust_length(nadjust). Returns the result of the reserve() call.
|
inline |
Remove characters from the end of the StringAccum.
| n | number of characters to remove |
Same as adjust_length(-n).
|
inline |
Append character c to the StringAccum.
| c | character to append |
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inline |
Append Unicode character ch encoded in UTF-8.
Appends nothing if ch is not a valid Unicode character.
|
inline |
Append the null-terminated C string s to this StringAccum.
| s | data to append |
|
inline |
Append the first len characters of s to this StringAccum.
| s | data to append |
| len | length of data |
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inline |
Append the data from first to last to the end of this StringAccum.
Does nothing if first >= last.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
| void StringAccum::append_fill | ( | int | c, |
| int | len | ||
| ) |
Append len copies of character c to the StringAccum.
| void StringAccum::append_numeric | ( | String::intmax_t | num, |
| int | base = 10, |
||
| bool | uppercase = true |
||
| ) |
Append string representation of x to this StringAccum.
| x | number to append |
| base | numeric base: must be 8, 10, or 16 |
| uppercase | true means use uppercase letters in base 16 |
| void StringAccum::append_numeric | ( | String::uintmax_t | num, |
| int | base = 10, |
||
| bool | uppercase = true |
||
| ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
| StringAccum & StringAccum::snprintf | ( | int | n, |
| const char * | format, | ||
| ... | |||
| ) |
Append result of snprintf() to this StringAccum.
| n | maximum number of characters to print |
| format | format argument to snprintf() |
The terminating null character is not appended to the string.
| String StringAccum::take_string | ( | ) |
Return a String object with this StringAccum's contents.
This operation donates the StringAccum's memory to the returned String. After a call to take_string(), the StringAccum object becomes empty, and any future append() operations may cause memory allocations. If the StringAccum is out-of-memory, the returned String is also out-of-memory, but the StringAccum's out-of-memory state is reset.
| void StringAccum::swap | ( | StringAccum & | x | ) |
Swap this StringAccum's contents with x.
|
related |
|
related |
|
related |
|
related |
Append "true" or "false" to sa, depending on x.
|
related |
Append decimal representation of x to sa.
|
related |
Append the contents of str to sa.
|
related |
Append the contents of x to sa.
|
related |
Append decimal representation of i to sa.
|
related |
Append decimal representation of u to sa.
|
related |
Append decimal representation of d to sa.
|
related |
Append hexadecimal representation of ptr's value to sa.