UCommon
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes
ucommon::String Class Reference

A copy-on-write string class that operates by reference count. More...

#include <string.h>

Inheritance diagram for ucommon::String:
Inheritance graph
[legend]
Collaboration diagram for ucommon::String:
Collaboration graph
[legend]

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.
int __isoc99_vscanf (const char *format, va_list args)
 Scan input items from a string object.
void add (const char *text)
 Append null terminated text to our string buffer.
void add (char character)
 Append a single character to our string buffer.
char at (int position) const
 Return character found at a specific position in the string.
const char * begin (void) const
 Get pointer to first character in string for iteration.
char * c_mem (void) const
 Get memory text buffer of string object.
const char * c_str (void) const
 Get character text buffer of string object.
strsize_t ccount (const char *list) const
 Count number of occurrences of characters in string.
void chop (const char *list)
 Chop trailing characters from the string.
void chop (strsize_t count=1)
 Chop trailing characters from text.
const char * chr (char character) const
 Find pointer in string where specified character appears.
void clear (strsize_t offset, strsize_t size=0)
 Clear a field of a filled string with filler.
void clear (void)
 Clear string by setting to empty.
int collate (const char *string) const
virtual int compare (const char *string) const
 Compare the values of two string.
String copy (strsize_t offset, strsize_t size) const
 Convenience method for substring extraction.
strsize_t count (void) const
 Count all characters in the string (strlen).
void cut (strsize_t offset, strsize_t size=0)
 Cut (remove) text from string.
const char * end (void) const
 Get pointer to last character in string for iteration.
void erase (void)
 Erase string memory.
char fill (void)
 Get filler character used for field array strings.
const char * find (const char *list, strsize_t offset=0) const
 Find a character in the string.
bool full (void) const
 Test if the string's allocated space is all used up.
String get (strsize_t offset, strsize_t size=0) const
 Get a new string object as a substring of the current object.
String left (strsize_t size) const
 Convenience method for left of string.
strsize_t len (void) const
 Get length of string.
void lower (void)
 Convert string to lower case.
strsize_t offset (const char *pointer) const
 Find offset of a pointer into our string buffer.
 operator bool () const
 Test if string has data.
 operator const char * () const
 Casting reference to raw text string.
bool operator! () const
 Test if string is empty.
bool operator!= (const char *text) const
 Compare our object with null terminated text.
Stringoperator% (short &value)
 Parse short integer value from a string.
Stringoperator% (unsigned short &value)
 Parse long integer value from a string.
Stringoperator% (long &value)
 Parse long integer value from a string.
Stringoperator% (unsigned long &value)
 Parse long integer value from a string.
Stringoperator% (double &value)
 Parse double value from a string.
Stringoperator% (const char *text)
 Parse text from a string in a scan expression.
Stringoperator& (const char *text)
 Concatenate null terminated text to our object.
Stringoperator&= (const char *text)
String operator() (int offset, strsize_t size) const
 Get a new substring through object expression.
const char * operator() (int offset) const
 Reference a string in the object by relative offset.
const char * operator* () const
 Reference raw text buffer by pointer operator.
bool operator*= (const char *substring)
bool operator*= (regex &expr)
Stringoperator*= (strsize_t number)
 Delete a specified number of characters from start of string.
String operator+ (const char *text)
 Concatenate null terminated text to our object.
Stringoperator++ (void)
 Delete first character from string.
Stringoperator+= (const char *text)
 Concatenate text to an existing string object.
Stringoperator+= (strsize_t number)
 Delete a specified number of characters from start of string.
Stringoperator-- (void)
 Delete last character from string.
Stringoperator-= (strsize_t number)
 Delete a specified number of characters from end of string.
bool operator< (const char *text) const
 Compare our object with null terminated text.
Stringoperator<< (const char *text)
Stringoperator<< (char code)
bool operator<= (const char *text) const
 Compare our object with null terminated text.
Stringoperator= (const String &object)
 Assign our string with the cstring of another object.
Stringoperator= (const char *text)
 Assign text to our existing buffer.
bool operator== (const char *text) const
 Compare our object with null terminated text.
bool operator> (const char *text) const
 Compare our object with null terminated text.
bool operator>= (const char *text) const
 Compare our object with null terminated text.
const char operator[] (int offset) const
 Reference a single character in string object by array offset.
Stringoperator^= (const String &object)
 Create new cow instance and assign value from another string object.
Stringoperator^= (const char *text)
 Create new cow instance and assign value from null terminated text.
Stringoperator| (const char *text)
 Concatenate null terminated text to our object.
Stringoperator|= (const char *text)
 Concatenate text to an existing string object.
void paste (strsize_t offset, const char *text, strsize_t size=0)
 Insert (paste) text into string.
strsize_t printf (const char *format,...)
 Print items into a string object.
const char * rchr (char character) const
 Find pointer in string where specified character last appears.
unsigned replace (const char *string, const char *text=((void *) 0), unsigned flags=0)
unsigned replace (regex &expr, const char *text=((void *) 0), unsigned flags=0)
virtual bool resize (strsize_t size)
 Resize and re-allocate string memory.
