ucommon  7.0.0
About: GNU uCommon C++ is a portable and optimized class framework for writing C++ applications that need to use threads and support concurrent synchronization, and that use sockets, XML parsing, object serialization, thread-optimized string and data structure classes, etc..
  Fossies Dox: ucommon-7.0.0.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

ucommon::String Class Reference

#include <string.h>

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

Classes

class  cstring
 
class  regex
 

Public Types

enum  { SENSITIVE = 0x00, INSENSITIVE = 0x01 }
 

Public Member Functions

virtual int compare (const char *string) const
 
 String ()
 
 String (size_t size)
 
 String (size_t size, const char *format,...)
 
 String (const char *text)
 
 String (const char *text, size_t size)
 
 String (const char *text, const char *end)
 
 String (const String &existing)
 
virtual ~String ()
 
String get (size_t offset, size_t size=0) const
 
int scanf (const char *format,...) __SCANF(2
 
int int vscanf (const char *format, va_list args) __SCANF(2
 
int int size_t printf (const char *format,...) __PRINTF(2
 
int int size_t size_t vprintf (const char *format, va_list args) __PRINTF(2
 
int int size_t size_t char * data (void)
 
char * c_mem ()
 
const char * c_str (void) const
 
virtual bool resize (size_t size)
 
void set (const char *text)
 
void set (size_t offset, const char *text, size_t size=0)
 
void set (const char *text, char overflow, size_t offset, size_t size=0)
 
void rset (const char *text, char overflow, size_t offset, size_t size=0)
 
void add (const char *text)
 
void add (char character)
 
void trim (const char *list)
 
void trim (size_t count=1)
 
void chop (const char *list)
 
void chop (size_t count=1)
 
void strip (const char *list)
 
bool unquote (const char *quote)
 
void cut (size_t offset, size_t size=0)
 
void paste (size_t offset, const char *text, size_t size=0)
 
void clear (size_t offset)
 
void clear (void)
 
void upper (void)
 
void lower (void)
 
void erase (void)
 
size_t ccount (const char *list) const
 
size_t count (void) const
 
size_t size (void) const
 
size_t offset (const char *pointer) const
 
char at (int position) const
 
const char * begin (void) const
 
const char * end (void) const
 
const char * skip (const char *list, size_t offset=0) const
 
const char * rskip (const char *list, size_t offset=npos) const
 
const char * search (const char *string, unsigned instance=0, unsigned flags=0) const
 
const char * search (regex &expr, unsigned instance=0, unsigned flags=0) const
 
unsigned replace (const char *string, const char *text=NULL, unsigned flags=0)
 
unsigned replace (regex &expr, const char *text=NULL, unsigned flags=0)
 
const char * find (const char *list, size_t offset=0) const
 
const char * rfind (const char *list, size_t offset=npos) const
 
void split (const char *pointer)
 
void split (size_t offset)
 
void fill (size_t size, char fill)
 
void rsplit (const char *pointer)
 
void rsplit (size_t offset)
 
const char * chr (char character) const
 
const char * rchr (char character) const
 
size_t len (void) const
 
 operator const char * () const
 
const char * operator* () const
 
bool full (void) const
 
String operator() (int offset, size_t size) const
 
String left (size_t size) const
 
String right (size_t offset) const
 
String copy (size_t offset, size_t size) const
 
const char * operator() (int offset) const
 
const char operator[] (int offset) const
 
bool operator! () const
 
 operator bool () const
 
Stringoperator^= (const String &object)
 
Stringoperator|= (const char *text)
 
Stringoperator&= (const char *text)
 
Stringoperator+= (const char *text)
 
Stringoperator^= (const char *text)
 
const String operator+ (const char *text) const
 
Stringoperator| (const char *text)
 
Stringoperator& (const char *text)
 
Stringoperator= (const String &object)
 
bool operator*= (const char *substring)
 
bool operator*= (regex &expr)
 
Stringoperator= (const char *text)
 
Stringoperator++ (void)
 
Stringoperator+= (size_t number)
 
Stringoperator-- (void)
 
Stringoperator-= (size_t number)
 
Stringoperator*= (size_t number)
 
bool operator== (const char *text) const
 
bool operator!= (const char *text) const
 
bool operator< (const char *text) const
 
bool operator<= (const char *text) const
 
bool operator> (const char *text) const
 
bool operator>= (const char *text) const
 
Stringoperator<< (const char *text)
 
Stringoperator<< (char code)
 
Stringoperator% (short &value)
 
Stringoperator% (unsigned short &value)
 
Stringoperator% (long &value)
 
Stringoperator% (unsigned long &value)
 
Stringoperator% (double &value)
 
Stringoperator% (const char *text)
 
char * token (char **last, const char *list, const char *quote=NULL, const char *end=NULL)
 
double tod (char **pointer=NULL)
 
long tol (char **pointer=NULL)
 

Static Public Member Functions

static void swap (String &object1, String &object2)
 
static void fix (String &object)
 
static bool check (const char *string, size_t maximum, size_t minimum=0)
 
static void erase (char *text)
 
static void lower (char *text)
 
static void upper (char *text)
 
static char * token (char *text, char **last, const char *list, const char *quote=NULL, const char *end=NULL)
 
static char * skip (char *text, const char *list)
 
static char * rskip (char *text, const char *list)
 
static char * unquote (char *text, const char *quote)
 
static char * rset (char *buffer, size_t size, const char *text)
 
static char * set (char *buffer, size_t size, const char *text)
 
static char * set (char *buffer, size_t size, const char *text, size_t max)
 
static char * add (char *buffer, size_t size, const char *text)
 
static char * add (char *buffer, size_t size, const char *text, size_t max)
 
static const char * ifind (const char *text, const char *key, const char *optional)
 
static const char * find (const char *text, const char *key, const char *optional)
 
static size_t count (const char *text)
 
static int compare (const char *text1, const char *text2)
 
static int collate (const char *text1, const char *text2)
 
static bool equal (const char *text1, const char *text2)
 
static int compare (const char *text1, const char *text2, size_t size)
 
static bool equal (const char *text1, const char *text2, size_t size)
 
static bool eq_case (const char *text1, const char *text2)
 
static bool eq_case (const char *text1, const char *text2, size_t size)
 
static char * trim (char *text, const char *list)
 
static char * chop (char *text, const char *list)
 
static char * strip (char *text, const char *list)
 
static char * fill (char *text, size_t size, char character)
 
static unsigned ccount (const char *text, const char *list)
 
static char * find (char *text, const char *list)
 
static size_t seek (char *text, const char *list)
 
static char * rfind (char *text, const char *list)
 
static char * dup (const char *text)
 
static char * left (const char *text, size_t size)
 
static const char * pos (const char *text, ssize_t offset)
 
static char * right (const char *text, size_t size)
 
static char * copy (const char *text, size_t offset, size_t len)
 
static void cut (char *text, size_t offset, size_t len)
 
static void paste (char *text, size_t max, size_t offset, const char *data, size_t len=0)
 
static double tod (const char *text, char **pointer=NULL)
 
static long tol (const char *text, char **pointer=NULL)
 
static String b64 (const uint8_t *binary, size_t size)
 
static size_t b64size (size_t size)
 
static size_t b64encode (char *string, const uint8_t *binary, size_t size, size_t width=0)
 
static size_t b64decode (uint8_t *binary, const char *string, size_t size, bool ws=false)
 
static size_t b64count (const char *str, bool ws=false)
 
static uint32_t crc24 (uint8_t *binary, size_t size)
 
static uint16_t crc16 (uint8_t *binary, size_t size)
 
static String hex (const uint8_t *binary, size_t size)
 
static size_t hexdump (const uint8_t *binary, char *string, const char *format)
 
static size_t hexpack (uint8_t *binary, const char *string, const char *format)
 
static size_t hex2bin (const char *string, uint8_t *binary, size_t maxsize, bool wsflag=false)
 
static size_t hexsize (const char *format)
 
static size_t hexcount (const char *str, bool ws=false)
 

Static Public Attributes

const static size_t npos = ((size_t)-1)
 
const static char eos = '\0'
 

Protected Member Functions

cstringcreate (size_t size) const
 
bool equal (const char *string) const
 
virtual void retain (void) __OVERRIDE
 
virtual void release (void) __OVERRIDE
 
virtual cstringc_copy (void) const
 
virtual void cow (size_t size=0)
 
size_t getStringSize (void) const
 

Protected Attributes

cstringstr
 

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.nosp@m.@gnu.nosp@m.telep.nosp@m.hony.nosp@m..org

Definition at line 78 of file string.h.

Member Enumeration Documentation

◆ anonymous enum

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.nosp@m.@gnu.nosp@m.telep.nosp@m.hony.nosp@m..org
Enumerator
SENSITIVE 
INSENSITIVE 

Definition at line 93 of file string.h.

Constructor & Destructor Documentation

◆ String() [1/7]

ucommon::String::String ( )

Create a new empty string object.

Definition at line 169 of file string.cpp.

References str.

Referenced by get(), and operator()().

◆ String() [2/7]

ucommon::String::String ( size_t  size)

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

Parameters
sizeof buffer to allocate.

Definition at line 210 of file string.cpp.

References create(), ucommon::CountedObject::retain(), size(), and str.

◆ String() [3/7]

ucommon::String::String ( size_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.

Definition at line 216 of file string.cpp.

References create(), ucommon::CountedObject::retain(), size(), str, and ucommon::String::cstring::text.

◆ String() [4/7]

ucommon::String::String ( const char *  text)

Create a string from null terminated text.

Parameters
textto use for string.

Definition at line 189 of file string.cpp.

References count(), create(), ucommon::CountedObject::retain(), ucommon::String::cstring::set(), size(), and str.

◆ String() [5/7]

ucommon::String::String ( const char *  text,
size_t  size 
)

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

Parameters
textto use for string.
sizelimit of new string.

Definition at line 199 of file string.cpp.

References create(), ucommon::CountedObject::retain(), ucommon::String::cstring::set(), size(), and str.

◆ String() [6/7]

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.

Definition at line 174 of file string.cpp.

References create(), end(), ucommon::CountedObject::retain(), ucommon::String::cstring::set(), size(), and str.

◆ String() [7/7]

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.

Definition at line 229 of file string.cpp.

References dup(), ucommon::CountedObject::retain(), and str.

◆ ~String()

ucommon::String::~String ( )
virtual

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

Definition at line 236 of file string.cpp.

References release().

Member Function Documentation

◆ add() [1/4]

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.

Definition at line 1591 of file string.cpp.

References set(), size(), and str.

◆ add() [2/4]

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.

Definition at line 1574 of file string.cpp.

References set(), size(), and str.

◆ add() [3/4]

void ucommon::String::add ( char  character)

Append a single character to our string buffer.

Parameters
characterto append.

Definition at line 973 of file string.cpp.

References ucommon::String::cstring::add(), ch, cow(), set(), and str.

◆ add() [4/4]

void ucommon::String::add ( const char *  text)

Append null terminated text to our string buffer.

Parameters
textto append.

Definition at line 992 of file string.cpp.

References ucommon::String::cstring::add(), cow(), set(), and str.

Referenced by ost::addString(), operator&(), operator+(), operator+=(), ucommon::charbuf< S >::operator+=(), ucommon::cidr::set(), ucommon::shell::set0(), and ucommon::StringPager::split().

◆ at()

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.

Definition at line 1006 of file string.cpp.

References ucommon::String::cstring::len, offset(), str, and ucommon::String::cstring::text.

◆ b64()

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.

Definition at line 2117 of file string.cpp.

References b64encode(), out, and size().

Referenced by ucommon::typeref< const uint8_t * >::b64().

◆ b64count()

size_t ucommon::String::b64count ( const char *  str,
bool  ws = false 
)
static

Definition at line 2180 of file string.cpp.

References ucommon::alphabet, count(), and decoder.

Referenced by ucommon::typeref< const uint8_t * >::b64().

◆ b64decode()

size_t ucommon::String::b64decode ( uint8_t *  binary,
const char *  string,
size_t  size,
bool  ws = false 
)
static

Standard radix 64 decoding.

Parameters
binarydata to save.
stringof encoded text.
sizeof destination buffer.
wsflag to skip whitespaces.
Returns
number of characters actually decoded.

Definition at line 2226 of file string.cpp.

References ucommon::alphabet, count(), decoder, and size().

Referenced by ucommon::Cipher::Key::b64(), ucommon::typeref< const uint8_t * >::b64(), and streamdecode().

◆ b64encode()

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.

Definition at line 2126 of file string.cpp.

References ucommon::alphabet, b64size(), count(), end(), and size().

Referenced by ucommon::typeref< const char * >::b64(), b64(), encode(), and encodefile().

◆ b64size()

size_t ucommon::String::b64size ( size_t  size)
static

Definition at line 2175 of file string.cpp.

References size().

Referenced by ucommon::typeref< const char * >::b64(), and b64encode().

◆ begin()

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

Get pointer to first character in string for iteration.

Returns
first character pointer or NULL if empty.

Definition at line 331 of file string.cpp.

References str, and ucommon::String::cstring::text.

◆ c_copy()

String::cstring * ucommon::String::c_copy ( void  ) const
protectedvirtual

Return cstring to use in copy constructors. Is virtual for memstring.

Returns
cstring for copy constructor.

Reimplemented in ucommon::memstring.

Definition at line 241 of file string.cpp.

References str.

◆ c_mem()

char* ucommon::String::c_mem ( )
inline

Definition at line 368 of file string.h.

◆ c_str()

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

Get character text buffer of string object.

Returns
character text buffer.

Definition at line 289 of file string.cpp.

References str, and ucommon::String::cstring::text.

Referenced by ucommon::_stream_operators::append(), ucommon::stringbuf< S >::operator=(), operator^=(), ucommon::_stream_operators::print(), and ost::PersistEngine::write().

◆ ccount() [1/2]

size_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.

Definition at line 625 of file string.cpp.

References str, and ucommon::String::cstring::text.

◆ ccount() [2/2]

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.

Definition at line 1684 of file string.cpp.

References count(), and str.

◆ check()

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.

Definition at line 1643 of file string.cpp.

References count(), ucommon::max(), ucommon::min(), and str.

◆ chop() [1/3]

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.

Definition at line 1622 of file string.cpp.

References offset(), and str.

◆ chop() [2/3]

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

Chop trailing characters from the string.

Parameters
listof characters to remove.

Definition at line 416 of file string.cpp.

References clear(), ucommon::String::cstring::fix(), ucommon::String::cstring::len, offset(), str, and ucommon::String::cstring::text.

Referenced by ucommon::keyfile::load(), and strip().

◆ chop() [3/3]

void ucommon::String::chop ( size_t  count = 1)
inline

Chop trailing characters from text.

Parameters
countof characters to remove.

Definition at line 454 of file string.h.

◆ chr()

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.

Definition at line 347 of file string.cpp.

References ch, str, and ucommon::String::cstring::text.

◆ clear() [1/2]

void ucommon::String::clear ( size_t  offset)

Clear a field of a filled string with filler.

Parameters
offsetto start of field to clear.

Definition at line 933 of file string.cpp.

References ucommon::String::cstring::clear(), offset(), and str.

Referenced by ucommon::Socket::readline().

◆ clear() [2/2]

void ucommon::String::clear ( void  )

Clear string by setting to empty.

Definition at line 941 of file string.cpp.

References ucommon::String::cstring::set(), and str.

Referenced by chop(), and trim().

◆ collate()

static int ucommon::String::collate ( const char *  text1,
const char *  text2 
)
inlinestatic

Definition at line 1099 of file string.h.

Referenced by ucommon::ncompare().

◆ compare() [1/3]

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.

Definition at line 314 of file string.cpp.

References str, and ucommon::String::cstring::text.

Referenced by ucommon::eq(), equal(), ucommon::ge(), ucommon::gt(), ucommon::le(), ucommon::lt(), ucommon::ne(), operator!=(), operator<(), operator<=(), operator==(), operator>(), and operator>=().

◆ compare() [2/3]

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.

Definition at line 1822 of file string.cpp.

◆ compare() [3/3]

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.

◆ copy() [1/2]

static char* ucommon::String::copy ( const char *  text,
size_t  offset,
size_t  len 
)
inlinestatic

Definition at line 1242 of file string.h.

◆ copy() [2/2]

String ucommon::String::copy ( size_t  offset,
size_t  size 
) const
inline

Convenience method for substring extraction.

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

Definition at line 712 of file string.h.

◆ count() [1/2]

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.

Definition at line 1444 of file string.cpp.

◆ count() [2/2]

◆ cow()

void ucommon::String::cow ( size_t  size = 0)
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.

Parameters
sizeto add to allocated space when creating new cstring.

Reimplemented in ucommon::memstring.

Definition at line 947 of file string.cpp.

References create(), ucommon::CountedObject::is_copied(), ucommon::String::cstring::len, ucommon::String::cstring::max, ucommon::CountedObject::release(), ucommon::CountedObject::retain(), set(), size(), str, and ucommon::String::cstring::text.

Referenced by add(), and paste().

◆ crc16()

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.

Definition at line 2307 of file string.cpp.

References binary, and size().

◆ crc24()

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.

Definition at line 2291 of file string.cpp.

References binary, CRC24_INIT, CRC24_POLY, and size().

◆ create()

String::cstring * ucommon::String::create ( size_t  size) const
protected

Factory create a cstring object of specified size.

Parameters
sizeof allocated space for string buffer.
Returns
new cstring object.

Definition at line 256 of file string.cpp.

References size().

Referenced by ucommon::memstring::c_copy(), cow(), fill(), paste(), resize(), ucommon::UString::set(), set(), String(), and ucommon::UString::UString().

◆ cut() [1/2]

void ucommon::String::cut ( char *  text,
size_t  offset,
size_t  len 
)
static

Definition at line 894 of file string.cpp.

References len(), offset(), and size().

◆ cut() [2/2]

void ucommon::String::cut ( size_t  offset,
size_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.

Definition at line 849 of file string.cpp.

References ucommon::String::cstring::fix(), ucommon::String::cstring::len, offset(), size(), str, and ucommon::String::cstring::text.

Referenced by ucommon::UString::cut(), and replace().

◆ data()

char * ucommon::String::data ( void  )

Get memory text buffer of string object.

Returns
writable string buffer.

Definition at line 281 of file string.cpp.

References str, and ucommon::String::cstring::text.

Referenced by ucommon::_stream_operators::input(), ucommon::Socket::readline(), and ucommon::str().

◆ dup()

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.

Definition at line 1390 of file string.cpp.

References __THROW_ALLOC, len(), and set().

Referenced by ucommon::StringPager::split(), and String().

◆ end()

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

Get pointer to last character in string for iteration.

Returns
last character pointer or NULL if empty.

Definition at line 339 of file string.cpp.

References ucommon::String::cstring::len, str, and ucommon::String::cstring::text.

Referenced by b64encode(), ucommon::UString::get(), and String().

◆ eq_case() [1/2]

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.

Definition at line 1772 of file string.cpp.

References stricmp().

Referenced by ucommon::eq_case(), and ucommon::ne_case().

◆ eq_case() [2/2]

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.

Definition at line 1787 of file string.cpp.

References size(), and strnicmp().

◆ equal() [1/3]

bool ucommon::String::equal ( const char *  string) const
protected

Test if two string values are equal.

Parameters
stringto compare with.
Returns
true if equal.

Definition at line 297 of file string.cpp.

References compare(), str, and ucommon::String::cstring::text.

Referenced by ucommon::eq(), and ucommon::ne().

◆ equal() [2/3]

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.

Definition at line 1802 of file string.cpp.

◆ equal() [3/3]

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.

Definition at line 1812 of file string.cpp.

References size().

◆ erase() [1/2]

void ucommon::String::erase ( char *  text)
static

Erase string memory. Often used to clear out passwords.

Parameters
textstring to erase.

Definition at line 1676 of file string.cpp.

References str.

◆ erase() [2/2]

void ucommon::String::erase ( void  )

Erase string memory.

Definition at line 596 of file string.cpp.

References ucommon::String::cstring::fix(), ucommon::String::cstring::max, str, and ucommon::String::cstring::text.

◆ fill() [1/2]

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.

Definition at line 1855 of file string.cpp.

References fill(), size(), and str.

◆ fill() [2/2]

void ucommon::String::fill ( size_t  size,
char  fill 
)

◆ find() [1/3]

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.

Definition at line 1740 of file string.cpp.

References str.

◆ find() [2/3]

const char * ucommon::String::find ( const char *  list,
size_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.

Definition at line 552 of file string.cpp.

References ucommon::String::cstring::len, len(), offset(), str, and ucommon::String::cstring::text.

Referenced by main().

◆ find() [3/3]

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.

Definition at line 1452 of file string.cpp.

References delim, and str.

◆ fix()

void ucommon::String::fix ( String object)
static

◆ full()

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.

Definition at line 1153 of file string.cpp.

References ucommon::String::cstring::len, ucommon::String::cstring::max, and str.

◆ get()

String ucommon::String::get ( size_t  offset,
size_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.

Definition at line 246 of file string.cpp.

References ucommon::String::cstring::len, len(), offset(), str, String(), and ucommon::String::cstring::text.

Referenced by operator%().

◆ getStringSize()

size_t ucommon::String::getStringSize ( void  ) const
protected

◆ hex()

String ucommon::String::hex ( const uint8_t *  binary,
size_t  size 
)
static

Convert binary data buffer into hex string.

Parameters
binarydata to convert.
sizeof data.
Returns
string from data.

Definition at line 1913 of file string.cpp.

References binary, out, and size().

Referenced by ucommon::typeref< const uint8_t * >::hex().

◆ hex2bin()

size_t ucommon::String::hex2bin ( const char *  string,
uint8_t *  binary,
size_t  maxsize,
bool  wsflag = false 
)
static

Definition at line 1949 of file string.cpp.

References count(), ucommon::hexcode(), ucommon::max(), out, and str.

Referenced by ucommon::typeref< const uint8_t * >::hex().

◆ hexcount()

size_t ucommon::String::hexcount ( const char *  str,
bool  ws = false 
)
static

Definition at line 1875 of file string.cpp.

References count(), ucommon::hexcode(), and str.

Referenced by ucommon::typeref< const uint8_t * >::hex().

◆ hexdump()

size_t ucommon::String::hexdump ( const uint8_t *  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.

Definition at line 1924 of file string.cpp.

References binary, count(), and skip().

Referenced by ucommon::secure::uuid(), ucommon::Digest::uuid(), and ucommon::Random::uuid().

◆ hexpack()

size_t ucommon::String::hexpack ( uint8_t *  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.
whitespaceflag to ignore.
Returns
number of bytes processed.

Definition at line 1973 of file string.cpp.

References binary, count(), ucommon::hexcode(), and skip().

◆ hexsize()

size_t ucommon::String::hexsize ( const char *  format)
static

Definition at line 1893 of file string.cpp.

References count(), and skip().

◆ ifind()

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.

Definition at line 1482 of file string.cpp.

References delim, str, and strnicmp().

◆ left() [1/2]

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.

Definition at line 1405 of file string.cpp.

References __THROW_ALLOC, set(), and size().

◆ left() [2/2]

String ucommon::String::left ( size_t  size) const
inline

Convenience method for left of string.

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

Definition at line 693 of file string.h.

◆ len()

◆ lower() [1/2]

void ucommon::String::lower ( char *  text)
static

Convert null terminated text to lower case.

Parameters
textto convert.

Definition at line 1668 of file string.cpp.

References str.

◆ lower() [2/2]

void ucommon::String::lower ( void  )

Convert string to lower case.

Definition at line 590 of file string.cpp.

References str, and ucommon::String::cstring::text.

◆ offset()

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.

Parameters
pointerinto our object's string buffer.

Definition at line 604 of file string.cpp.

References ucommon::String::cstring::len, ucommon::String::cstring::max, npos, str, and ucommon::String::cstring::text.

Referenced by ucommon::UString::at(), at(), chop(), ucommon::String::cstring::clear(), clear(), ucommon::UString::cut(), cut(), ucommon::String::cstring::dec(), find(), get(), ucommon::String::cstring::inc(), ucommon::UString::operator()(), operator()(), operator+=(), operator-=(), operator[](), ucommon::UString::paste(), paste(), pos(), replace(), rfind(), rset(), rskip(), ucommon::String::cstring::set(), set(), skip(), and trim().

◆ operator bool()

ucommon::String::operator bool ( ) const

Test if string has data.

Returns
true if string has data.

Definition at line 1177 of file string.cpp.

References ucommon::String::cstring::fix(), ucommon::String::cstring::len, and str.

◆ operator const char *()

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

Casting reference to raw text string.

Returns
null terminated text of string.

Definition at line 662 of file string.h.

◆ operator!()

bool ucommon::String::operator! ( void  ) const

Test if string is empty.

Returns
true if string is empty.

Definition at line 1164 of file string.cpp.

References ucommon::String::cstring::fix(), ucommon::String::cstring::len, and str.

◆ operator!=()

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.

Definition at line 1195 of file string.cpp.

References compare().

◆ operator%() [1/6]

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.

Definition at line 2095 of file string.cpp.

References ucommon::eq(), get(), len(), set(), str, and ucommon::String::cstring::text.

◆ operator%() [2/6]

String & ucommon::String::operator% ( double &  value)

Parse double value from a string.

Parameters
valueto store.
Returns
object in expression.

Definition at line 2079 of file string.cpp.

References set(), str, and ucommon::String::cstring::text.

◆ operator%() [3/6]

String & ucommon::String::operator% ( long &  value)

Parse long integer value from a string.

Parameters
valueto store.
Returns
object in expression.

Definition at line 2047 of file string.cpp.

References set(), str, and ucommon::String::cstring::text.

◆ operator%() [4/6]

String & ucommon::String::operator% ( short &  value)

Parse short integer value from a string.

Parameters
valueto store.
Returns
object in expression.

Definition at line 2021 of file string.cpp.

References set(), str, temp, and ucommon::String::cstring::text.

◆ operator%() [5/6]

String & ucommon::String::operator% ( unsigned long &  value)

Parse long integer value from a string.

Parameters
valueto store.
Returns
object in expression.

Definition at line 2063 of file string.cpp.

References set(), str, and ucommon::String::cstring::text.

◆ operator%() [6/6]

String & ucommon::String::operator% ( unsigned short &  value)

Parse short integer value from a string.

Parameters
valueto store.
Returns
object in expression.

Definition at line 1998 of file string.cpp.

References set(), str, temp, and ucommon::String::cstring::text.

◆ operator&()

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.

Definition at line 1220 of file string.cpp.

References add().

◆ operator&=()

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

Definition at line 1125 of file string.cpp.

References set().

◆ operator()() [1/2]

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.

Definition at line 1035 of file string.cpp.

References ucommon::String::cstring::len, offset(), str, and ucommon::String::cstring::text.

◆ operator()() [2/2]

String ucommon::String::operator() ( int  offset,
size_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.

Definition at line 1023 of file string.cpp.

References len(), offset(), and String().

◆ operator*()

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

Reference raw text buffer by pointer operator.

Returns
null terminated text of string.

Definition at line 670 of file string.h.

◆ operator*=() [1/3]

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

Definition at line 1097 of file string.cpp.

References search().

◆ operator*=() [2/3]

bool ucommon::String::operator*= ( regex expr)

Definition at line 215 of file regex.cpp.

References search().

◆ operator*=() [3/3]

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

Delete a specified number of characters from start of string.

Parameters
numberof characters to delete.

◆ operator+()

const String ucommon::String::operator+ ( const char *  text) const

Concatenate null terminated text to our object.

Parameters
textto concatenate.

Definition at line 1240 of file string.cpp.

References add(), set(), str, and ucommon::String::cstring::text.

◆ operator++()

String & ucommon::String::operator++ ( void  )

Delete first character from string.

Definition at line 1069 of file string.cpp.

References ucommon::String::cstring::inc(), and str.

◆ operator+=() [1/2]

String & ucommon::String::operator+= ( const char *  text)

Concatenate text to an existing string object.

Parameters
textto add.
Returns
our object for expression use.

Definition at line 1252 of file string.cpp.

References add().

◆ operator+=() [2/2]

String & ucommon::String::operator+= ( size_t  number)

Delete a specified number of characters from start of string.

Parameters
numberof characters to delete.

Definition at line 1083 of file string.cpp.

References ucommon::String::cstring::inc(), offset(), and str.

◆ operator--()

String & ucommon::String::operator-- ( void  )

Delete last character from string.

Definition at line 1076 of file string.cpp.

References ucommon::String::cstring::dec(), and str.

◆ operator-=()

String & ucommon::String::operator-= ( size_t  number)

Delete a specified number of characters from end of string.

Parameters
numberof characters to delete.

Definition at line 1090 of file string.cpp.

References ucommon::String::cstring::dec(), offset(), and str.

◆ operator<()

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.

Definition at line 1200 of file string.cpp.

References compare().

◆ operator<<() [1/2]

String& ucommon::String::operator<< ( char  code)
inline

Definition at line 887 of file string.h.

◆ operator<<() [2/2]

String& ucommon::String::operator<< ( const char *  text)
inline

Definition at line 883 of file string.h.

◆ operator<=()

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.

Definition at line 1205 of file string.cpp.

References compare().

◆ operator=() [1/2]

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

Assign text to our existing buffer. This performs a set method.

Parameters
textto assign from.

Definition at line 1112 of file string.cpp.

References release(), and set().

◆ operator=() [2/2]

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.

Definition at line 1138 of file string.cpp.

References ucommon::CountedObject::release(), ucommon::CountedObject::retain(), and str.

◆ operator==()

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.

Definition at line 1190 of file string.cpp.

References compare().

◆ operator>()

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.

Definition at line 1210 of file string.cpp.

References compare().

◆ operator>=()

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.

Definition at line 1215 of file string.cpp.

References compare().

◆ operator[]()

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.

Definition at line 1052 of file string.cpp.

References ucommon::String::cstring::len, offset(), str, and ucommon::String::cstring::text.

◆ operator^=() [1/2]

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.

Definition at line 1105 of file string.cpp.

References release(), and set().

◆ operator^=() [2/2]

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.

Definition at line 1131 of file string.cpp.

References c_str(), release(), and set().

◆ operator|()

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.

Definition at line 1226 of file string.cpp.

References ucommon::String::cstring::add(), set(), and str.

◆ operator|=()

String & ucommon::String::operator|= ( const char *  text)

Concatenate text to an existing string object. This will use the old behavior when +/= updated.

Definition at line 1119 of file string.cpp.

References set().

◆ paste() [1/2]

void ucommon::String::paste ( char *  text,
size_t  max,
size_t  offset,
const char *  data,
size_t  len = 0 
)
static

Definition at line 868 of file string.cpp.

References len(), ucommon::max(), offset(), set(), and size().

◆ paste() [2/2]

void ucommon::String::paste ( size_t  offset,
const char *  text,
size_t  size = 0 
)

Insert (paste) text into string.

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

Definition at line 818 of file string.cpp.

References cow(), create(), ucommon::String::cstring::fix(), ucommon::String::cstring::len, offset(), set(), size(), str, and ucommon::String::cstring::text.

Referenced by ucommon::UString::paste(), and replace().

◆ pos()

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.

Definition at line 1422 of file string.cpp.

References len(), and offset().

Referenced by ucommon::UString::cut(), ucommon::UString::find(), ucommon::UString::get(), ucommon::UString::paste(), ucommon::UString::rfind(), rsplit(), seek(), and split().

◆ printf()

size_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.

Definition at line 633 of file string.cpp.

References ucommon::String::cstring::fix(), ucommon::String::cstring::len, len(), ucommon::String::cstring::max, str, and ucommon::String::cstring::text.

◆ rchr()

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.

Definition at line 357 of file string.cpp.

References ch, str, and ucommon::String::cstring::text.

◆ release()

void ucommon::String::release ( void  )
protectedvirtual

Decrease retention of our reference counted cstring. May be overridden for memstring which has fixed cstring object.

Reimplemented in ucommon::memstring.

Definition at line 274 of file string.cpp.

References ucommon::CountedObject::release(), and str.

Referenced by operator=(), operator^=(), resize(), and ~String().

◆ replace() [1/2]

unsigned ucommon::String::replace ( const char *  string,
const char *  text = NULL,
unsigned  flags = 0 
)

◆ replace() [2/2]

unsigned ucommon::String::replace ( regex expr,
const char *  text = NULL,
unsigned  flags = 0 
)

◆ resize()

bool ucommon::String::resize ( size_t  size)
virtual

Resize and re-allocate string memory.

Parameters
sizeto allocate for string.
Returns
true if re-allocated. False in derived memstring.

Reimplemented in ucommon::memstring.

Definition at line 913 of file string.cpp.

References create(), ucommon::CountedObject::is_copied(), ucommon::String::cstring::max, ucommon::CountedObject::release(), release(), ucommon::CountedObject::retain(), size(), and str.

Referenced by ucommon::UString::add().

◆ retain()

void ucommon::String::retain ( void  )
protectedvirtual

Increase retention of our reference counted cstring. May be overridden for memstring which has fixed cstring object.

Definition at line 268 of file string.cpp.

References ucommon::CountedObject::retain(), and str.

◆ rfind() [1/2]

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.

Definition at line 1755 of file string.cpp.

References str.

◆ rfind() [2/2]

const char * ucommon::String::rfind ( const char *  list,
size_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.

Definition at line 398 of file string.cpp.

References ucommon::String::cstring::len, offset(), str, and ucommon::String::cstring::text.

◆ right() [1/2]

static char* ucommon::String::right ( const char *  text,
size_t  size 
)
inlinestatic

Definition at line 1238 of file string.h.

References ucommon::dup().

◆ right() [2/2]

String ucommon::String::right ( size_t  offset) const
inline

Convenience method for right of string.

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

Definition at line 702 of file string.h.

◆ rset() [1/2]

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.

Definition at line 1540 of file string.cpp.

References count(), len(), set(), size(), and str.

◆ rset() [2/2]

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.

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.

Definition at line 782 of file string.cpp.

References count(), len(), ucommon::String::cstring::max, offset(), set(), size(), str, and ucommon::String::cstring::text.

◆ rskip() [1/2]

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.

Definition at line 1708 of file string.cpp.

References count(), len(), and str.

◆ rskip() [2/2]

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.

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.

Definition at line 380 of file string.cpp.

References ucommon::String::cstring::len, offset(), str, and ucommon::String::cstring::text.

◆ rsplit() [1/2]

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.

Definition at line 695 of file string.cpp.

References ucommon::String::cstring::len, ucommon::String::cstring::set(), str, and ucommon::String::cstring::text.

Referenced by main().

◆ rsplit() [2/2]

void ucommon::String::rsplit ( size_t  offset)

Split the string at a specific offset. Everything before the offset is removed.

Parameters
offsetto split position in string.

Definition at line 703 of file string.cpp.

References ucommon::String::cstring::len, pos(), ucommon::String::cstring::set(), str, and ucommon::String::cstring::text.

◆ scanf()

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

Scan input items from a string object.

Parameters
formatstring of input to scan.
Returns
number of items scanned.

Definition at line 670 of file string.cpp.

References str, and ucommon::String::cstring::text.

◆ search() [1/2]

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.

Definition at line 521 of file string.cpp.

References INSENSITIVE, ucommon::String::cstring::len, result(), str, and ucommon::String::cstring::text.

Referenced by operator*=().

◆ search() [2/2]

const char * ucommon::String::search ( regex expr,
unsigned  instance = 0,
unsigned  flags = 0 
) const

◆ seek()

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.

Definition at line 1722 of file string.cpp.

References pos(), and str.

◆ set() [1/5]

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.

Definition at line 1548 of file string.cpp.

References size(), and str.

◆ set() [2/5]

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.

Definition at line 1512 of file string.cpp.

References len(), size(), and str.

◆ set() [3/5]

◆ set() [4/5]

void ucommon::String::set ( const char *  text,
char  overflow,
size_t  offset,
size_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.

Definition at line 758 of file string.cpp.

References count(), len(), ucommon::String::cstring::max, offset(), set(), size(), str, and ucommon::String::cstring::text.

◆ set() [5/5]

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.

Parameters
offsetin object string buffer.
textto set at offset.
sizeof text area to set or 0 until end of text.

Definition at line 746 of file string.cpp.

References offset(), ucommon::String::cstring::set(), size(), and str.

◆ size()

◆ skip() [1/2]

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.

Definition at line 1694 of file string.cpp.

References str.

◆ skip() [2/2]

const char * ucommon::String::skip ( const char *  list,
size_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.

Definition at line 367 of file string.cpp.

References ucommon::String::cstring::len, len(), offset(), str, and ucommon::String::cstring::text.

Referenced by hexdump(), hexpack(), and hexsize().

◆ split() [1/2]

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.

Definition at line 711 of file string.cpp.

References ucommon::String::cstring::fix(), ucommon::String::cstring::len, pos(), str, and ucommon::String::cstring::text.

Referenced by main().

◆ split() [2/2]

void ucommon::String::split ( size_t  offset)

Split the string at a specific offset. Everything after the offset is removed.

Parameters
offsetto split position in string.

Definition at line 726 of file string.cpp.

References ucommon::String::cstring::fix(), ucommon::String::cstring::len, pos(), str, and ucommon::String::cstring::text.

◆ strip() [1/2]

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.

Definition at line 1636 of file string.cpp.

References chop(), str, and trim().

◆ strip() [2/2]

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

Strip lead and trailing characters from the string.

Parameters
listof characters to remove.

Definition at line 445 of file string.cpp.

References chop(), and trim().

Referenced by ucommon::keyfile::load().

◆ swap()

void ucommon::String::swap ( String object1,
String object2 
)
static

Swap the cstring references between two strings.

Parameters
object1to swap.
object2to swap.

Definition at line 1383 of file string.cpp.

References str.

Referenced by ucommon::swap< string_t >().

◆ tod() [1/2]

double ucommon::String::tod ( char **  pointer = NULL)
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 1272 of file string.h.

◆ tod() [2/2]

static double ucommon::String::tod ( const char *  text,
char **  pointer = NULL 
)
inlinestatic

Convert text to a double value.

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

Definition at line 1292 of file string.h.

◆ token() [1/2]

char* ucommon::String::token ( char **  last,
const char *  list,
const char *  quote = NULL,
const char *  end = NULL 
)
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 1262 of file string.h.

References quote.

◆ token() [2/2]

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

Definition at line 1305 of file string.cpp.

References quote, and result().

Referenced by ucommon::StringPager::token().

◆ tol() [1/2]

long ucommon::String::tol ( char **  pointer = NULL)
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 1282 of file string.h.

◆ tol() [2/2]

static long ucommon::String::tol ( const char *  text,
char **  pointer = NULL 
)
inlinestatic

Convert text to a long value.

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

Definition at line 1302 of file string.h.

◆ trim() [1/3]

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.

Definition at line 1608 of file string.cpp.

References str.

◆ trim() [2/3]

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

Trim lead characters from the string.

Parameters
listof characters to remove.

Definition at line 451 of file string.cpp.

References clear(), ucommon::String::cstring::fix(), ucommon::String::cstring::len, len(), offset(), str, and ucommon::String::cstring::text.

Referenced by strip().

◆ trim() [3/3]

void ucommon::String::trim ( size_t  count = 1)
inline

Trim lead characters from text.

Parameters
countof characters to remove.

Definition at line 440 of file string.h.

References ucommon::operator+=().

◆ unquote() [1/2]

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.

Definition at line 1837 of file string.cpp.

References count(), len(), and str.

◆ unquote() [2/2]

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.

Definition at line 565 of file string.cpp.

References ucommon::String::cstring::fix(), set(), str, and ucommon::String::cstring::text.

Referenced by ucommon::keyfile::load().

◆ upper() [1/2]

void ucommon::String::upper ( char *  text)
static

Convert null terminated text to upper case.

Parameters
textto convert.

Definition at line 1660 of file string.cpp.

References str.

◆ upper() [2/2]

void ucommon::String::upper ( void  )

Convert string to upper case.

Definition at line 584 of file string.cpp.

References str, and ucommon::String::cstring::text.

◆ vprintf()

size_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.

Definition at line 648 of file string.cpp.

References ucommon::String::cstring::fix(), ucommon::String::cstring::len, len(), ucommon::String::cstring::max, str, and ucommon::String::cstring::text.

◆ vscanf()

int ucommon::String::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.

Definition at line 661 of file string.cpp.

References str, and ucommon::String::cstring::text.

Member Data Documentation

◆ eos

const static char ucommon::String::eos = '\0'
static

Definition at line 266 of file string.h.

◆ npos

const static size_t ucommon::String::npos = ((size_t)-1)
static

Definition at line 265 of file string.h.

Referenced by ucommon::UString::cut(), offset(), and ucommon::UString::paste().

◆ str


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