UCommon
|
A copy-on-write string class that operates by reference count. More...
#include <string.h>
Public Types | |
enum | { SENSITIVE = 0x00, INSENSITIVE = 0x01 } |
This is an internal class which contains the actual string data along with some control fields. More... | |
Public Member Functions | |
int | __isoc99_scanf (const char *format,...) |
Scan input items from a string object. More... | |
int | __isoc99_vscanf (const char *format, va_list args) |
Scan input items from a string object. More... | |
void | add (const char *text) |
Append null terminated text to our string buffer. More... | |
void | add (char character) |
Append a single character to our string buffer. More... | |
char | at (int position) const |
Return character found at a specific position in the string. More... | |
const char * | begin (void) const |
Get pointer to first character in string for iteration. More... | |
char * | c_mem () |
const char * | c_str (void) const |
Get character text buffer of string object. More... | |
size_t | ccount (const char *list) const |
Count number of occurrences of characters in string. More... | |
void | chop (const char *list) |
Chop trailing characters from the string. More... | |
void | chop (size_t count=1) |
Chop trailing characters from text. More... | |
const char * | chr (char character) const |
Find pointer in string where specified character appears. More... | |
void | clear (size_t offset) |
Clear a field of a filled string with filler. More... | |
void | clear (void) |
Clear string by setting to empty. | |
virtual int | compare (const char *string) const |
Compare the values of two string. More... | |
String | copy (size_t offset, size_t size) const |
Convenience method for substring extraction. More... | |
size_t | count (void) const |
Count all characters in the string (strlen). More... | |
void | cut (size_t offset, size_t size=0) |
Cut (remove) text from string. More... | |
char * | data (void) |
Get memory text buffer of string object. More... | |
const char * | end (void) const |
Get pointer to last character in string for iteration. More... | |
void | erase (void) |
Erase string memory. | |
void | fill (size_t size, char fill) |
const char * | find (const char *list, size_t offset=0) const |
Find a character in the string. More... | |
bool | full (void) const |
Test if the string's allocated space is all used up. More... | |
String | get (size_t offset, size_t size=0) const |
Get a new string object as a substring of the current object. More... | |
String | left (size_t size) const |
Convenience method for left of string. More... | |
size_t | len (void) const |
Get length of string. More... | |
void | lower (void) |
Convert string to lower case. | |
size_t | offset (const char *pointer) const |
Find offset of a pointer into our string buffer. More... | |
String & | operator & (const char *text) |
Concatenate null terminated text to our object. More... | |
const char * | operator * () const |
Reference raw text buffer by pointer operator. More... | |
bool | operator *= (const char *substring) |
bool | operator *= (regex &expr) |
String & | operator *= (size_t number) |
Delete a specified number of characters from start of string. More... | |
operator bool () const | |
Test if string has data. More... | |
operator const char * () const | |
Casting reference to raw text string. More... | |
bool | operator! () const |
Test if string is empty. More... | |
bool | operator!= (const char *text) const |
Compare our object with null terminated text. More... | |
String & | operator% (short &value) |
Parse short integer value from a string. More... | |
String & | operator% (unsigned short &value) |
Parse short integer value from a string. More... | |
String & | operator% (long &value) |
Parse long integer value from a string. More... | |
String & | operator% (unsigned long &value) |
Parse long integer value from a string. More... | |
String & | operator% (double &value) |
Parse double value from a string. More... | |
String & | operator% (const char *text) |
Parse text from a string in a scan expression. More... | |
String & | operator&= (const char *text) |
String | operator() (int offset, size_t size) const |
Get a new substring through object expression. More... | |
const char * | operator() (int offset) const |
Reference a string in the object by relative offset. More... | |
const String | operator+ (const char *text) const |
Concatenate null terminated text to our object. More... | |
String & | operator++ (void) |
Delete first character from string. | |
String & | operator+= (const char *text) |
Concatenate text to an existing string object. More... | |
String & | operator+= (size_t number) |
Delete a specified number of characters from start of string. More... | |
String & | operator-- (void) |
Delete last character from string. | |
String & | operator-= (size_t number) |
Delete a specified number of characters from end of string. More... | |
bool | operator< (const char *text) const |
Compare our object with null terminated text. More... | |
String & | operator<< (const char *text) |
String & | operator<< (char code) |
bool | operator<= (const char *text) const |
Compare our object with null terminated text. More... | |
String & | operator= (const String &object) |
Assign our string with the cstring of another object. More... | |
String & | operator= (const char *text) |
Assign text to our existing buffer. More... | |
bool | operator== (const char *text) const |
Compare our object with null terminated text. More... | |
bool | operator> (const char *text) const |
Compare our object with null terminated text. More... | |
bool | operator>= (const char *text) const |
Compare our object with null terminated text. More... | |
const char | operator[] (int offset) const |
Reference a single character in string object by array offset. More... | |
String & | operator^= (const String &object) |
Create new cow instance and assign value from another string object. More... | |
String & | operator^= (const char *text) |
Create new cow instance and assign value from null terminated text. More... | |
String & | operator| (const char *text) |
Concatenate null terminated text to our object. More... | |
String & | operator|= (const char *text) |
Concatenate text to an existing string object. More... | |
void | paste (size_t offset, const char *text, size_t size=0) |
Insert (paste) text into string. More... | |
size_t | printf (const char *format,...) |
Print items into a string object. More... | |
const char * | rchr (char character) const |
Find pointer in string where specified character last appears. More... | |
unsigned | replace (const char *string, const char *text=NULL, unsigned flags=0) |
unsigned | replace (regex &expr, const char *text=NULL, unsigned flags=0) |
virtual bool | resize (size_t size) |
Resize and re-allocate string memory. More... | |
const char * | rfind (const char *list, size_t offset=npos) const |
Find last occurrence of character in the string. More... | |
String | right (size_t offset) const |
Convenience method for right of string. More... | |
void | rset (const char *text, char overflow, size_t offset, size_t size=0) |
Set a text field within our string object offset from the end of buffer. More... | |
const char * | rskip (const char *list, size_t offset=npos) const |
Skip trailing characters in the string. More... | |
void | rsplit (const char *pointer) |
Split the string by a pointer position. More... | |
void | rsplit (size_t offset) |
Split the string at a specific offset. More... | |
const char * | search (const char *string, unsigned instance=0, unsigned flags=0) const |
Search for a substring in the string. More... | |
const char * | search (regex &expr, unsigned instance=0, unsigned flags=0) const |
void | set (const char *text) |
Set string object to text of a null terminated string. More... | |
void | set (size_t offset, const char *text, size_t size=0) |
Set a portion of the string object at a specified offset to a text string. More... | |
void | set (const char *text, char overflow, size_t offset, size_t size=0) |
Set a text field within our string object. More... | |
size_t | size (void) const |
Get the size of currently allocated space for string. More... | |
const char * | skip (const char *list, size_t offset=0) const |
Skip lead characters in the string. More... | |
void | split (const char *pointer) |
Split the string by a pointer position. More... | |
void | split (size_t offset) |
Split the string at a specific offset. More... | |
String () | |
Create a new empty string object. | |
String (size_t size) | |
Create an empty string with a buffer pre-allocated to a specified size. More... | |
String (size_t size, const char *format,...) | |
Create a string by printf-like formating into a pre-allocated space of a specified size. More... | |
String (const char *text) | |
Create a string from null terminated text. More... | |
String (const char *text, size_t size) | |
Create a string from null terminated text up to a maximum specified size. More... | |
String (const char *text, const char *end) | |
Create a string for a substring. More... | |
String (const String &existing) | |
Construct a copy of a string object. More... | |
void | strip (const char *list) |
Strip lead and trailing characters from the string. More... | |
double | tod (char **pointer=NULL) |
Convert string to a double value. More... | |
char * | token (char **last, const char *list, const char *quote=NULL, const char *end=NULL) |
A thread-safe token parsing routine for strings objects. More... | |
long | tol (char **pointer=NULL) |
Convert string to a long value. More... | |
void | trim (const char *list) |
Trim lead characters from the string. More... | |
void | trim (size_t count=1) |
Trim lead characters from text. More... | |
bool | unquote (const char *quote) |
Unquote a quoted string. More... | |
void | upper (void) |
Convert string to upper case. | |
size_t | vprintf (const char *format, va_list args) |
Print items into a string object. More... | |
virtual | ~String () |
Destroy string. More... | |
![]() | |
ObjectProtocol * | copy (void) |
Retain (increase retention of) object when copying. | |
void | operator++ (void) |
Increase retention operator. | |
void | operator-- (void) |
Decrease retention operator. | |
virtual | ~ObjectProtocol () |
Required virtual destructor. | |
Static Public Member Functions | |
static char * | add (char *buffer, size_t size, const char *text) |
Safely append a null terminated string into an existing string in memory. More... | |
static char * | add (char *buffer, size_t size, const char *text, size_t max) |
Safely append a null terminated string into an existing string in memory. More... | |
static String | b64 (const uint8_t *binary, size_t size) |
Standard radix 64 string encoding. More... | |
static size_t | b64count (const char *str, bool ws=false) |
static size_t | b64decode (uint8_t *binary, const char *string, size_t size, bool ws=false) |
Standard radix 64 decoding. More... | |
static size_t | b64encode (char *string, const uint8_t *binary, size_t size, size_t width=0) |
Standard radix 64 encoding. More... | |
static size_t | b64size (size_t size) |
static unsigned | ccount (const char *text, const char *list) |
Count instances of characters in a list in a text buffer. More... | |
static bool | check (const char *string, size_t maximum, size_t minimum=0) |
Check if string is valid and in specific constraints. More... | |
static char * | chop (char *text, const char *list) |
Strip trailing characters from the text string. More... | |
static int | collate (const char *text1, const char *text2) |
static int | compare (const char *text1, const char *text2) |
Safe string collation function. More... | |
static int | compare (const char *text1, const char *text2, size_t size) |
Depreciated string comparison function. More... | |
static char * | copy (const char *text, size_t offset, size_t len) |
static size_t | count (const char *text) |
Safe version of strlen function. More... | |
static uint16_t | crc16 (uint8_t *binary, size_t size) |
ccitt 16 bit crc for binary data. More... | |
static uint32_t | crc24 (uint8_t *binary, size_t size) |
24 bit crc as used in openpgp. More... | |
static void | cut (char *text, size_t offset, size_t len) |
static char * | dup (const char *text) |
Duplicate null terminated text into the heap. More... | |
static bool | eq_case (const char *text1, const char *text2) |
Simple case insensitive equal test for strings. More... | |
static bool | eq_case (const char *text1, const char *text2, size_t size) |
Simple case insensitive equal test for strings. More... | |
static bool | equal (const char *text1, const char *text2) |
Simple equal test for strings. More... | |
static bool | equal (const char *text1, const char *text2, size_t size) |
Simple equal test for strings. More... | |
static void | erase (char *text) |
Erase string memory. More... | |
static char * | fill (char *text, size_t size, char character) |
Fill a section of memory with a fixed text character. More... | |
static const char * | find (const char *text, const char *key, const char *optional) |
Find position of substring within a string. More... | |
static char * | find (char *text, const char *list) |
Find the first occurrence of a character in a text buffer. More... | |
static void | fix (String &object) |
Fix and reset string object filler. More... | |
static String | hex (const uint8_t *binary, size_t size) |
Convert binary data buffer into hex string. More... | |
static size_t | hex2bin (const char *string, uint8_t *binary, size_t maxsize, bool wsflag=false) |
static size_t | hexcount (const char *str, bool ws=false) |
static size_t | hexdump (const uint8_t *binary, char *string, const char *format) |
Dump hex data to a string buffer. More... | |
static size_t | hexpack (uint8_t *binary, const char *string, const char *format) |
Pack hex data from a string buffer. More... | |
static size_t | hexsize (const char *format) |
static const char * | ifind (const char *text, const char *key, const char *optional) |
Find position of case insensitive substring within a string. More... | |
static char * | left (const char *text, size_t size) |
Duplicate null terminated text of specific size to heap. More... | |
static void | lower (char *text) |
Convert null terminated text to lower case. More... | |
static void | paste (char *text, size_t max, size_t offset, const char *data, size_t len=0) |
static const char * | pos (const char *text, ssize_t offset) |
Compute position in string. More... | |
static char * | rfind (char *text, const char *list) |
Find the last occurrence of a character in a text buffer. More... | |
static char * | right (const char *text, size_t size) |
static char * | rset (char *buffer, size_t size, const char *text) |
Set a field in a null terminated string relative to the end of text. More... | |
static char * | rskip (char *text, const char *list) |
Skip before trailing characters in a null terminated string. More... | |
static size_t | seek (char *text, const char *list) |
Offset until next occurrence of character in a text or length. More... | |
static char * | set (char *buffer, size_t size, const char *text) |
Safely set a null terminated string buffer in memory. More... | |
static char * | set (char *buffer, size_t size, const char *text, size_t max) |
Safely set a null terminated string buffer in memory. More... | |
static char * | skip (char *text, const char *list) |
Skip after lead characters in a null terminated string. More... | |
static char * | strip (char *text, const char *list) |
Skip lead and remove trailing characters from a text string. More... | |
static void | swap (String &object1, String &object2) |
Swap the cstring references between two strings. More... | |
static double | tod (const char *text, char **pointer=NULL) |
Convert text to a double value. More... | |
static char * | token (char *text, char **last, const char *list, const char *quote=NULL, const char *end=NULL) |
A thread-safe token parsing routine for null terminated strings. More... | |
static long | tol (const char *text, char **pointer=NULL) |
Convert text to a long value. More... | |
static char * | trim (char *text, const char *list) |
Return start of string after characters to trim from beginning. More... | |
static char * | unquote (char *text, const char *quote) |
Unquote a quoted null terminated string. More... | |
static void | upper (char *text) |
Convert null terminated text to upper case. More... | |
Static Public Attributes | |
static const char | eos = '\0' |
static const size_t | npos = ((size_t)-1) |
Protected Member Functions | |
virtual cstring * | c_copy (void) const |
Return cstring to use in copy constructors. More... | |
virtual void | cow (size_t size=0) |
Copy on write operation for cstring. More... | |
cstring * | create (size_t size) const |
Factory create a cstring object of specified size. More... | |
bool | equal (const char *string) const |
Test if two string values are equal. More... | |
size_t | getStringSize (void) const |
virtual void | release (void) |
Decrease retention of our reference counted cstring. More... | |
virtual void | retain (void) |
Increase retention of our reference counted cstring. More... | |
Protected Attributes | |
cstring * | str |
cstring instance our object references. More... | |
A copy-on-write string class that operates by reference count.
This string class anchors a counted object that is managed as a copy-on-write instance of the string data. This means that multiple instances of the string class can refer to the same string in memory if it has not been modifed, which reduces heap allocation. The string class offers functions to manipulate both the string object, and generic safe string functions to manipulate ordinary null terminated character arrays directly in memory.
anonymous enum |
This is an internal class which contains the actual string data along with some control fields.
The string can be either NULL terminated or filled like a Pascal-style string, but with a user selected fill character. The cstring object is an overdraft object, as the actual string text which is of unknown size follows immediately after the class control data. This class is primarily for internal use.
ucommon::String::String | ( | size_t | size | ) |
Create an empty string with a buffer pre-allocated to a specified size.
size | of buffer to allocate. |
ucommon::String::String | ( | size_t | size, |
const char * | format, | ||
... | |||
) |
ucommon::String::String | ( | const char * | text | ) |
Create a string from null terminated text.
text | to use for string. |
ucommon::String::String | ( | const char * | text, |
size_t | size | ||
) |
Create a string from null terminated text up to a maximum specified size.
text | to use for string. |
size | limit of new string. |
ucommon::String::String | ( | const char * | text, |
const char * | end | ||
) |
Create a string for a substring.
The end of the substring is a pointer within the substring itself.
text | to use for string. |
end | of text in substring. |
ucommon::String::String | ( | const String & | existing | ) |
Construct a copy of a string object.
Our copy inherets the same reference counted instance of cstring as in the original.
existing | string to copy from. |
|
virtual |
Destroy string.
De-reference cstring. If last reference to cstring, then also remove cstring from heap.
int ucommon::String::__isoc99_scanf | ( | const char * | format, |
... | |||
) |
Scan input items from a string object.
format | string of input to scan. |
int ucommon::String::__isoc99_vscanf | ( | const char * | format, |
va_list | args | ||
) |
Scan input items from a string object.
format | string of input to scan. |
args | list to scan into. |
void ucommon::String::add | ( | const char * | text | ) |
Append null terminated text to our string buffer.
text | to append. |
void ucommon::String::add | ( | char | character | ) |
Append a single character to our string buffer.
character | to append. |
|
static |
Safely append a null terminated string into an existing string in memory.
If the resulting string is too large to fit into the buffer, it is truncated to the size.
buffer | to set. |
size | of buffer. Includes null byte at end of string. |
text | to set in buffer. |
|
static |
Safely append a null terminated string into an existing string in memory.
If the resulting string is too large to fit into the buffer, it is truncated to the size.
buffer | to set. |
size | of buffer. Includes null byte at end of string. |
text | to set in buffer. |
max | size of text to append. |
char ucommon::String::at | ( | int | position | ) | const |
Return character found at a specific position in the string.
position | in string, negative values computed from end. |
|
static |
Standard radix 64 string encoding.
binary | data to encode. |
size | of binary data to encode. |
|
static |
Standard radix 64 decoding.
binary | data to save. |
string | of encoded text. |
size | of destination buffer. |
ws | flag to skip whitespaces. |
|
static |
Standard radix 64 encoding.
string | of encoded text save into. |
binary | data to encode. |
size | of binary data to encode. |
width | of string buffer for data if partial supported. |
const char* ucommon::String::begin | ( | void | ) | const |
Get pointer to first character in string for iteration.
|
protectedvirtual |
Return cstring to use in copy constructors.
Is virtual for memstring.
Reimplemented in ucommon::memstring.
const char* ucommon::String::c_str | ( | void | ) | const |
Get character text buffer of string object.
size_t ucommon::String::ccount | ( | const char * | list | ) | const |
Count number of occurrences of characters in string.
list | of characters to find. |
|
static |
Count instances of characters in a list in a text buffer.
text | buffer to examine. |
list | of characters to count in buffer. |
|
static |
Check if string is valid and in specific constraints.
string | to check. |
maximum | size allowed. |
minimum | size required. |
void ucommon::String::chop | ( | const char * | list | ) |
Chop trailing characters from the string.
list | of characters to remove. |
|
inline |
|
static |
Strip trailing characters from the text string.
This function will modify memory.
text | buffer to examine. |
list | of characters to chop from trailing end of string. |
const char* ucommon::String::chr | ( | char | character | ) | const |
Find pointer in string where specified character appears.
character | to find. |
void ucommon::String::clear | ( | size_t | offset | ) |
Clear a field of a filled string with filler.
offset | to start of field to clear. |
|
virtual |
Compare the values of two string.
This is a virtual so that it can be overridden for example if we want to create strings which ignore case, or which have special ordering rules.
string | to compare with. |
|
static |
Safe string collation function.
text1 | to compare. |
text2 | to compare. |
|
static |
Depreciated string comparison function.
text1 | to compare. |
text2 | to compare. |
size | limit of strings to compare. |
|
inline |
size_t ucommon::String::count | ( | void | ) | const |
Count all characters in the string (strlen).
|
static |
Safe version of strlen function.
Accepts NULL as 0 length strings.
text | string. |
|
protectedvirtual |
Copy on write operation for cstring.
This always creates a new unique copy for write/modify operations and is a virtual for memstring to disable.
size | to add to allocated space when creating new cstring. |
|
static |
ccitt 16 bit crc for binary data.
binary | data to sum. |
size | of binary data to sum. |
|
static |
24 bit crc as used in openpgp.
binary | data to sum. |
size | of binary data to sum. |
|
protected |
Factory create a cstring object of specified size.
size | of allocated space for string buffer. |
void ucommon::String::cut | ( | size_t | offset, |
size_t | size = 0 |
||
) |
Cut (remove) text from string.
offset | to start of text field to remove. |
size | of text field to remove or 0 to remove to end of string. |
char* ucommon::String::data | ( | void | ) |
Get memory text buffer of string object.
|
static |
Duplicate null terminated text into the heap.
text | to duplicate. |
const char* ucommon::String::end | ( | void | ) | const |
Get pointer to last character in string for iteration.
|
static |
Simple case insensitive equal test for strings.
text1 | to test. |
text2 | to test. |
|
static |
Simple case insensitive equal test for strings.
text1 | to test. |
text2 | to test. |
size | limit of strings to compare. |
|
protected |
Test if two string values are equal.
string | to compare with. |
|
static |
Simple equal test for strings.
text1 | to test. |
text2 | to test. |
|
static |
Simple equal test for strings.
text1 | to test. |
text2 | to test. |
size | limit of strings to compare. |
|
static |
Erase string memory.
Often used to clear out passwords.
text | string to erase. |
|
static |
Fill a section of memory with a fixed text character.
Adds a null byte at the end.
text | buffer to fill. |
size | of text buffer with null terminated byte. |
character | to fill with. |
const char* ucommon::String::find | ( | const char * | list, |
size_t | offset = 0 |
||
) | const |
Find a character in the string.
list | of characters to search for. |
offset | to start of search. |
|
static |
Find position of substring within a string.
text | to search in. |
key | string to locate. |
optional | separator chars if formatted as list of keys. |
|
static |
Find the first occurrence of a character in a text buffer.
text | buffer to examine. |
list | of characters to search for. |
|
static |
Fix and reset string object filler.
object | to fix. |
bool ucommon::String::full | ( | void | ) | const |
Test if the string's allocated space is all used up.
String ucommon::String::get | ( | size_t | offset, |
size_t | size = 0 |
||
) | const |
Get a new string object as a substring of the current object.
offset | of substring. |
size | of substring or 0 if to end. |
|
static |
Convert binary data buffer into hex string.
binary | data to convert. |
size | of data. |
|
static |
Dump hex data to a string buffer.
binary | memory to dump. |
string | to save into. |
format | string to convert with. |
|
static |
Pack hex data from a string buffer.
binary | memory to pack. |
string | to save into. |
format | string to convert with. |
whitespace | flag to ignore. |
|
static |
Find position of case insensitive substring within a string.
text | to search in. |
key | string to locate. |
optional | separator chars if formatted as list of keys. |
|
inline |
|
static |
Duplicate null terminated text of specific size to heap.
text | to duplicate. |
size | of text, maximum space allocated. |
size_t ucommon::String::len | ( | void | ) | const |
|
static |
Convert null terminated text to lower case.
text | to convert. |
size_t ucommon::String::offset | ( | const char * | pointer | ) | const |
Find offset of a pointer into our string buffer.
This can be used to find the offset position of a pointer returned by find, for example. This is used when one needs to convert a member function that returns a pointer to call a member function that operates by a offset value. If the pointer is outside the range of the string then npos is returned.
pointer | into our object's string buffer. |
String& ucommon::String::operator & | ( | const char * | text | ) |
Concatenate null terminated text to our object.
This directly appends the text to the string buffer and does not resize the object if the existing cstring allocation space is fully used.
text | to concatenate. |
|
inline |
String& ucommon::String::operator *= | ( | size_t | number | ) |
Delete a specified number of characters from start of string.
number | of characters to delete. |
ucommon::String::operator bool | ( | ) | const |
Test if string has data.
|
inline |
bool ucommon::String::operator! | ( | ) | const |
Test if string is empty.
bool ucommon::String::operator!= | ( | const char * | text | ) | const |
Compare our object with null terminated text.
Compare method is used.
text | to compare with. |
String& ucommon::String::operator% | ( | short & | value | ) |
Parse short integer value from a string.
value | to store. |
String& ucommon::String::operator% | ( | unsigned short & | value | ) |
Parse short integer value from a string.
value | to store. |
String& ucommon::String::operator% | ( | long & | value | ) |
Parse long integer value from a string.
value | to store. |
String& ucommon::String::operator% | ( | unsigned long & | value | ) |
Parse long integer value from a string.
value | to store. |
String& ucommon::String::operator% | ( | double & | value | ) |
Parse double value from a string.
value | to store. |
String& ucommon::String::operator% | ( | const char * | text | ) |
Parse text from a string in a scan expression.
text | to scan and bypass. |
String ucommon::String::operator() | ( | int | offset, |
size_t | size | ||
) | const |
Get a new substring through object expression.
offset | of substring. |
size | of substring or 0 if to end. |
const char* ucommon::String::operator() | ( | int | offset | ) | const |
Reference a string in the object by relative offset.
Positive offsets are from the start of the string, negative from the end.
offset | to string position. |
const String ucommon::String::operator+ | ( | const char * | text | ) | const |
Concatenate null terminated text to our object.
text | to concatenate. |
String& ucommon::String::operator+= | ( | const char * | text | ) |
Concatenate text to an existing string object.
text | to add. |
String& ucommon::String::operator+= | ( | size_t | number | ) |
Delete a specified number of characters from start of string.
number | of characters to delete. |
String& ucommon::String::operator-= | ( | size_t | number | ) |
Delete a specified number of characters from end of string.
number | of characters to delete. |
bool ucommon::String::operator< | ( | const char * | text | ) | const |
Compare our object with null terminated text.
Compare method is used.
text | to compare with. |
bool ucommon::String::operator<= | ( | const char * | text | ) | const |
Compare our object with null terminated text.
Compare method is used.
text | to compare with. |
Assign our string with the cstring of another object.
If we had an active string reference, it is released. The object now has a duplicate reference to the cstring of the other object.
object | to assign from. |
String& ucommon::String::operator= | ( | const char * | text | ) |
Assign text to our existing buffer.
This performs a set method.
text | to assign from. |
bool ucommon::String::operator== | ( | const char * | text | ) | const |
Compare our object with null terminated text.
text | to compare with. |
bool ucommon::String::operator> | ( | const char * | text | ) | const |
Compare our object with null terminated text.
Compare method is used.
text | to compare with. |
bool ucommon::String::operator>= | ( | const char * | text | ) | const |
Compare our object with null terminated text.
Compare method is used.
text | to compare with. |
const char ucommon::String::operator[] | ( | int | offset | ) | const |
Reference a single character in string object by array offset.
offset | to character. |
Create new cow instance and assign value from another string object.
object | to assign from. |
String& ucommon::String::operator^= | ( | const char * | text | ) |
Create new cow instance and assign value from null terminated text.
text | to assign from. |
String& ucommon::String::operator| | ( | const char * | text | ) |
Concatenate null terminated text to our object.
This creates a new copy-on-write instance to hold the concatenated string. This will eventually replace '+' when + creates a new string instance instead.
text | to concatenate. |
String& ucommon::String::operator|= | ( | const char * | text | ) |
Concatenate text to an existing string object.
This will use the old behavior when +/= updated.
void ucommon::String::paste | ( | size_t | offset, |
const char * | text, | ||
size_t | size = 0 |
||
) |
Insert (paste) text into string.
offset | to start paste. |
text | to paste. |
size | of text to paste. |
|
static |
Compute position in string.
text | of string. |
offset | from start, negative values from end. |
size_t ucommon::String::printf | ( | const char * | format, |
... | |||
) |
Print items into a string object.
format | string of print format. |
const char* ucommon::String::rchr | ( | char | character | ) | const |
Find pointer in string where specified character last appears.
character | to find. |
|
protectedvirtual |
Decrease retention of our reference counted cstring.
May be overridden for memstring which has fixed cstring object.
Implements ucommon::ObjectProtocol.
|
virtual |
Resize and re-allocate string memory.
size | to allocate for string. |
|
protectedvirtual |
Increase retention of our reference counted cstring.
May be overridden for memstring which has fixed cstring object.
Implements ucommon::ObjectProtocol.
const char* ucommon::String::rfind | ( | const char * | list, |
size_t | offset = npos |
||
) | const |
Find last occurrence of character in the string.
list | of characters to search for. |
offset | to start of search. Default is end of string. |
|
static |
Find the last occurrence of a character in a text buffer.
text | buffer to examine. |
list | of characters to search for. |
|
inline |
void ucommon::String::rset | ( | const char * | text, |
char | overflow, | ||
size_t | offset, | ||
size_t | size = 0 |
||
) |
Set a text field within our string object offset from the end of buffer.
text | to set. |
overflow | character to use as filler if text is too short. |
offset | from end of object string buffer to set text at. |
size | of part of buffer to set with text and overflow. |
|
static |
Set a field in a null terminated string relative to the end of text.
buffer | to modify. |
size | of field to set. |
text | to replace end of string with. |
const char* ucommon::String::rskip | ( | const char * | list, |
size_t | offset = npos |
||
) | const |
Skip trailing characters in the string.
This searches the string in reverse order.
list | of characters to skip when found. |
offset | to start of scan. Default is end of string. |
|
static |
Skip before trailing characters in a null terminated string.
text | pointer to start at. |
list | of characters to skip when found. |
void ucommon::String::rsplit | ( | const char * | pointer | ) |
Split the string by a pointer position.
Everything before the pointer is removed.
pointer | to split position in string. |
void ucommon::String::rsplit | ( | size_t | offset | ) |
Split the string at a specific offset.
Everything before the offset is removed.
offset | to split position in string. |
const char* ucommon::String::search | ( | const char * | string, |
unsigned | instance = 0 , |
||
unsigned | flags = 0 |
||
) | const |
Search for a substring in the string.
substring | to search for. |
flags | for case insensitive search. |
|
static |
Offset until next occurrence of character in a text or length.
text | buffer to examine. |
list | of characters to search for. |
void ucommon::String::set | ( | const char * | text | ) |
Set string object to text of a null terminated string.
text | string to set. |
void ucommon::String::set | ( | size_t | offset, |
const char * | text, | ||
size_t | size = 0 |
||
) |
Set a portion of the string object at a specified offset to a text string.
offset | in object string buffer. |
text | to set at offset. |
size | of text area to set or 0 until end of text. |
void ucommon::String::set | ( | const char * | text, |
char | overflow, | ||
size_t | offset, | ||
size_t | size = 0 |
||
) |
Set a text field within our string object.
text | to set. |
overflow | character to use as filler if text is too short. |
offset | in object string buffer to set text at. |
size | of part of buffer to set with text and overflow. |
|
static |
Safely set a null terminated string buffer in memory.
If the text is too large to fit into the buffer, it is truncated to the size.
buffer | to set. |
size | of buffer. Includes null byte at end of string. |
text | to set in buffer. |
|
static |
Safely set a null terminated string buffer in memory.
If the text is too large to fit into the buffer, it is truncated to the size.
buffer | to set. |
size | of buffer. Includes null byte at end of string. |
text | to set in buffer. |
max | size of text to set. |
size_t ucommon::String::size | ( | void | ) | const |
Get the size of currently allocated space for string.
const char* ucommon::String::skip | ( | const char * | list, |
size_t | offset = 0 |
||
) | const |
Skip lead characters in the string.
list | of characters to skip when found. |
offset | to start of scan. |
|
static |
Skip after lead characters in a null terminated string.
text | pointer to start at. |
list | of characters to skip when found. |
void ucommon::String::split | ( | const char * | pointer | ) |
Split the string by a pointer position.
Everything after the pointer is removed.
pointer | to split position in string. |
void ucommon::String::split | ( | size_t | offset | ) |
Split the string at a specific offset.
Everything after the offset is removed.
offset | to split position in string. |
void ucommon::String::strip | ( | const char * | list | ) |
Strip lead and trailing characters from the string.
list | of characters to remove. |
|
static |
Skip lead and remove trailing characters from a text string.
This function will modify memory.
text | buffer to examine. |
list | of characters to trim and chop. |
Swap the cstring references between two strings.
object1 | to swap. |
object2 | to swap. |
|
inline |
|
inlinestatic |
|
static |
A thread-safe token parsing routine for null terminated strings.
This is related to strtok, but with safety checks for NULL values and a number of enhancements including support for quoted text that may contain token separators within quotes. The text string is modified as it is parsed.
text | string to examine for tokens. |
last | token position or set to NULL for start of string. |
list | of characters to use as token separators. |
quote | pairs of characters for quoted text or NULL if not used. |
end | of line marker characters or NULL if not used. |
|
inline |
A thread-safe token parsing routine for strings objects.
This is related to strtok, but with safety checks for NULL values and a number of enhancements including support for quoted text that may contain token separators within quotes. The object is modified as it is parsed.
last | token position or set to NULL for start of string. |
list | of characters to use as token separators. |
quote | pairs of characters for quoted text or NULL if not used. |
end | of line marker characters or NULL if not used. |
|
inline |
|
inlinestatic |
void ucommon::String::trim | ( | const char * | list | ) |
Trim lead characters from the string.
list | of characters to remove. |
|
inline |
|
static |
Return start of string after characters to trim from beginning.
This function does not modify memory.
text | buffer to examine. |
list | of characters to skip from start. |
bool ucommon::String::unquote | ( | const char * | quote | ) |
Unquote a quoted string.
Removes lead and trailing quote marks.
quote | pairs of characters for open and close quote. |
|
static |
Unquote a quoted null terminated string.
Returns updated string position and replaces trailing quote with null byte if quoted.
text | to examine. |
quote | pairs of character for open and close quote. |
|
static |
Convert null terminated text to upper case.
text | to convert. |
size_t ucommon::String::vprintf | ( | const char * | format, |
va_list | args | ||
) |
Print items into a string object.
format | string of print format. |
args | list to print. |
|
protected |