const char * rfind (const char *list, strsize_t offset=npos) const
 Find last occurrence of character in the string.
String right (strsize_t offset) const
 Convenience method for right of string.
void rset (const char *text, char overflow, strsize_t offset, strsize_t size=0)
 Set a text field within our string object offset from the end of buffer.
const char * rskip (const char *list, strsize_t offset=npos) const
 Skip trailing characters in the string.
void rsplit (const char *pointer)
 Split the string by a pointer position.
void rsplit (strsize_t offset)
 Split the string at a specific offset.
const char * search (const char *string, unsigned instance=0, unsigned flags=0) const
 Search for a substring in the string.
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.
void set (strsize_t offset, const char *text, strsize_t size=0)
 Set a portion of the string object at a specified offset to a text string.
void set (const char *text, char overflow, strsize_t offset, strsize_t size=0)
 Set a text field within our string object.
strsize_t size (void) const
 Get the size of currently allocated space for string.
const char * skip (const char *list, strsize_t offset=0) const
 Skip lead characters in the string.
void split (const char *pointer)
 Split the string by a pointer position.
void split (strsize_t offset)
 Split the string at a specific offset.
 String ()
 Create a new empty string object.
 String (long value)
 Create a string from a long integer.
 String (double value)
 Create a string from a floating point.
 String (strsize_t size)
 Create an empty string with a buffer pre-allocated to a specified size.
 String (strsize_t size, char fill)
 Create a filled string with a buffer pre-allocated to a specified size.
 String (strsize_t size, const char *format,...)
 Create a string by printf-like formating into a pre-allocated space of a specified size.
 String (const char *text)
 Create a string from null terminated text.
 String (const char *text, strsize_t size)
 Create a string from null terminated text up to a maximum specified size.
 String (const char *text, const char *end)
 Create a string for a substring.
 String (const String &existing)
 Construct a copy of a string object.
void strip (const char *list)
 Strip lead and trailing characters from the string.
double tod (char **pointer=((void *) 0))
 Convert string to a double value.
char * token (char **last, const char *list, const char *quote=((void *) 0), const char *end=((void *) 0))
 A thread-safe token parsing routine for strings objects.
long tol (char **pointer=((void *) 0))
 Convert string to a long value.
void trim (const char *list)
 Trim lead characters from the string.
void trim (strsize_t count=1)
 Trim lead characters from text.
bool unquote (const char *quote)
 Unquote a quoted string.
void upper (void)
 Convert string to upper case.
strsize_t vprintf (const char *format, va_list args)
 Print items into a string object.
virtual ~String ()
 Destroy string.

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.
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.
static String b64 (const uint8_t *binary, size_t size)
 Standard radix 64 string encoding.
static size_t b64decode (uint8_t *binary, const char *string, size_t size)
 Standard radix 64 decoding.
static size_t b64encode (char *string, const uint8_t *binary, size_t size, size_t width=0)
 Standard radix 64 encoding.
static int case_compare (const char *text1, const char *text2)
 Depreciated case insensitive string comparison function.
static int case_compare (const char *text1, const char *text2, size_t size)
 Depreciated case insensitive string comparison function.
static unsigned ccount (const char *text, const char *list)
 Count instances of characters in a list in a text buffer.
static bool check (const char *string, size_t maximum, size_t minimum=0)
 Check if string is valid and in specific constraints.
static char * chop (char *text, const char *list)
 Strip trailing characters from the text string.
static int collate (const char *text1, const char *text2)
static int compare (const char *text1, const char *text2)
 Safe string collation function.
static int compare (const char *text1, const char *text2, size_t size)
 Depreciated string comparison function.
static char * copy (const char *text, size_t offset, size_t len)
static size_t count (const char *text)
 Safe version of strlen function.
static uint16_t crc16 (uint8_t *binary, size_t size)
 ccitt 16 bit crc for binary data.
static uint32_t crc24 (uint8_t *binary, size_t size)
 24 bit crc as used in openpgp.
static void cut (char *text, size_t offset, size_t len)
static char * dup (const char *text)
 Duplicate null terminated text into the heap.
static bool eq_case (const char *text1, const char *text2)
 Simple case insensitive equal test for strings.
static bool eq_case (const char *text1, const char *text2, size_t size)
 Simple case insensitive equal test for strings.
static bool equal (const char *text1, const char *text2)
 Simple equal test for strings.
static bool equal (const char *text1, const char *text2, size_t size)
 Simple equal test for strings.
static void erase (char *text)
 Erase string memory.
static char * fill (char *text, size_t size, char character)
 Fill a section of memory with a fixed text character.
static const char * find (const char *text, const char *key, const char *optional)
 Find position of substring within a string.
static char * find (char *text, const char *list)
 Find the first occurrence of a character in a text buffer.
static void fix (String &object)
 Fix and reset string object filler.
static String hex (const unsigned char *binary, size_t size)
 Convert binary data buffer into hex string.
static unsigned hexdump (const unsigned char *binary, char *string, const char *format)
 Dump hex data to a string buffer.
static unsigned hexpack (unsigned char *binary, const char *string, const char *format)
 Pack hex data from a string buffer.
