Yate
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
String Class Reference

A C-style string handling class. More...

#include <yateclass.h>

Inheritance diagram for String:
GenObject CapturedEvent ClientAccountList ClientSound Compressor Configuration MessageHandler NamedCounter NamedInt NamedList NamedString Regexp UIFactory UIWidget URI

Public Types

enum  Align { Left = 0, Center, Right }
 

Public Member Functions

 String ()
 
 String (const char *value, int len=-1)
 
 String (char value, unsigned int repeat=1)
 
 String (int32_t value)
 
 String (uint32_t value)
 
 String (int64_t value)
 
 String (uint64_t value)
 
 String (bool value)
 
 String (double value)
 
 String (const String &value)
 
 String (const String *value)
 
virtual ~String ()
 
virtual void * getObject (const String &name) const
 
const char * c_str () const
 
const char * safe () const
 
const char * safe (const char *defStr) const
 
unsigned int length () const
 
bool null () const
 
int lenUtf8 (uint32_t maxChar=0x10ffff, bool overlong=false) const
 
int fixUtf8 (const char *replace=0, uint32_t maxChar=0x10ffff, bool overlong=false)
 
bool checkBOM () const
 
bool stripBOM ()
 
unsigned int hash () const
 
void clear ()
 
char at (int index) const
 
String substr (int offs, int len=-1) const
 
StringtrimBlanks ()
 
StringtrimSpaces ()
 
virtual const StringtoString () const
 
int toInteger (int defvalue=0, int base=0, int minvalue=INT_MIN, int maxvalue=INT_MAX, bool clamp=true) const
 
int toInteger (const TokenDict *tokens, int defvalue=0, int base=0) const
 
long int toLong (long int defvalue=0, int base=0, long int minvalue=LONG_MIN, long int maxvalue=LONG_MAX, bool clamp=true) const
 
int64_t toInt64 (int64_t defvalue=0, int base=0, int64_t minvalue=LLONG_MIN, int64_t maxvalue=LLONG_MAX, bool clamp=true) const
 
double toDouble (double defvalue=0.0) const
 
bool toBoolean (bool defvalue=false) const
 
bool isBoolean () const
 
StringtoUpper ()
 
StringtoLower ()
 
char operator[] (signed int index) const
 
char operator[] (unsigned int index) const
 
 operator const char * () const
 
Stringassign (const char *value, int len=-1)
 
Stringassign (char value, unsigned int repeat=1)
 
Stringhexify (void *data, unsigned int len, char sep=0, bool upCase=false)
 
Stringoperator= (const String &value)
 
Stringoperator= (const String *value)
 
Stringoperator= (const char *value)
 
Stringoperator= (char value)
 
Stringoperator= (int32_t value)
 
Stringoperator= (uint32_t value)
 
Stringoperator= (int64_t value)
 
Stringoperator= (uint64_t value)
 
Stringoperator= (bool value)
 
Stringoperator= (double value)
 
Stringoperator+= (const char *value)
 
Stringoperator+= (char value)
 
Stringoperator+= (int32_t value)
 
Stringoperator+= (uint32_t value)
 
Stringoperator+= (int64_t value)
 
Stringoperator+= (uint64_t value)
 
Stringoperator+= (bool value)
 
Stringoperator+= (double value)
 
bool operator== (const char *value) const
 
bool operator!= (const char *value) const
 
bool operator== (const String &value) const
 
bool operator!= (const String &value) const
 
bool operator&= (const char *value) const
 
bool operator|= (const char *value) const
 
Stringoperator<< (const char *value)
 
Stringoperator<< (char value)
 
Stringoperator<< (int32_t value)
 
Stringoperator<< (uint32_t value)
 
Stringoperator<< (int64_t value)
 
Stringoperator<< (uint64_t value)
 
Stringoperator<< (bool value)
 
Stringoperator<< (double value)
 
Stringoperator>> (const char *skip)
 
Stringoperator>> (char &store)
 
Stringoperator>> (UChar &store)
 
Stringoperator>> (int &store)
 
Stringoperator>> (unsigned int &store)
 
Stringoperator>> (bool &store)
 
Stringappend (const char *value, int len)
 
Stringappend (const char *value, const char *separator=0, bool force=false)
 
