My Project
|
A NON-thread-safe, mutable sequence of characters(Binary is also possible). More...
#include <StringBuilder.h>
Public Types | |
typedef std::string | string_type |
The standard string object which correspond to the builder. More... | |
typedef UserAllocator | user_allocator |
typedef char | Char |
Public Member Functions | |
StringBuilderT (const string_type &sz) | |
Creates a new builder with the content of the given string. More... | |
StringBuilderT (const Char *sz) | |
Creates a new builder with the content of the given character array. More... | |
StringBuilderT (Char ch, size_t count) | |
Creates a new builder with the given character repeated multiple times over the array. More... | |
StringBuilderT (size_t reserved) | |
Creates a new builder with an empty buffer. More... | |
StringBuilderT () | |
Creates a new builder with an empty buffer. More... | |
~StringBuilderT () | |
Deletes the builder. More... | |
void | reserve (size_t length) |
Reserves a given number of character slots. More... | |
void | resize (size_t length) |
resize the buffer | |
size_t | length () const |
Retrieves the length of the content within the builder. More... | |
size_t | size () const |
void | clear () |
Clears the content of the builder. More... | |
bool | empty () const |
Retrieves whether the builder is empty. More... | |
void | append (Char c) |
Appends a character to the content of the builder. More... | |
void | append (const string_type &sz) |
Appends a string to the content of the builder. More... | |
void | append (const Char *sz) |
Appends a character array to the content of the builder. More... | |
void | append (const Char *sz, size_t len) |
Appends a character array to the content of the builder. More... | |
void | append (const StringBuilderT< UserAllocator > &b) |
Appends the content of a builder to the content of this builder. More... | |
void | append (int32 i) |
Appends the integer value, after converting it to a string, to the content of the builder. More... | |
void | append (uint32 i) |
See above. More... | |
void | append (uint64 i) |
See above. More... | |
void | appendBinary (uint16 i) |
void | appendBinary (uint32 i) |
See above. More... | |
void | appendHex (uint8 i) |
Appends the integer value, after converting it to a fm::string, in hexadecimal, to the content of the builder. More... | |
template<class T > | |
void | appendHex (const T &i) |
See above. More... | |
void | append (long i) |
See above. More... | |
void | append (float f) |
Appends the floating-point value, after converting it to a string, to the content of the builder. More... | |
void | append (double f) |
See above. More... | |
template<typename TYPE > | |
void | WriteAt (int nIndex, const TYPE &val) |
this is useful for writing to a previous cached location. More... | |
void | WriteAt (int nIndex, const Char *data, size_t nSize) |
template<typename TYPE > | |
StringBuilderT & | operator+= (const TYPE &val) |
Appends a value to the content of the builder. More... | |
void | appendLine (const Char *sz) |
Appends a character array to the content of the builder. More... | |
void | remove (int32 start) |
Removes a section of the content of the builder. More... | |
void | remove (int32 start, int32 end) |
Removes a section of the content of the builder. More... | |
void | pop_back () |
Removes the last character of the content of the builder. More... | |
template<typename TYPE > | |
void | set (const TYPE &val) |
Sets the content of the builder to a given value. More... | |
template<typename TYPE > | |
StringBuilderT & | operator= (const TYPE &val) |
See above. More... | |
string_type | ToString () const |
Converts the content of the builder to a standard string. More... | |
const Char * | c_str () const |
Converts the content of the builder to a character array. More... | |
operator const Char * () const | |
See above. More... | |
Char * | str () |
get raw string | |
Char & | operator[] (const int nIndex) |
overload the operator []. More... | |
int32 | index (Char c) const |
Retrieves the index of the first character within the content of the builder that is equivalent to the given character. More... | |
int32 | rindex (Char c) const |
Retrieves the index of the last character within the content of the builder that is equivalent to the given character. More... | |
Char | back () const |
Retrieves the last character within the content of the builder. More... | |
A NON-thread-safe, mutable sequence of characters(Binary is also possible).
A string buffer is like a std::string, but does not have SSO(16 bytes small string optimization); use ParaEngine::NPLString if one wants SSO support. A string buffer is usually associated with a memory pool allocator such as CNPLPool_Char_alloc<char>. At any point in time it contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls.
String buffers are NOT safe for use by multiple threads. One should use a mutex if the object is shared by multiple thread.
The principal operations on a StringBuffer are the append, which are overloaded so as to accept data of many types. Each effectively converts a given datum to a string and then appends the characters of that string to the string buffer.
Every string buffer has a capacity. As long as the length of the character sequence contained in the string buffer does not exceed the capacity, it is not necessary to allocate a new internal buffer array. If the internal buffer overflows, it is automatically made larger.
: c_str() is NOT null terminated, unless one manually append('\0'); so always use a size() to retrieve it.
typedef std::string ParaEngine::StringBuilderT< UserAllocator >::string_type |
The standard string object which correspond to the builder.
ParaEngine::StringBuilderT< UserAllocator >::StringBuilderT | ( | const string_type & | sz | ) |
Creates a new builder with the content of the given string.
sz | A string. Its content will be copied within the builder. |
ParaEngine::StringBuilderT< UserAllocator >::StringBuilderT | ( | const Char * | sz | ) |
Creates a new builder with the content of the given character array.
sz | A character array. Its content will be copied within the builder. It must terminate with an element containing the 'zero' value. |
ParaEngine::StringBuilderT< UserAllocator >::StringBuilderT | ( | Char | ch, |
size_t | count | ||
) |
Creates a new builder with the given character repeated multiple times over the array.
ch | A character to repeat. |
count | The number of times to repeat the given character. |
ParaEngine::StringBuilderT< UserAllocator >::StringBuilderT | ( | size_t | reserved | ) |
Creates a new builder with an empty buffer.
reserved | The number of character slots to reserve within the empty buffer. |
ParaEngine::StringBuilderT< UserAllocator >::StringBuilderT | ( | ) |
Creates a new builder with an empty buffer.
ParaEngine::StringBuilderT< UserAllocator >::~StringBuilderT | ( | ) |
Deletes the builder.
Its buffer will be cleared. Any pointers to its data will be dangling.
void ParaEngine::StringBuilderT< UserAllocator >::append | ( | Char | c | ) |
Appends a character to the content of the builder.
c | A character. May not be the 'zero' value. |
void ParaEngine::StringBuilderT< UserAllocator >::append | ( | const string_type & | sz | ) |
Appends a string to the content of the builder.
sz | A string. |
void ParaEngine::StringBuilderT< UserAllocator >::append | ( | const Char * | sz | ) |
Appends a character array to the content of the builder.
sz | A character array. It must terminate with an element containing the 'zero' value. |
void ParaEngine::StringBuilderT< UserAllocator >::append | ( | const Char * | sz, |
size_t | len | ||
) |
Appends a character array to the content of the builder.
sz | A character array. It should not contain any 'zero' characters before 'len' |
len | The number of characters to read from sz. |
void ParaEngine::StringBuilderT< UserAllocator >::append | ( | const StringBuilderT< UserAllocator > & | b | ) |
Appends the content of a builder to the content of this builder.
b | A string builder. |
void ParaEngine::StringBuilderT< UserAllocator >::append | ( | int32 | i | ) |
Appends the integer value, after converting it to a string, to the content of the builder.
i | An integer value. |
void ParaEngine::StringBuilderT< UserAllocator >::append | ( | uint32 | i | ) |
See above.
void ParaEngine::StringBuilderT< UserAllocator >::append | ( | uint64 | i | ) |
See above.
|
inline |
See above.
void ParaEngine::StringBuilderT< UserAllocator >::append | ( | float | f | ) |
Appends the floating-point value, after converting it to a string, to the content of the builder.
If the floating-point value is the special token that represents infinity, the string "INF" is appended. If it represents the negative infinity, the string "-INF" is appended. If it represents the impossibility, the string "NaN" is appended.
f | A floating-point value. |
void ParaEngine::StringBuilderT< UserAllocator >::append | ( | double | f | ) |
See above.
void ParaEngine::StringBuilderT< UserAllocator >::appendBinary | ( | uint32 | i | ) |
See above.
void ParaEngine::StringBuilderT< UserAllocator >::appendHex | ( | uint8 | i | ) |
Appends the integer value, after converting it to a fm::string, in hexadecimal, to the content of the builder.
The size of the integer will determine the number of characters used.
i | An unsigned integer value. |
|
inline |
See above.
void ParaEngine::StringBuilderT< UserAllocator >::appendLine | ( | const Char * | sz | ) |
Appends a character array to the content of the builder.
A newline character will be appended after the character array.
sz | A character array. It must terminate with an element containing the 'zero' value. |
|
inline |
Retrieves the last character within the content of the builder.
const StringBuilderT< UserAllocator >::Char * ParaEngine::StringBuilderT< UserAllocator >::c_str | ( | ) | const |
Converts the content of the builder to a character array.
Please note the char array is not null terminated.
void ParaEngine::StringBuilderT< UserAllocator >::clear | ( | ) |
Clears the content of the builder.
This does not re-allocate a new buffer.
|
inline |
Retrieves whether the builder is empty.
A builder is considered empty when it has no content, regardless of the size or allocation status of its buffer.
int32 ParaEngine::StringBuilderT< UserAllocator >::index | ( | Char | c | ) | const |
Retrieves the index of the first character within the content of the builder that is equivalent to the given character.
c | The character to match. |
|
inline |
Retrieves the length of the content within the builder.
|
inline |
See above.
|
inline |
Appends a value to the content of the builder.
This is a shortcut for the append function.
val | A value. This may be numerical, a character, a character array or a string. |
|
inline |
See above.
|
inline |
overload the operator [].
You are at your own risk if nIndex is out of risk. There is no check for performance reasons.
|
inline |
Removes the last character of the content of the builder.
void ParaEngine::StringBuilderT< UserAllocator >::remove | ( | int32 | start | ) |
Removes a section of the content of the builder.
Every character that occurs after the given index will be removed, resulting in a shrunk string.
start | An index within the content of the builder. |
void ParaEngine::StringBuilderT< UserAllocator >::remove | ( | int32 | start, |
int32 | end | ||
) |
Removes a section of the content of the builder.
The substring defined by the 'start' and 'end' indices will be removed. The 'start' character is removed and is replaced by the 'end' character.
start | The index of the first character of the substring to remove. |
end | The index of the first character after the removed substring. |
void ParaEngine::StringBuilderT< UserAllocator >::reserve | ( | size_t | length | ) |
Reserves a given number of character slots.
Internally it uses buffer 32, 64, 128, 256, 512, 1024, 2048. Larger than 2048, length is used etc.
length | The number of character slots to reserve. |
int32 ParaEngine::StringBuilderT< UserAllocator >::rindex | ( | Char | c | ) | const |
Retrieves the index of the last character within the content of the builder that is equivalent to the given character.
c | The character to match. |
|
inline |
Sets the content of the builder to a given value.
This clears the builder of all its content and appends the given value.
val | A value. This may be numerical, a character, a character array or a string. |
|
inline |
Converts the content of the builder to a standard string.
|
inline |
this is useful for writing to a previous cached location.