static unsigned 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.
static char * left (const char *text, size_t size)
 Duplicate null terminated text of specific size to heap.
static void lower (char *text)
 Convert null terminated text to lower case.
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.
static char * rfind (char *text, const char *list)
 Find the last occurrence of a character in a text buffer.
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.
static char * rskip (char *text, const char *list)
 Skip before trailing characters in a null terminated string.
static size_t seek (char *text, const char *list)
 Offset until next occurrence of character in a text or length.
static char * set (char *buffer, size_t size, const char *text)
 Safely set a null terminated string buffer in memory.
static char * set (char *buffer, size_t size, const char *text, size_t max)
 Safely set a null terminated string buffer in memory.
static char * skip (char *text, const char *list)
 Skip after lead characters in a null terminated string.
static char * strip (char *text, const char *list)
 Skip lead and remove trailing characters from a text string.
static void swap (String &object1, String &object2)
 Swap the cstring references between two strings.
static double tod (const char *text, char **pointer=((void *) 0))
 Convert text to a double value.
static char * token (char *text, char **last, const char *list, const char *quote=((void *) 0), const char *end=((void *) 0))
 A thread-safe token parsing routine for null terminated strings.
static long tol (const char *text, char **pointer=((void *) 0))
 Convert text to a long value.
static char * trim (char *text, const char *list)
 Return start of string after characters to trim from beginning.
static char * unquote (char *text, const char *quote)
 Unquote a quoted null terminated string.
static void upper (char *text)
 Convert null terminated text to upper case.

Static Public Attributes

static const char eos
static const strsize_t npos

Protected Member Functions

virtual cstring * c_copy (void) const
 Return cstring to use in copy constructors.
virtual void cow (strsize_t size=0)
 Copy on write operation for cstring.
cstring * create (strsize_t size, char fill=0) const
 Factory create a cstring object of specified size.
bool equal (const char *string) const
 Test if two string values are equal.
strsize_t getStringSize (void) const
virtual void release (void)
 Decrease retention of our reference counted cstring.
virtual void retain (void)
 Increase retention of our reference counted cstring.

Protected Attributes

cstring * str
 cstring instance our object references.

Detailed Description

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.

Author:
David Sugar <dyfet@gnutelephony.org>
Examples:
datetime.cpp, digest.cpp, shell.cpp, and string.cpp.

Definition at line 83 of file string.h.


Member Enumeration Documentation

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.

Author:
David Sugar <dyfet@gnutelephony.org>

Definition at line 98 of file string.h.


Constructor & Destructor Documentation

ucommon::String::String ( long  value)

Create a string from a long integer.

Parameters:
valueto convert to string.
ucommon::String::String ( double  value)

Create a string from a floating point.

Parameters:
valueto convert to string.

Create an empty string with a buffer pre-allocated to a specified size.

Parameters:
sizeof buffer to allocate.
ucommon::String::String ( strsize_t  size,
char  fill 
)

Create a filled string with a buffer pre-allocated to a specified size.

Parameters:
sizeof buffer to allocate.
fillcharacter to use.
ucommon::String::String ( strsize_t  size,
const char *  format,
  ... 
)

Create a string by printf-like formating into a pre-allocated space of a specified size.

A typical use might be in a concat function like String x = (String)something + (String){10, "%ud", var}.

Parameters:
sizeof buffer to allocate.
formatcontrol for string.
ucommon::String::String ( const char *  text)

Create a string from null terminated text.

Parameters:
textto use for string.
ucommon::String::String ( const char *  text,
strsize_t  size 
)

Create a string from null terminated text up to a maximum specified size.

Parameters:
textto use for string.
sizelimit 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.

Parameters:
textto use for string.
endof 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.

Parameters:
existingstring to copy from.
virtual ucommon::String::~String ( ) [virtual]

Destroy string.

De-reference cstring. If last reference to cstring, then also remove cstring from heap.


Member Function Documentation

int ucommon::String::__isoc99_scanf ( const char *  format,
  ... 
)

Scan input items from a string object.

Parameters:
formatstring of input to scan.
Returns:
number of items scanned.
int ucommon::String::__isoc99_vscanf ( const char *  format,
va_list  args 
)

Scan input items from a string object.

Parameters:
formatstring of input to scan.
argslist to scan into.
Returns:
number of items scanned.
void ucommon::String::add ( const char *  text)

Append null terminated text to our string buffer.

Parameters:
textto append.
void ucommon::String::add ( char  character)

Append a single character to our string buffer.