Stringappend (const ObjList *list, const char *separator=0, bool force=false)
 
Stringappend (const ObjList &list, const char *separator=0, bool force=false)
 
Stringappend (double value, unsigned int decimals=3)
 
Stringprintf (const char *format,...)
 
Stringprintf (unsigned int length, const char *format,...)
 
StringappendFixed (unsigned int fixedLength, const char *str, unsigned int len=-1, char fill= ' ', int align=Left)
 
StringappendFixed (unsigned int fixedLength, const String &str, char fill= ' ', int align=Left)
 
int find (char what, unsigned int offs=0) const
 
int find (const char *what, unsigned int offs=0) const
 
int rfind (char what) const
 
int rfind (const char *what) const
 
bool startsWith (const char *what, bool wordBreak=false, bool caseInsensitive=false) const
 
bool endsWith (const char *what, bool wordBreak=false, bool caseInsensitive=false) const
 
bool startSkip (const char *what, bool wordBreak=true, bool caseInsensitive=false)
 
StringextractTo (const char *sep, String &store)
 
StringextractTo (const char *sep, bool &store)
 
StringextractTo (const char *sep, int &store, int base=0)
 
StringextractTo (const char *sep, int &store, const TokenDict *tokens, int base=0)
 
StringextractTo (const char *sep, double &store)
 
virtual bool matches (const String &value) const
 
bool matches (const Regexp &rexp)
 
int matchOffset (int index=0) const
 
int matchLength (int index=0) const
 
String matchString (int index=0) const
 
String replaceMatches (const String &templ) const
 
int matchCount () const
 
ObjListsplit (char separator, bool emptyOK=true) const
 
String msgEscape (char extraEsc=0) const
 
String msgUnescape (int *errptr=0, char extraEsc=0) const
 
String sqlEscape (char extraEsc=0) const
 
String uriEscape (char extraEsc=0, const char *noEsc=0) const
 
String uriUnescape (int *errptr=0) const
 
- Public Member Functions inherited from GenObject
 GenObject ()
 
virtual ~GenObject ()
 
virtual bool alive () const
 
virtual void destruct ()
 
NamedCountergetObjCounter () const
 
NamedCountersetObjCounter (NamedCounter *counter)
 

Static Public Member Functions

static const Stringempty ()
 
static const char * boolText (bool value)
 
static int lenUtf8 (const char *value, uint32_t maxChar=0x10ffff, bool overlong=false)
 
static bool checkBOM (const char *str)
 
static bool stripBOM (const char *&str)
 
static bool stripBOM (char *&str)
 
static unsigned int hash (const char *value, unsigned int h=0)
 
static String msgEscape (const char *str, char extraEsc=0)
 
static String msgUnescape (const char *str, int *errptr=0, char extraEsc=0)
 
static String sqlEscape (const char *str, char extraEsc=0)
 
static String uriEscape (const char *str, char extraEsc=0, const char *noEsc=0)
 
static String uriEscape (const char *str, const char *extraEsc, const char *noEsc=0)
 
static String uriUnescape (const char *str, int *errptr=0)
 
static const Stringatom (const String *&str, const char *val)
 
- Static Public Member Functions inherited from GenObject
static void * getObject (const String &name, const GenObject *obj)
 
static bool getObjCounting ()
 
static void setObjCounting (bool enable)
 
static NamedCountergetObjCounter (const String &name, bool create=true)
 
static ObjListgetObjCounters ()
 

Protected Member Functions

virtual void changed ()
 

Detailed Description

A C-style string handling class.

A simple string handling class for C style (one byte) strings. For simplicity and read speed no copy-on-write is performed. Strings have hash capabilities and comparations are using the hash for fast inequality check.

Constructor & Destructor Documentation

String ( )

Creates a new, empty string.

String ( const char *  value,
int  len = -1 
)

Creates a new initialized string.

Parameters
valueInitial value of the string
lenLength of the data to copy, -1 for full string
String ( char  value,
unsigned int  repeat = 1 
)
explicit

Creates a new initialized string.

Parameters
valueCharacter to fill the string
repeatHow many copies of the character to use
String ( int32_t  value)
explicit

Creates a new initialized string from a 32 bit integer.

Parameters
valueValue to convert to string
String ( uint32_t  value)
explicit

Creates a new initialized string from a 32 bit unsigned int.

Parameters
valueValue to convert to string
String ( int64_t  value)
explicit

Creates a new initialized string from a 64 bit integer.

Parameters
valueValue to convert to string
String ( uint64_t  value)
explicit

Creates a new initialized string from a 64 bit unsigned int.

Parameters
valueValue to convert to string
String ( bool  value)
explicit

Creates a new initialized string from a boolean.

Parameters
valueValue to convert to string
String ( double  value)
explicit

Creates a new initialized string from a double value.

Parameters
valueValue to convert to string
String ( const String value)

Copy constructor.

Parameters
valueInitial value of the string
String ( const String value)

Constructor from String pointer.

Parameters
valueInitial value of the string
virtual ~String ( )
virtual

Destroys the string, disposes the memory.

Member Function Documentation

String& append ( const char *  value,
int  len 
)

Append a string to the current string

Parameters
valueString from which to append
lenLength of the data to copy, -1 for full string
Returns
Reference to the String

Referenced by String::append(), SliceVector< Obj >::dump(), and String::operator+=().

String& append ( const char *  value,
const char *  separator = 0,
bool  force = false 
)

Conditional appending with a separator

Parameters
valueString to append
separatorSeparator to insert before the value
forceTrue to allow appending empty strings
String& append ( const ObjList list,
const char *  separator = 0,
bool  force = false 
)

List members appending with a separator

Parameters
listPointer to ObjList whose GenObject::toString() of the items will be appended
separatorSeparator to insert before each item in list
forceTrue to allow appending empty strings
String& append ( const ObjList list,
const char *  separator = 0,
bool  force = false 
)
inline

List members appending with a separator

Parameters
listReference of ObjList whose GenObject::toString() of the items will be appended
separatorSeparator to insert before each item in list
forceTrue to allow appending empty strings

References String::append().

String& append ( double  value,
unsigned int  decimals = 3 
)

Explicit double append

Parameters
valueValue to append
decimalsNumber of decimals
String& appendFixed ( unsigned int  fixedLength,
const char *  str,
unsigned int  len = -1,
char  fill = ' ',
int  align = Left 
)

Build a fixed aligned string from str and append it.

Parameters
fixedLengthThe fixed length in which the 'str' will be aligned.
strThe string to align
lenThe number of characters to use from str.
fillCharacter to fill the empty space.
alignThe alignment mode.

Referenced by String::appendFixed().

String& appendFixed ( unsigned int  fixedLength,
const String str,
char  fill = ' ',
int  align = Left 
)
inline

Build a fixed aligned string from str and append it.

Parameters
fixedLengthThe fixed length in which the 'str' will be aligned.
strThe string to align
fillCharacter to fill the empty space.
alignThe alignment mode.

References String::appendFixed(), String::c_str(), and String::length().

String& assign ( const char *  value,
int  len = -1 
)

Assigns a new value to the string from a character block.

Parameters
valueNew value of the string
lenLength of the data to copy, -1 for full string
Returns
Reference to the String
String& assign ( char  value,
unsigned int  repeat = 1 
)

Assigns a new value by filling with a repeated character

Parameters
valueCharacter to fill the string
repeatHow many copies of the character to use
Returns
Reference to the String
char at ( int  index) const

Extract the caracter at a given index

Parameters
indexIndex of character in string
Returns
Character at given index or 0 if out of range

Referenced by String::operator[]().

static const String* atom ( const String *&  str,
const char *  val 
)
static

Atom string support helper

Parameters
strReference to variable to hold the atom string
valString value to allocate to the atom
Returns
Pointer to shared atom string

Referenced by Atom::Atom().

static const char* boolText ( bool  value)
inlinestatic

A standard text representation of boolean values

Parameters
valueBoolean value to convert
Returns
Pointer to a text representation of the value

Referenced by String::operator+=(), String::operator=(), ClientContact::setLocal(), ClientContact::setRemote(), and ClientAccount::startup().

const char* c_str ( ) const
inline
virtual void changed ( )
protectedvirtual

Called whenever the value changed (except in constructors).

Reimplemented in URI, NamedPointer, Regexp, and DataFormat.