Parameters:
characterto append.
static char* ucommon::String::add ( char *  buffer,
size_t  size,
const char *  text 
) [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.

Parameters:
bufferto set.
sizeof buffer. Includes null byte at end of string.
textto set in buffer.
Returns:
pointer to text buffer.
static char* ucommon::String::add ( char *  buffer,
size_t  size,
const char *  text,
size_t  max 
) [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.

Parameters:
bufferto set.
sizeof buffer. Includes null byte at end of string.
textto set in buffer.
maxsize of text to append.
Returns:
pointer to text buffer.
char ucommon::String::at ( int  position) const

Return character found at a specific position in the string.

Parameters:
positionin string, negative values computed from end.
Returns:
character code at specified position in string.

Reimplemented in ucommon::UString.

static String ucommon::String::b64 ( const uint8_t *  binary,
size_t  size 
) [static]

Standard radix 64 string encoding.

Parameters:
binarydata to encode.
sizeof binary data to encode.
Returns:
encoded string.
static size_t ucommon::String::b64decode ( uint8_t *  binary,
const char *  string,
size_t  size 
) [static]

Standard radix 64 decoding.

Parameters:
binarydata to save.
stringof encoded text.
sizeof destination buffer.
Returns:
number of bytes actually decoded.
static size_t ucommon::String::b64encode ( char *  string,
const uint8_t *  binary,
size_t  size,
size_t  width = 0 
) [static]

Standard radix 64 encoding.

Parameters:
stringof encoded text save into.
binarydata to encode.
sizeof binary data to encode.
widthof string buffer for data if partial supported.
Returns:
number of bytes encoded.
const char* ucommon::String::begin ( void  ) const

Get pointer to first character in string for iteration.

Returns:
first character pointer or NULL if empty.
virtual cstring* ucommon::String::c_copy ( void  ) const [protected, virtual]

Return cstring to use in copy constructors.

Is virtual for memstring.

Returns:
cstring for copy constructor.

Reimplemented in ucommon::memstring.

char* ucommon::String::c_mem ( void  ) const

Get memory text buffer of string object.

Returns:
writable string buffer.
const char* ucommon::String::c_str ( void  ) const

Get character text buffer of string object.

Returns:
character text buffer.
static int ucommon::String::case_compare ( const char *  text1,
const char *  text2 
) [static]

Depreciated case insensitive string comparison function.

Parameters:
text1to compare.
text2to compare.
Returns:
0 if equal, >0 if text1 > text2, <0 if text1 < text2.
static int ucommon::String::case_compare ( const char *  text1,
const char *  text2,
size_t  size 
) [static]

Depreciated case insensitive string comparison function.

Parameters:
text1to compare.
text2to compare.
sizelimit of strings to compare.
Returns:
0 if equal, >0 if text1 > text2, <0 if text1 < text2.
strsize_t ucommon::String::ccount ( const char *  list) const

Count number of occurrences of characters in string.

Parameters:
listof characters to find.
Returns:
count of instances of characters in string.
static unsigned ucommon::String::ccount ( const char *  text,
const char *  list 
) [static]

Count instances of characters in a list in a text buffer.

Parameters:
textbuffer to examine.
listof characters to count in buffer.
Returns:
number of instances of the characters in buffer.
static bool ucommon::String::check ( const char *  string,
size_t  maximum,
size_t  minimum = 0 
) [static]

Check if string is valid and in specific constraints.

Parameters:
stringto check.
maximumsize allowed.
minimumsize required.
Returns:
true if string is valid.
Examples:
string.cpp.
void ucommon::String::chop ( const char *  list)

Chop trailing characters from the string.

Parameters:
listof characters to remove.
void ucommon::String::chop ( strsize_t  count = 1) [inline]

Chop trailing characters from text.

Parameters:
countof characters to remove.

Definition at line 494 of file string.h.

static char* ucommon::String::chop ( char *  text,
const char *  list 
) [static]

Strip trailing characters from the text string.

This function will modify memory.

Parameters:
textbuffer to examine.
listof characters to chop from trailing end of string.
Returns:
pointer to text buffer.
const char* ucommon::String::chr ( char  character) const

Find pointer in string where specified character appears.

Parameters:
characterto find.
Returns:
string pointer for character if found, NULL if not.
void ucommon::String::clear ( strsize_t  offset,
strsize_t  size = 0 
)

Clear a field of a filled string with filler.

Parameters:
offsetto start of field to clear.
sizeof field to fill or 0 to fill to end of string.
virtual int ucommon::String::compare ( const char *  string) const [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.

Parameters:
stringto compare with.
Returns:
0 if equal, <0 if less than, 0> if greater than.
static int ucommon::String::compare ( const char *  text1,
const char *  text2 
) [static]

Safe string collation function.

Parameters:
text1to compare.
text2to compare.
Returns:
0 if equal, >0 if text1 > text2, <0 if text1 < text2.
static int ucommon::String::compare ( const char *  text1,
const char *  text2,
size_t  size 
) [static]

Depreciated string comparison function.

Parameters:
text1to compare.
text2to compare.
sizelimit of strings to compare.
Returns:
0 if equal, >0 if text1 > text2, <0 if text1 < text2.
String ucommon::String::copy ( strsize_t  offset,
strsize_t  size 
) const [inline]

Convenience method for substring extraction.

Parameters:
offsetinto string.
sizeof string to return.
Returns:
string object holding substring.

Reimplemented in ucommon::UString.

Definition at line 752 of file string.h.

Count all characters in the string (strlen).

Returns:
count of characters.

Reimplemented in ucommon::UString.

static size_t ucommon::String::count ( const char *  text) [static]

Safe version of strlen function.

Accepts NULL as 0 length strings.

Parameters:
textstring.
Returns:
length of string.
virtual void ucommon::String::cow ( strsize_t  size = 0) [protected, virtual]

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.

Parameters:
sizeto add to allocated space when creating new cstring.
static uint16_t ucommon::String::crc16 ( uint8_t *  binary,
size_t  size 
) [static]

ccitt 16 bit crc for binary data.

Parameters:
binarydata to sum.
sizeof binary data to sum.
Returns:
16 bit crc.
static uint32_t ucommon::String::crc24 ( uint8_t *  binary,
size_t  size 
) [static]

24 bit crc as used in openpgp.

Parameters:
binarydata to sum.
sizeof binary data to sum.
Returns:
24 bit crc of data.
cstring* ucommon::String::create ( strsize_t  size,
char  fill = 0 
) const [protected]

Factory create a cstring object of specified size.

Parameters:
sizeof allocated space for string buffer.
fillcharacter to use or 0 if null.
Returns:
new cstring object.
void ucommon::String::cut ( strsize_t  offset,
strsize_t  size = 0 
)

Cut (remove) text from string.

Parameters:
offsetto start of text field to remove.
sizeof text field to remove or 0 to remove to end of string.

Reimplemented in ucommon::UString.

static char* ucommon::String::dup ( const char *  text) [static]

Duplicate null terminated text into the heap.

Parameters:
textto duplicate.
Returns:
duplicate copy of text allocated from heap.
const char* ucommon::String::end ( void  ) const

Get pointer to last character in string for iteration.

Returns:
last character pointer or NULL if empty.
static bool ucommon::String::eq_case ( const char *  text1,
const char *  text2 
) [static]

Simple case insensitive equal test for strings.

Parameters:
text1to test.
text2to test.
Returns:
true if equal.
static bool ucommon::String::eq_case ( const char *  text1,
const char *  text2,
size_t  size 
) [static]

Simple case insensitive equal test for strings.

Parameters:
text1to test.
text2to test.
sizelimit of strings to compare.
Returns:
true if equal.
bool ucommon::String::equal ( const char *  string) const [protected]

Test if two string values are equal.

Parameters:
stringto compare with.
Returns:
true if equal.
static bool ucommon::String::equal ( const char *  text1,
const char *  text2 
) [static]

Simple equal test for strings.

Parameters:
text1to test.
text2to test.
Returns:
true if equal and case is same.
static bool ucommon::String::equal ( const char *  text1,
const char *  text2,
size_t  size 
) [static]

Simple equal test for strings.

Parameters:
text1to test.
text2to test.
sizelimit of strings to compare.
Returns:
true if equal and case is same.
static void ucommon::String::erase ( char *  text) [static]

Erase string memory.

Often used to clear out passwords.

Parameters:
textstring to erase.
char ucommon::String::fill ( void  )

Get filler character used for field array strings.

Returns:
filler character or 0 if none.
Examples:
string.cpp.
static char* ucommon::String::fill ( char *  text,
size_t  size,
char  character 
) [static]

Fill a section of memory with a fixed text character.

Adds a null byte at the end.

Parameters:
textbuffer to fill.
sizeof text buffer with null terminated byte.
characterto fill with.
Returns:
pointer to text buffer.
const char* ucommon::String::find ( const char *  list,
strsize_t  offset = 0 
) const

Find a character in the string.

Parameters:
listof characters to search for.
offsetto start of search.
Returns:
pointer to first occurrence of character.
static const char* ucommon::String::find ( const char *  text,
const char *  key,
const char *  optional 
) [static]

Find position of substring within a string.

Parameters:
textto search in.
keystring to locate.
optionalseparator chars if formatted as list of keys.
Returns:
substring position if found, or NULL.
static char* ucommon::String::find ( char *  text,
const char *  list 
) [static]

Find the first occurrence of a character in a text buffer.

Parameters:
textbuffer to examine.
listof characters to search for.
Returns:
pointer to first instance found or NULL.
static void ucommon::String::fix ( String object) [static]

Fix and reset string object filler.

Parameters:
objectto fix.
bool ucommon::String::full ( void  ) const

Test if the string's allocated space is all used up.

Returns:
true if no more room for append.
String ucommon::String::get ( strsize_t  offset,
strsize_t  size = 0 
) const

Get a new string object as a substring of the current object.

Parameters:
offsetof substring.
sizeof substring or 0 if to end.
Returns:
string object holding substring.

Reimplemented in ucommon::UString.

static String ucommon::String::hex ( const unsigned char *  binary,
size_t  size 
) [static]

Convert binary data buffer into hex string.

Parameters:
binarydata to convert.
sizeof data.
Returns:
string from data.
Examples:
string.cpp.
static unsigned ucommon::String::hexdump ( const unsigned char *  binary,
char *  string,
const char *  format 
) [static]

Dump hex data to a string buffer.

Parameters:
binarymemory to dump.
stringto save into.
formatstring to convert with.
Returns:
number of bytes processed.
Examples:
string.cpp.
static unsigned ucommon::String::hexpack ( unsigned char *  binary,
const char *  string,
const char *  format 
) [static]

Pack hex data from a string buffer.

Parameters:
binarymemory to pack.
stringto save into.
formatstring to convert with.
Returns:
number of bytes processed.
Examples:
string.cpp.
static const char* ucommon::String::ifind ( const char *  text,
const char *  key,
const char *  optional 
) [static]

Find position of case insensitive substring within a string.

Parameters:
textto search in.
keystring to locate.
optionalseparator chars if formatted as list of keys.
Returns:
substring position if found, or NULL.
String ucommon::String::left ( strsize_t  size) const [inline]

Convenience method for left of string.

Parameters:
sizeof substring to gather.
Returns:
string object holding substring.

Reimplemented in ucommon::UString.

Definition at line 735 of file string.h.

static char* ucommon::String::left ( const char *  text,
size_t  size 
) [static]

Duplicate null terminated text of specific size to heap.

Parameters:
textto duplicate.
sizeof text, maximum space allocated.
Returns:
duplicate copy of text allocated on heap.
strsize_t ucommon::String::len ( void  ) const

Get length of string.

Returns:
length of string.
Examples:
string.cpp.
static void ucommon::String::lower ( char *  text) [static]

Convert null terminated text to lower case.

Parameters:
textto convert.
strsize_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.

Parameters:
pointerinto our object's string buffer.
ucommon::String::operator bool ( ) const

Test if string has data.

Returns:
true if string has data.
ucommon::String::operator const char * ( ) const [inline]

Casting reference to raw text string.

Returns:
null terminated text of string.

Definition at line 706 of file string.h.

Test if string is empty.

Returns:
true if string is empty.
bool ucommon::String::operator!= ( const char *  text) const

Compare our object with null terminated text.

Compare method is used.

Parameters:
textto compare with.
Returns:
true if we are not equal.
String& ucommon::String::operator% ( short &  value)

Parse short integer value from a string.

Parameters:
valueto store.
Returns:
object in expression.
String& ucommon::String::operator% ( unsigned short &  value)

Parse long integer value from a string.

Parameters:
valueto store.
Returns:
object in expression.
String& ucommon::String::operator% ( long &  value)

Parse long integer value from a string.

Parameters:
valueto store.
Returns:
object in expression.
String& ucommon::String::operator% ( unsigned long &  value)

Parse long integer value from a string.

Parameters:
valueto store.
Returns:
object in expression.
String& ucommon::String::operator% ( double &  value)

Parse double value from a string.

Parameters:
valueto store.
Returns:
object in expression.
String& ucommon::String::operator% ( const char *  text)

Parse text from a string in a scan expression.

Parameters:
textto scan and bypass.
Returns:
object in expression.
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.

Parameters:
textto concatenate.
String ucommon::String::operator() ( int  offset,
strsize_t  size 
) const

Get a new substring through object expression.

Parameters:
offsetof substring.
sizeof substring or 0 if to end.
Returns:
string object holding substring.

Reimplemented in ucommon::UString.

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.

Parameters:
offsetto string position.
Returns:
pointer to string data or NULL if invalid offset.

Reimplemented in ucommon::UString.

const char* ucommon::String::operator* ( ) const [inline]

Reference raw text buffer by pointer operator.

Returns:
null terminated text of string.

Definition at line 713 of file string.h.

String& ucommon::String::operator*= ( strsize_t  number)

Delete a specified number of characters from start of string.

Parameters:
numberof characters to delete.
String ucommon::String::operator+ ( const char *  text)

Concatenate null terminated text to our object.

Parameters:
textto concatenate.
String& ucommon::String::operator+= ( const char *  text)

Concatenate text to an existing string object.

Parameters:
textto add.
Returns:
our object for expression use.
String& ucommon::String::operator+= ( strsize_t  number)

Delete a specified number of characters from start of string.

Parameters:
numberof characters to delete.
String& ucommon::String::operator-= ( strsize_t  number)

Delete a specified number of characters from end of string.

Parameters:
numberof characters to delete.
bool ucommon::String::operator< ( const char *  text) const

Compare our object with null terminated text.

Compare method is used.

Parameters:
textto compare with.
Returns:
true if we are less than text.
bool ucommon::String::operator<= ( const char *  text) const

Compare our object with null terminated text.

Compare method is used.

Parameters:
textto compare with.
Returns:
true if we are less than or equal to text.
String& ucommon::String::operator= ( const String object)

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.

Parameters:
objectto assign from.
String& ucommon::String::operator= ( const char *  text)

Assign text to our existing buffer.

This performs a set method.

Parameters:
textto assign from.

Reimplemented in ucommon::stringbuf< S >, and ucommon::memstring.

bool ucommon::String::operator== ( const char *  text) const

Compare our object with null terminated text.

Parameters:
textto compare with.
Returns:
true if we are equal.
bool ucommon::String::operator> ( const char *  text) const

Compare our object with null terminated text.

Compare method is used.

Parameters:
textto compare with.
Returns:
true if we are greater than text.
bool ucommon::String::operator>= ( const char *  text) const

Compare our object with null terminated text.

Compare method is used.

Parameters:
textto compare with.
Returns:
true if we are greater than or equal to text.
const char ucommon::String::operator[] ( int  offset) const

Reference a single character in string object by array offset.

Parameters:
offsetto character.
Returns:
character value at offset.

Reimplemented in ucommon::UString.

String& ucommon::String::operator^= ( const String object)

Create new cow instance and assign value from another string object.

Parameters:
objectto assign from.
Returns:
our object for expression use.
String& ucommon::String::operator^= ( const char *  text)

Create new cow instance and assign value from null terminated text.

Parameters:
textto assign from.
Returns:
our object for expression use.
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.

Parameters:
textto 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 ( strsize_t  offset,
const char *  text,
strsize_t  size = 0 
)

Insert (paste) text into string.

Parameters:
offsetto start paste.
textto paste.
sizeof text to paste.

Reimplemented in ucommon::UString.

Examples:
string.cpp.
static const char* ucommon::String::pos ( const char *  text,
ssize_t  offset 
) [static]

Compute position in string.

Parameters:
textof string.
offsetfrom start, negative values from end.
Returns:
pointer to string position.
strsize_t ucommon::String::printf ( const char *  format,
  ... 
)

Print items into a string object.

Parameters:
formatstring of print format.
Returns:
number of bytes written to string.
const char* ucommon::String::rchr ( char  character) const

Find pointer in string where specified character last appears.

Parameters:
characterto find.
Returns:
string pointer for last occurrence of character if found, NULL if not.
virtual void ucommon::String::release ( void  ) [protected, virtual]

Decrease retention of our reference counted cstring.

May be overridden for memstring which has fixed cstring object.

Implements ucommon::ObjectProtocol.

virtual bool ucommon::String::resize ( strsize_t  size) [virtual]

Resize and re-allocate string memory.

Parameters:
sizeto allocate for string.
Returns:
true if re-allocated. False in derived memstring.
virtual void ucommon::String::retain ( void  ) [protected, virtual]

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,
strsize_t  offset = npos 
) const

Find last occurrence of character in the string.

Parameters:
listof characters to search for.
offsetto start of search. Default is end of string.
Returns:
pointer to last occurrence of character.
static char* ucommon::String::rfind ( char *  text,
const char *  list 
) [static]

Find the last occurrence of a character in a text buffer.

Parameters:
textbuffer to examine.
listof characters to search for.
Returns:
pointer to last instance found or NULL.
String ucommon::String::right ( strsize_t  offset) const [inline]

Convenience method for right of string.

Parameters:
offsetof substring from right.
Returns:
string object holding substring.

Reimplemented in ucommon::UString.

Definition at line 743 of file string.h.

void ucommon::String::rset ( const char *  text,
char  overflow,
strsize_t  offset,
strsize_t  size = 0 
)

Set a text field within our string object offset from the end of buffer.

Parameters:
textto set.
overflowcharacter to use as filler if text is too short.
offsetfrom end of object string buffer to set text at.
sizeof part of buffer to set with text and overflow.
static char* ucommon::String::rset ( char *  buffer,
size_t  size,
const char *  text 
) [static]

Set a field in a null terminated string relative to the end of text.

Parameters:
bufferto modify.
sizeof field to set.
textto replace end of string with.
Returns:
pointer to text buffer.
const char* ucommon::String::rskip ( const char *  list,
strsize_t  offset = npos 
) const

Skip trailing characters in the string.

This searches the string in reverse order.

Parameters:
listof characters to skip when found.
offsetto start of scan. Default is end of string.
Returns:
pointer to first part of string before skipped characters.
static char* ucommon::String::rskip ( char *  text,
const char *  list 
) [static]

Skip before trailing characters in a null terminated string.

Parameters:
textpointer to start at.
listof characters to skip when found.
Returns:
pointer to last part of string past skipped characters.
void ucommon::String::rsplit ( const char *  pointer)

Split the string by a pointer position.

Everything before the pointer is removed.

Parameters:
pointerto split position in string.

Split the string at a specific offset.

Everything before the offset is removed.

Parameters:
offsetto 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.

Parameters:
substringto search for.
flagsfor case insensitive search.
static size_t ucommon::String::seek ( char *  text,
const char *  list 
) [static]

Offset until next occurrence of character in a text or length.

Parameters:
textbuffer to examine.
listof characters to search for.
Returns:
offset to next occurrence or length of string.
void ucommon::String::set ( const char *  text)

Set string object to text of a null terminated string.

Parameters:
textstring to set.
Examples:
string.cpp.
void ucommon::String::set ( strsize_t  offset,
const char *  text,
strsize_t  size = 0 
)

Set a portion of the string object at a specified offset to a text string.

Parameters:
offsetin object string buffer.
textto set at offset.
sizeof text area to set or 0 until end of text.
void ucommon::String::set ( const char *  text,
char  overflow,
strsize_t  offset,
strsize_t  size = 0 
)

Set a text field within our string object.

Parameters:
textto set.
overflowcharacter to use as filler if text is too short.
offsetin object string buffer to set text at.
sizeof part of buffer to set with text and overflow.
static char* ucommon::String::set ( char *  buffer,
size_t  size,
const char *  text 
) [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.

Parameters:
bufferto set.
sizeof buffer. Includes null byte at end of string.
textto set in buffer.
Returns:
pointer to text buffer.
static char* ucommon::String::set ( char *  buffer,
size_t  size,
const char *  text,
size_t  max 
) [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.

Parameters:
bufferto set.
sizeof buffer. Includes null byte at end of string.
textto set in buffer.
maxsize of text to set.
Returns:
pointer to text buffer.
strsize_t ucommon::String::size ( void  ) const

Get the size of currently allocated space for string.

Returns:
size allocated for text.
const char* ucommon::String::skip ( const char *  list,
strsize_t  offset = 0 
) const

Skip lead characters in the string.

Parameters:
listof characters to skip when found.
offsetto start of scan.
Returns:
pointer to first part of string past skipped characters.
static char* ucommon::String::skip ( char *  text,
const char *  list 
) [static]

Skip after lead characters in a null terminated string.

Parameters:
textpointer to start at.
listof characters to skip when found.
Returns:
pointer to first part of string past skipped characters.
void ucommon::String::split ( const char *  pointer)

Split the string by a pointer position.

Everything after the pointer is removed.

Parameters:
pointerto split position in string.

Split the string at a specific offset.

Everything after the offset is removed.

Parameters:
offsetto split position in string.
void ucommon::String::strip ( const char *  list)

Strip lead and trailing characters from the string.

Parameters:
listof characters to remove.
Examples:
string.cpp.
static char* ucommon::String::strip ( char *  text,
const char *  list 
) [static]

Skip lead and remove trailing characters from a text string.

This function will modify memory.

Parameters:
textbuffer to examine.
listof characters to trim and chop.
Returns:
position in text past lead trim.
static void ucommon::String::swap ( String object1,
String object2 
) [static]

Swap the cstring references between two strings.

Parameters:
object1to swap.
object2to swap.
double ucommon::String::tod ( char **  pointer = ((void*)0)) [inline]

Convert string to a double value.

Parameters:
objectto convert.
pointerto update with end of parsed value.
Returns:
double value of object.

Definition at line 1322 of file string.h.

static double ucommon::String::tod ( const char *  text,
char **  pointer = ((void*)0) 
) [inline, static]

Convert text to a double value.

Parameters:
textto convert.
pointerto update with end of parsed value.
Returns:
double value of object.

Definition at line 1340 of file string.h.

static char* ucommon::String::token ( char *  text,
char **  last,
const char *  list,
const char *  quote = ((void *) 0),
const char *  end = ((void *) 0) 
) [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.

Parameters:
textstring to examine for tokens.
lasttoken position or set to NULL for start of string.
listof characters to use as token separators.
quotepairs of characters for quoted text or NULL if not used.
endof line marker characters or NULL if not used.
Returns:
token extracted from string or NULL if no more tokens found.
Examples:
string.cpp.
char* ucommon::String::token ( char **  last,
const char *  list,
const char *  quote = ((void*)0),
const char *  end = ((void*)0) 
) [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.

Parameters:
lasttoken position or set to NULL for start of string.
listof characters to use as token separators.
quotepairs of characters for quoted text or NULL if not used.
endof line marker characters or NULL if not used.
Returns:
token extracted from string or NULL if no more tokens found.

Definition at line 1313 of file string.h.

Here is the call graph for this function:

long ucommon::String::tol ( char **  pointer = ((void*)0)) [inline]

Convert string to a long value.

Parameters:
objectto convert.
pointerto update with end of parsed value.
Returns:
long value of object.

Definition at line 1331 of file string.h.

static long ucommon::String::tol ( const char *  text,
char **  pointer = ((void*)0) 
) [inline, static]

Convert text to a long value.

Parameters:
textto convert.
pointerto update with end of parsed value.
Returns:
long value of object.

Definition at line 1349 of file string.h.

void ucommon::String::trim ( const char *  list)

Trim lead characters from the string.

Parameters:
listof characters to remove.
void ucommon::String::trim ( strsize_t  count = 1) [inline]

Trim lead characters from text.

Parameters:
countof characters to remove.

Definition at line 481 of file string.h.

static char* ucommon::String::trim ( char *  text,
const char *  list 
) [static]

Return start of string after characters to trim from beginning.

This function does not modify memory.

Parameters:
textbuffer to examine.
listof characters to skip from start.
Returns:
position in text past lead trim.
bool ucommon::String::unquote ( const char *  quote)

Unquote a quoted string.

Removes lead and trailing quote marks.

Parameters:
quotepairs of characters for open and close quote.
Returns:
true if string was quoted.
static char* ucommon::String::unquote ( char *  text,
const char *  quote 
) [static]

Unquote a quoted null terminated string.

Returns updated string position and replaces trailing quote with null byte if quoted.

Parameters:
textto examine.
quotepairs of character for open and close quote.
Returns:
new text pointer if quoted, NULL if unchanged.
static void ucommon::String::upper ( char *  text) [static]

Convert null terminated text to upper case.

Parameters:
textto convert.
strsize_t ucommon::String::vprintf ( const char *  format,
va_list  args 
)

Print items into a string object.

Parameters:
formatstring of print format.
argslist to print.
Returns:
number of bytes written to string.

Field Documentation

cstring* ucommon::String::str [protected]

cstring instance our object references.

Definition at line 225 of file string.h.


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