static bool checkBOM ( const char *  str)
inlinestatic

Check if a string starts with UTF-8 Byte Order Mark

Parameters
strString to check for BOM
Returns
True if the string starts with UTF-8 BOM
bool checkBOM ( ) const
inline

Check if this string starts with UTF-8 Byte Order Mark

Returns
True if the string starts with UTF-8 BOM

References String::c_str().

Referenced by String::stripBOM().

void clear ( )

Clear the string and free the memory

Referenced by XmlSaxParser::resetParsed().

static const String& empty ( )
static
bool endsWith ( const char *  what,
bool  wordBreak = false,
bool  caseInsensitive = false 
) const

Checks if the string ends with a substring

Parameters
whatSubstring to search for
wordBreakCheck if a word boundary precedes the substring
caseInsensitiveCompare case-insensitive if set
Returns
True if the substring occurs at the end of the string
String& extractTo ( const char *  sep,
String store 
)

Extract a substring up to a separator

Parameters
sepSeparator string to match after extracted fragment
storeReference to String variable to store extracted fragment
Returns
Reference to this string
String& extractTo ( const char *  sep,
bool &  store 
)

Extract a boolean substring up to a separator

Parameters
sepSeparator string to match after extracted fragment
storeReference to boolean variable to store extracted fragment
Returns
Reference to this string
String& extractTo ( const char *  sep,
int &  store,
int  base = 0 
)

Extract an integer value substring up to a separator

Parameters
sepSeparator string to match after extracted fragment
storeReference to integer variable to store extracted fragment
baseNumeration base, 0 to autodetect
Returns
Reference to this string
String& extractTo ( const char *  sep,
int &  store,
const TokenDict tokens,
int  base = 0 
)

Extract an integer or token value substring up to a separator

Parameters
sepSeparator string to match after extracted fragment
storeReference to integer variable to store extracted fragment
tokensPointer to an array of tokens to lookup first
baseNumeration base, 0 to autodetect
Returns
Reference to this string
String& extractTo ( const char *  sep,
double &  store 
)

Extract a double value substring up to a separator

Parameters
sepSeparator string to match after extracted fragment
storeReference to double variable to store extracted fragment
Returns
Reference to this string
int find ( char  what,
unsigned int  offs = 0 
) const

Locate the first instance of a character in the string

Parameters
whatCharacter to search for
offsOffset in string to start searching from
Returns
Offset of character or -1 if not found

Referenced by ClientContact::splitContactId().

int find ( const char *  what,
unsigned int  offs = 0 
) const

Locate the first instance of a substring in the string

Parameters
whatSubstring to search for
offsOffset in string to start searching from
Returns
Offset of substring or -1 if not found
int fixUtf8 ( const char *  replace = 0,
uint32_t  maxChar = 0x10ffff,
bool  overlong = false 
)

Fix an UTF-8 encoded string by replacing invalid sequences

Parameters
replaceString to replace invalid sequences, use U+FFFD if null
maxCharMaximum accepted Unicode character code
overlongAccept overlong UTF-8 sequences (dangerous!)
Returns
Count of invalid UTF-8 sequences that were replaced
virtual void* getObject ( const String name) const
virtual

Get a pointer to a derived class given that class name

Parameters
nameName of the class we are asking for
Returns
Pointer to the requested class or NULL if this object doesn't implement it

Reimplemented from GenObject.

Reimplemented in NamedList, NamedPointer, NamedString, Message, MimeAuthLine, and MimeHeaderLine.

unsigned int hash ( ) const
inline

Get the hash of the contained string.

Returns
The hash of the string.

Referenced by HashList::getHashList(), String::operator!=(), and String::operator==().

static unsigned int hash ( const char *  value,
unsigned int  h = 0 
)
static

Get the hash of an arbitrary string.

Parameters
valueC string to hash
hOld hash value for incremental hashing
Returns
The hash of the string.
String& hexify ( void *  data,
unsigned int  len,
char  sep = 0,
bool  upCase = false 
)

Build a hexadecimal representation of a buffer of data

Parameters
dataPointer to data to dump
lenLength of the data buffer
sepSeparator character to use between octets
upCaseSet to true to use upper case characters in hexa
Returns
Reference to the String

Referenced by SliceVector< Obj >::hexify().

bool isBoolean ( ) const

Check if the string can be converted to a boolean value.

Returns
True if the string is a valid boolean.
unsigned int length ( ) const
inline
static int lenUtf8 ( const char *  value,
uint32_t  maxChar = 0x10ffff,
bool  overlong = false 
)
static

Get the number of characters in a string assuming UTF-8 encoding

Parameters
valueC string to compute Unicode length
maxCharMaximum accepted Unicode character code
overlongAccept overlong UTF-8 sequences (dangerous!)
Returns
Count of Unicode characters, -1 if not valid UTF-8

Referenced by String::lenUtf8().

int lenUtf8 ( uint32_t  maxChar = 0x10ffff,
bool  overlong = false 
) const
inline

Get the number of characters in the string assuming UTF-8 encoding

Parameters
maxCharMaximum accepted Unicode character code
overlongAccept overlong UTF-8 sequences (dangerous!)
Returns
Count of Unicode characters, -1 if not valid UTF-8

References String::lenUtf8().

int matchCount ( ) const

Get the total number of submatches from the last match, 0 if no match

Returns
Number of matching subexpressions
virtual bool matches ( const String value) const
inlinevirtual

Checks if matches another string

Parameters
valueString to check for match
Returns
True if matches, false otherwise

Reimplemented in Regexp.

References String::operator==().

bool matches ( const Regexp rexp)

Checks if matches a regular expression and fill the match substrings

Parameters
rexpRegular expression to check for match
Returns
True if matches, false otherwise
int matchLength ( int  index = 0) const

Get the length of the last match

Parameters
indexIndex of the submatch to return, 0 for full match
Returns
Length of the last match, 0 if no match or out of range

Referenced by String::matchString().

int matchOffset ( int  index = 0) const

Get the offset of the last match

Parameters
indexIndex of the submatch to return, 0 for full match
Returns
Offset of the last match, -1 if no match or not in range

Referenced by String::matchString().

String matchString ( int  index = 0) const
inline

Get a copy of a matched (sub)string

Parameters
indexIndex of the submatch to return, 0 for full match
Returns
Copy of the matched substring

References String::matchLength(), String::matchOffset(), and String::substr().

static String msgEscape ( const char *  str,
char  extraEsc = 0 
)
static

Create an escaped string suitable for use in messages

Parameters
strString to convert to escaped format
extraEscCharacter to escape other than the default ones
Returns
The string with special characters escaped

Referenced by String::msgEscape().

String msgEscape ( char  extraEsc = 0) const
inline

Create an escaped string suitable for use in messages

Parameters
extraEscCharacter to escape other than the default ones
Returns
The string with special characters escaped

References String::c_str(), and String::msgEscape().

static String msgUnescape ( const char *  str,
int *  errptr = 0,
char  extraEsc = 0 
)
static

Decode an escaped string back to its raw form

Parameters
strString to convert to unescaped format
errptrPointer to an integer to receive the place of 1st error
extraEscCharacter to unescape other than the default ones
Returns
The string with special characters unescaped

Referenced by String::msgUnescape().

String msgUnescape ( int *  errptr = 0,
char  extraEsc = 0 
) const
inline

Decode an escaped string back to its raw form

Parameters
errptrPointer to an integer to receive the place of 1st error
extraEscCharacter to unescape other than the default ones
Returns
The string with special characters unescaped

References String::c_str(), and String::msgUnescape().

bool null ( ) const
inline

Checks if the string holds a NULL pointer.

Returns
True if the string holds NULL, false otherwise.

Referenced by Module::filterInstalled(), and TelEngine::null().

operator const char * ( ) const
inline

Conversion to "const char *" operator.

Returns
Pointer to the internally stored string
bool operator!= ( const char *  value) const

Inequality operator.

bool operator!= ( const String value) const
inline

Fast inequality operator.

References String::c_str(), and String::hash().

bool operator&= ( const char *  value) const

Case-insensitive equality operator.

String& operator+= ( const char *  value)
inline

Appending operator for strings.

Parameters
valueValue to assign to the string
See also
TelEngine::strcat

References String::append().

Referenced by String::operator+=(), and String::operator<<().

String& operator+= ( char  value)

Appending operator for single characters.

Parameters
valueValue to append to the string
String& operator+= ( int32_t  value)

Appending operator for 32 bit integers.

Parameters
valueValue to append to the string
String& operator+= ( uint32_t  value)

Appending operator for 32 bit unsigned integers.

Parameters
valueValue to append to the string
String& operator+= ( int64_t  value)

Appending operator for 64 bit integers.

Parameters
valueValue to append to the string
String& operator+= ( uint64_t  value)

Appending operator for 64 bit unsigned integers.

Parameters
valueValue to append to the string
String& operator+= ( bool  value)
inline

Appending operator for booleans.

Parameters
valueValue to append to the string

References String::boolText(), and String::operator+=().

String& operator+= ( double  value)

Appending operator for double.

Parameters
valueValue to append to the string
String& operator<< ( const char *  value)
inline

Stream style appending operator for C strings

References String::operator+=().

String& operator<< ( char  value)
inline

Stream style appending operator for single characters

References String::operator+=().

String& operator<< ( int32_t  value)
inline

Stream style appending operator for 32 bit integers

References String::operator+=().

String& operator<< ( uint32_t  value)
inline

Stream style appending operator for 32 bit unsigned integers

References String::operator+=().

String& operator<< ( int64_t  value)
inline

Stream style appending operator for 64 bit integers

References String::operator+=().

String& operator<< ( uint64_t  value)
inline

Stream style appending operator for 64 bit unsigned integers

References String::operator+=().

String& operator<< ( bool  value)
inline

Stream style appending operator for booleans

References String::operator+=().

String& operator<< ( double  value)
inline

Stream style appending operator for double

References String::operator+=().

String& operator= ( const String value)
inline

Assignment operator.

Parameters
valueValue to assign to the string

References String::c_str().

Referenced by Configuration::operator=(), Message::operator=(), String::operator=(), Regexp::operator=(), NamedString::operator=(), and URI::operator=().

String& operator= ( const String value)
inline

Assignment from String* operator.

Parameters
valueValue to assign to the string
See also
TelEngine::strcpy

References String::c_str(), and String::operator=().

String& operator= ( const char *  value)

Assignment from char* operator.

Parameters
valueValue to assign to the string
See also
TelEngine::strcpy
String& operator= ( char  value)

Assignment operator for single characters.

Parameters
valueValue to assign to the string
String& operator= ( int32_t  value)

Assignment operator for 32 bit integers.

Parameters
valueValue to assign to the string
String& operator= ( uint32_t  value)

Assignment operator for 32 bit unsigned integers.

Parameters
valueValue to assign to the string
String& operator= ( int64_t  value)

Assignment operator for 64 bit integers.

Parameters
valueValue to assign to the string
String& operator= ( uint64_t  value)

Assignment operator for 64 bit unsigned integers.

Parameters
valueValue to assign to the string
String& operator= ( bool  value)
inline

Assignment operator for booleans.

Parameters
valueValue to assign to the string

References String::boolText(), and String::operator=().

String& operator= ( double  value)

Assignment operator for double.

Parameters
valueValue to assign to the string
bool operator== ( const char *  value) const

Equality operator.

Referenced by String::matches().

bool operator== ( const String value) const
inline

Fast equality operator.

References String::c_str(), and String::hash().

String& operator>> ( const char *  skip)

Stream style substring skipping operator. It eats all characters up to and including the skip string

String& operator>> ( char &  store)

Stream style extraction operator for single characters

String& operator>> ( UChar store)

Stream style extraction operator for single Unicode characters

String& operator>> ( int &  store)

Stream style extraction operator for integers

String& operator>> ( unsigned int &  store)

Stream style extraction operator for unsigned integers

String& operator>> ( bool &  store)

Stream style extraction operator for booleans

char operator[] ( signed int  index) const
inline

Indexing operator with signed int

Parameters
indexIndex of character in string
Returns
Character at given index or 0 if out of range

References String::at().

char operator[] ( unsigned int  index) const
inline

Indexing operator with unsigned int

Parameters
indexIndex of character in string
Returns
Character at given index or 0 if out of range

References String::at().

bool operator|= ( const char *  value) const

Case-insensitive inequality operator.

String& printf ( const char *  format,
  ... 
)

Build a String in a printf style.

Parameters
formatThe output format. NOTE: The length of the resulting string will be at most 128 + length of format
String& printf ( unsigned int  length,
const char *  format,
  ... 
)

Build a String in a printf style.

Parameters
lengthmaximum length of the resulting string
formatThe output format.
String replaceMatches ( const String templ) const

Create a string by replacing matched strings in a template

Parameters
templTemplate of the string to generate
Returns
Copy of template with "\0" - "\9" replaced with submatches
int rfind ( char  what) const

Locate the last instance of a character in the string

Parameters
whatCharacter to search for
Returns
Offset of character or -1 if not found
int rfind ( const char *  what) const

Locate the last instance of a substring in the string

Parameters
whatSubstring to search for
Returns
Offset of substring or -1 if not found
const char* safe ( ) const
inline

Get a valid non-NULL C string.

Returns
The stored C string or a static "".

Referenced by TelEngine::c_safe(), and Regexp::matches().

const char* safe ( const char *  defStr) const
inline

Get a valid non-NULL C string with a provided default.

Parameters
defStrDefault C string to return if stored is NULL
Returns
The stored C string, the default or a static "".
ObjList* split ( char  separator,
bool  emptyOK = true 
) const

Splits the string at a delimiter character

Parameters
separatorCharacter where to split the string
emptyOKTrue if empty strings should be inserted in list
Returns
A newly allocated list of strings, must be deleted after use
static String sqlEscape ( const char *  str,
char  extraEsc = 0 
)
static

Create an escaped string suitable for use in SQL queries

Parameters
strString to convert to escaped format
extraEscCharacter to escape other than the default ones
Returns
The string with special characters escaped

Referenced by String::sqlEscape().

String sqlEscape ( char  extraEsc = 0) const
inline

Create an escaped string suitable for use in SQL queries

Parameters
extraEscCharacter to escape other than the default ones
Returns
The string with special characters escaped

References String::c_str(), and String::sqlEscape().

bool startSkip ( const char *  what,
bool  wordBreak = true,
bool  caseInsensitive = false 
)

Checks if the string starts with a substring and removes it

Parameters
whatSubstring to search for
wordBreakCheck if a word boundary follows the substring; this parameter defaults to True because the intended use of this method is to separate commands from their parameters
caseInsensitiveCompare case-insensitive if set
Returns
True if the substring occurs at the beginning of the string and also removes the substring; if wordBreak is True any word breaking characters are also removed

Referenced by ClientContact::getContactSection().

bool startsWith ( const char *  what,
bool  wordBreak = false,
bool  caseInsensitive = false 
) const

Checks if the string starts with a substring

Parameters
whatSubstring to search for
wordBreakCheck if a word boundary follows the substring
caseInsensitiveCompare case-insensitive if set
Returns
True if the substring occurs at the beginning of the string

Referenced by XmlElement::isXmlns().

static bool stripBOM ( const char *&  str)
inlinestatic

Advance a const string past an UTF-8 Byte Order Mark

Parameters
strString to check for and strip BOM
Returns
True if the string started with UTF-8 BOM

References String::checkBOM().

static bool stripBOM ( char *&  str)
inlinestatic

Advance a string past an UTF-8 Byte Order Mark

Parameters
strString to check for and strip BOM
Returns
True if the string started with UTF-8 BOM

References String::checkBOM().

bool stripBOM ( )
inline

Strip an UTF-8 Byte Order Mark from the start of this string

Returns
True if the string started with UTF-8 BOM

References String::c_str(), and String::checkBOM().

String substr ( int  offs,
int  len = -1 
) const

Substring extraction

Parameters
offsOffset of the substring, negative to count from end
lenLength of the substring, -1 for everything possible
Returns
A copy of the requested substring

Referenced by String::matchString(), and ClientContact::splitContactId().

bool toBoolean ( bool  defvalue = false) const

Convert the string to a boolean value.

Parameters
defvalueDefault to return if the string is not a bool
Returns
The boolean interpretation or defvalue.
double toDouble ( double  defvalue = 0.0) const

Convert the string to a floating point value.

Parameters
defvalueDefault to return if the string is not a number
Returns
The floating-point interpretation or defvalue.
int64_t toInt64 ( int64_t  defvalue = 0,
int  base = 0,
int64_t  minvalue = LLONG_MIN,
int64_t  maxvalue = LLONG_MAX,
bool  clamp = true 
) const

Convert the string to an 64 bit integer value.

Parameters
defvalueDefault to return if the string is not a number
baseNumeration base, 0 to autodetect
minvalueMinimum value allowed
maxvalueMaximum value allowed
clampControl the out of bound values: true to adjust to the nearest bound, false to return the default value
Returns
The 64 bit integer interpretation or defvalue.
int toInteger ( int  defvalue = 0,
int  base = 0,
int  minvalue = INT_MIN,
int  maxvalue = INT_MAX,
bool  clamp = true 
) const

Convert the string to an integer value.

Parameters
defvalueDefault to return if the string is not a number
baseNumeration base, 0 to autodetect
minvalueMinimum value allowed
maxvalueMaximum value allowed
clampControl the out of bound values: true to adjust to the nearest bound, false to return the default value
Returns
The integer interpretation or defvalue.
int toInteger ( const TokenDict tokens,
int  defvalue = 0,
int  base = 0 
) const

Convert the string to an integer value looking up first a token table.

Parameters
tokensPointer to an array of tokens to lookup first
defvalueDefault to return if the string is not a token or number
baseNumeration base, 0 to autodetect
Returns
The integer interpretation or defvalue.
long int toLong ( long int  defvalue = 0,
int  base = 0,
long int  minvalue = LONG_MIN,
long int  maxvalue = LONG_MAX,
bool  clamp = true 
) const

Convert the string to an long integer value.

Parameters
defvalueDefault to return if the string is not a number
baseNumeration base, 0 to autodetect
minvalueMinimum value allowed
maxvalueMaximum value allowed
clampControl the out of bound values: true to adjust to the nearest bound, false to return the default value
Returns
The long integer interpretation or defvalue.
String& toLower ( )

Turn the string to an all-lowercase string

Returns
A reference to this String

Referenced by ClientContact::buildContactId().

virtual const String& toString ( ) const
virtual

Override GenObject's method to return this String

Returns
A reference to this String

Reimplemented from GenObject.

Reimplemented in NamedString.

Referenced by UIWidget::name().

String& toUpper ( )

Turn the string to an all-uppercase string

Returns
A reference to this String
String& trimBlanks ( )

Strip off leading and trailing blank characters

String& trimSpaces ( )

Strip off leading and trailing whitespace characters (blank, tabs, form-feed, newlines)

static String uriEscape ( const char *  str,
char  extraEsc = 0,
const char *  noEsc = 0 
)
static

Create an escaped string suitable for use in URIs

Parameters
strString to convert to escaped format
extraEscCharacter to escape other than the default ones
noEscOptional pointer to string of characters that shouldn't be escaped
Returns
The string with special characters escaped

Referenced by ClientContact::buildContactId(), ClientContact::buildContactInstanceId(), and String::uriEscape().

static String uriEscape ( const char *  str,
const char *  extraEsc,
const char *  noEsc = 0 
)
static

Create an escaped string suitable for use in URIs

Parameters
strString to convert to escaped format
extraEscPointer to string of characters to escape other than the defaults
noEscOptional pointer to string of characters that shouldn't be escaped
Returns
The string with special characters escaped
String uriEscape ( char  extraEsc = 0,
const char *  noEsc = 0 
) const
inline

Create an escaped string suitable for use in URI

Parameters
extraEscCharacter to escape other than the default ones
noEscOptional pointer to string of characters that shouldn't be escaped
Returns
The string with special characters escaped

References String::c_str(), and String::uriEscape().

static String uriUnescape ( const char *  str,
int *  errptr = 0 
)
static

Decode an URI escaped string back to its raw form

Parameters
strString to convert to unescaped format
errptrPointer to an integer to receive the place of 1st error
Returns
The string with special characters unescaped

Referenced by ClientContact::getContactSection(), ClientContact::splitContactId(), and String::uriUnescape().

String uriUnescape ( int *  errptr = 0) const
inline

Decode an URI escaped string back to its raw form

Parameters
errptrPointer to an integer to receive the place of 1st error
Returns
The string with special characters unescaped

References String::c_str(), and String::uriUnescape().


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