|
Yate
|
A C-style string handling class. More...
#include <yateclass.h>
Public Member Functions | |
| String () | |
| String (const char *value, int len=-1) | |
| String (char value, unsigned int repeat=1) | |
| String (int value) | |
| String (unsigned int value) | |
| String (bool 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 (unsigned int maxSeq=4, bool overlong=false) const |
| int | fixUtf8 (const char *replace=0, unsigned int maxSeq=4, bool overlong=false) |
| unsigned int | hash () const |
| void | clear () |
| char | at (int index) const |
| String | substr (int offs, int len=-1) const |
| String & | trimBlanks () |
| String & | trimSpaces () |
| virtual const String & | toString () 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 |
| double | toDouble (double defvalue=0.0) const |
| bool | toBoolean (bool defvalue=false) const |
| bool | isBoolean () const |
| String & | toUpper () |
| String & | toLower () |
| char | operator[] (signed int index) const |
| char | operator[] (unsigned int index) const |
| operator const char * () const | |
| String & | assign (const char *value, int len=-1) |
| String & | assign (char value, unsigned int repeat=1) |
| String & | hexify (void *data, unsigned int len, char sep=0, bool upCase=false) |
| String & | operator= (const String &value) |
| String & | operator= (const String *value) |
| String & | operator= (const char *value) |
| String & | operator= (char value) |
| String & | operator= (int value) |
| String & | operator= (unsigned int value) |
| String & | operator= (bool value) |
| String & | operator+= (const char *value) |
| String & | operator+= (char value) |
| String & | operator+= (int value) |
| String & | operator+= (unsigned int value) |
| String & | operator+= (bool 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 |
| String & | operator<< (const char *value) |
| String & | operator<< (char value) |
| String & | operator<< (int value) |
| String & | operator<< (unsigned int value) |
| String & | operator<< (bool value) |
| String & | operator>> (const char *skip) |
| String & | operator>> (char &store) |
| String & | operator>> (int &store) |
| String & | operator>> (unsigned int &store) |
| String & | operator>> (bool &store) |
| String & | append (const char *value, const char *separator=0, bool force=false) |
| String & | append (const ObjList *list, const char *separator=0, bool force=false) |
| String & | append (const ObjList &list, const char *separator=0, bool force=false) |
| String & | append (double value, unsigned int decimals=3) |
| int | find (char what, unsigned int offs=0) const |
| int | find (const char *what, unsigned int offs=0) const |
| int | rfind (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) |
| String & | extractTo (const char *sep, String &store) |
| String & | extractTo (const char *sep, bool &store) |
| String & | extractTo (const char *sep, int &store, int base=0) |
| String & | extractTo (const char *sep, int &store, const TokenDict *tokens, int base=0) |
| String & | extractTo (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 |
| ObjList * | split (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 |
Static Public Member Functions | |
| static const String & | empty () |
| static const char * | boolText (bool value) |
| static int | lenUtf8 (const char *value, unsigned int maxSeq=4, bool overlong=false) |
| static unsigned int | hash (const char *value) |
| 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 | uriUnescape (const char *str, int *errptr=0) |
Protected Member Functions | |
| virtual void | changed () |
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.
| String | ( | ) |
Creates a new, empty string.
| String | ( | const char * | value, |
| int | len = -1 |
||
| ) |
Creates a new initialized string.
| value | Initial value of the string |
| len | Length of the data to copy, -1 for full string |
| String | ( | char | value, |
| unsigned int | repeat = 1 |
||
| ) | [explicit] |
Creates a new initialized string.
| value | Character to fill the string |
| repeat | How many copies of the character to use |
| String | ( | int | value | ) | [explicit] |
Creates a new initialized string from an integer.
| value | Value to convert to string |
| String | ( | unsigned int | value | ) | [explicit] |
Creates a new initialized string from an unsigned int.
| value | Value to convert to string |
| String | ( | bool | value | ) | [explicit] |
Creates a new initialized string from a boolean.
| value | Value to convert to string |
Constructor from String pointer.
| value | Initial value of the string |
| virtual ~String | ( | ) | [virtual] |
Destroys the string, disposes the memory.
Conditional appending with a separator
| value | String to append |
| separator | Separator to insert before the value |
| force | True to allow appending empty strings |
Referenced by ISDNQ931Message::append().
List members appending with a separator
| list | Pointer to ObjList whose GenObject::toString() of the items will be appended |
| separator | Separator to insert before each item in list |
| force | True to allow appending empty strings |
List members appending with a separator
| list | Reference of ObjList whose GenObject::toString() of the items will be appended |
| separator | Separator to insert before each item in list |
| force | True to allow appending empty strings |
References String::append().
Referenced by String::append().
Explicit double append
| value | Value to append |
| decimals | Number of decimals |
Assigns a new value to the string from a character block.
| value | New value of the string |
| len | Length of the data to copy, -1 for full string |
Referenced by SS7MsgSCCP::updateType().
Assigns a new value by filling with a repeated character
| value | Character to fill the string |
| repeat | How many copies of the character to use |
| char at | ( | int | index | ) | const |
Extract the caracter at a given index
| index | Index of character in string |
| static const char* boolText | ( | bool | value | ) | [inline, static] |
A standard text representation of boolean values
| value | Boolean value to convert |
Referenced by SDPMedia::rfc2833(), ClientContact::setLocal(), ClientContact::setRemote(), and ClientAccount::startup().
| const char* c_str | ( | ) | const [inline] |
Get the value of the stored string.
Referenced by ISDNQ931Message::appendIEValue(), IAXIEList::appendString(), SASL::buildAuthRspReply(), TelEngine::c_str(), ISDNQ931Message::getIEValue(), String::operator=(), TelEngine::strcat(), TelEngine::strcpy(), ClientResource::text(), MD5::update(), SHA1::update(), Compressor::writeComp(), Stream::writeData(), and Compressor::writeDecomp().
| virtual void changed | ( | ) | [protected, virtual] |
Called whenever the value changed (except in constructors).
Reimplemented in URI, NamedPointer, Regexp, and DataFormat.
| void clear | ( | ) |
Clear the string and free the memory
Reimplemented in SignallingCircuitRange, and JabberID.
Referenced by JabberID::clear().
A static null String
Reimplemented in NamedList, and JabberID.
Referenced by ClientContact::accountName(), StringArray::at(), ClientLogic::cdrRemoteParty(), XMPPUtils::createElement(), ClientContact::getContactSection(), SIPTransaction::getMethod(), SIPTransaction::getURI(), XMPPUtils::subject(), and XmlElementOut::toBuffer().
| bool endsWith | ( | const char * | what, |
| bool | wordBreak = false, |
||
| bool | caseInsensitive = false |
||
| ) | const |
Checks if the string ends with a substring
| what | Substring to search for |
| wordBreak | Check if a word boundary precedes the substring |
| caseInsensitive | Compare case-insensitive if set |
Extract a substring up to a separator
| sep | Separator string to match after extracted fragment |
| store | Reference to String variable to store extracted fragment |
Extract a boolean substring up to a separator
| sep | Separator string to match after extracted fragment |
| store | Reference to boolean variable to store extracted fragment |
Extract an integer value substring up to a separator
| sep | Separator string to match after extracted fragment |
| store | Reference to integer variable to store extracted fragment |
| base | Numeration base, 0 to autodetect |
Extract an integer or token value substring up to a separator
| sep | Separator string to match after extracted fragment |
| store | Reference to integer variable to store extracted fragment |
| tokens | Pointer to an array of tokens to lookup first |
| base | Numeration base, 0 to autodetect |
Extract a double value substring up to a separator
| sep | Separator string to match after extracted fragment |
| store | Reference to double variable to store extracted fragment |
| int find | ( | char | what, |
| unsigned int | offs = 0 |
||
| ) | const |
Locate the first instance of a character in the string
| what | Character to search for |
| offs | Offset in string to start searching from |
Referenced by ClientContact::splitContactId().
| int find | ( | const char * | what, |
| unsigned int | offs = 0 |
||
| ) | const |
Locate the first instance of a substring in the string
| what | Substring to search for |
| offs | Offset in string to start searching from |
| int fixUtf8 | ( | const char * | replace = 0, |
| unsigned int | maxSeq = 4, |
||
| bool | overlong = false |
||
| ) |
Fix an UTF-8 encoded string by replacing invalid sequences
| replace | String to replace invalid sequences, use U+FFFD if null |
| maxSeq | Maximum accepted UTF-8 sequence length |
| overlong | Accept overlong UTF-8 sequences (dangerous!) |
Get a pointer to a derived class given that class name
| name | Name of the class we are asking for |
Reimplemented from GenObject.
Reimplemented in NamedList, NamedPointer, NamedString, ExpWrapper, Message, MimeAuthLine, and MimeHeaderLine.
| unsigned int hash | ( | ) | const |
Get the hash of the contained string.
Referenced by HashList::getHashList().
| static unsigned int hash | ( | const char * | value | ) | [static] |
Get the hash of an arbitrary string.
| value | C string to hash |
Build a hexadecimal representation of a buffer of data
| data | Pointer to data to dump |
| len | Length of the data buffer |
| sep | Separator character to use between octets |
| upCase | Set to true to use upper case characters in hexa |
Referenced by OctetString::toHexString().
| bool isBoolean | ( | ) | const |
Check if the string can be converted to a boolean value.
Referenced by ExpOperation::ExpOperation().
| unsigned int length | ( | ) | const [inline] |
Get the length of the stored string.
Reimplemented in NamedList.
Referenced by IAXIEList::appendString(), SASL::buildAuthRspReply(), XmlElementOut::dataCount(), OctetString::fromHexString(), MD5::update(), SHA1::update(), Compressor::writeComp(), Stream::writeData(), and Compressor::writeDecomp().
| static int lenUtf8 | ( | const char * | value, |
| unsigned int | maxSeq = 4, |
||
| bool | overlong = false |
||
| ) | [static] |
Get the number of characters in a string assuming UTF-8 encoding
| value | C string to compute Unicode length |
| maxSeq | Maximum accepted UTF-8 sequence length |
| overlong | Accept overlong UTF-8 sequences (dangerous!) |
| int lenUtf8 | ( | unsigned int | maxSeq = 4, |
| bool | overlong = false |
||
| ) | const [inline] |
Get the number of characters in the string assuming UTF-8 encoding
| maxSeq | Maximum accepted UTF-8 sequence length |
| overlong | Accept overlong UTF-8 sequences (dangerous!) |
References String::lenUtf8().
Referenced by String::lenUtf8().
| int matchCount | ( | ) | const |
Get the total number of submatches from the last match, 0 if no match
Checks if matches a regular expression and fill the match substrings
| rexp | Regular expression to check for match |
| int matchLength | ( | int | index = 0 | ) | const |
Get the length of the last match
| index | Index of the submatch to return, 0 for full match |
| int matchOffset | ( | int | index = 0 | ) | const |
Get the offset of the last match
| index | Index of the submatch to return, 0 for full match |
| String matchString | ( | int | index = 0 | ) | const [inline] |
Get a copy of a matched (sub)string
| index | Index of the submatch to return, 0 for full match |
Create an escaped string suitable for use in messages
| str | String to convert to escaped format |
| extraEsc | Character to escape other than the default ones |
Create an escaped string suitable for use in messages
| extraEsc | Character to escape other than the default ones |
References TelEngine::c_str(), and String::msgEscape().
Referenced by String::msgEscape().
| static String msgUnescape | ( | const char * | str, |
| int * | errptr = 0, |
||
| char | extraEsc = 0 |
||
| ) | [static] |
Decode an escaped string back to its raw form
| str | String to convert to unescaped format |
| errptr | Pointer to an integer to receive the place of 1st error |
| extraEsc | Character to unescape other than the default ones |
| String msgUnescape | ( | int * | errptr = 0, |
| char | extraEsc = 0 |
||
| ) | const [inline] |
Decode an escaped string back to its raw form
| errptr | Pointer to an integer to receive the place of 1st error |
| extraEsc | Character to unescape other than the default ones |
References TelEngine::c_str(), and String::msgUnescape().
Referenced by String::msgUnescape().
| bool null | ( | ) | const [inline] |
Checks if the string holds a NULL pointer.
Referenced by JBServerStream::hasRemoteDomain(), JabberID::match(), and TelEngine::null().
| operator const char * | ( | ) | const [inline] |
Conversion to "const char *" operator.
| bool operator!= | ( | const char * | value | ) | const |
Inequality operator.
| bool operator&= | ( | const char * | value | ) | const |
Case-insensitive equality operator.
| String& operator+= | ( | const char * | value | ) |
Appending operator for strings.
| String& operator+= | ( | char | value | ) |
Appending operator for single characters.
| String& operator+= | ( | int | value | ) |
Appending operator for integers.
| String& operator+= | ( | unsigned int | value | ) |
Appending operator for unsigned integers.
| String& operator+= | ( | bool | value | ) | [inline] |
Appending operator for booleans.
References String::operator+=().
Referenced by String::operator+=().
| String& operator<< | ( | unsigned int | value | ) | [inline] |
Stream style appending operator for unsigned integers
Assignment operator.
Reimplemented in URI, JabberID, SIPDialog, and Configuration.
References String::c_str(), and String::operator=().
Referenced by ExpOperation::ExpOperation(), Configuration::operator=(), Message::operator=(), ExpOperation::operator=(), String::operator=(), Regexp::operator=(), NamedString::operator=(), and URI::operator=().
Assignment from String* operator.
Reimplemented in JabberID.
References String::c_str(), and String::operator=().
Referenced by String::operator=().
| String& operator= | ( | const char * | value | ) |
Assignment from char* operator.
Reimplemented in URI, NamedPointer, NamedString, Regexp, Message, and MimeHeaderLine.
| String& operator= | ( | char | value | ) |
Assignment operator for single characters.
| String& operator= | ( | int | value | ) |
Assignment operator for integers.
| String& operator= | ( | unsigned int | value | ) |
Assignment operator for unsigned integers.
| String& operator= | ( | bool | value | ) | [inline] |
Assignment operator for booleans.
References String::operator=().
Referenced by String::operator=().
| bool operator== | ( | const char * | value | ) | const |
Equality operator.
| String& operator>> | ( | const char * | skip | ) |
Stream style substring skipping operator. It eats all characters up to and including the skip string
| char operator[] | ( | signed int | index | ) | const [inline] |
Indexing operator with signed int
| index | Index of character in string |
| char operator[] | ( | unsigned int | index | ) | const [inline] |
Indexing operator with unsigned int
| index | Index of character in string |
| bool operator|= | ( | const char * | value | ) | const |
Case-insensitive inequality operator.
| String replaceMatches | ( | const String & | templ | ) | const |
Create a string by replacing matched strings in a template
| templ | Template of the string to generate |
| int rfind | ( | char | what | ) | const |
Locate the last instance of a character in the string
| what | Character to search for |
Referenced by AsnMib::getParent().
| const char* safe | ( | ) | const [inline] |
Get a valid non-NULL C string.
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.
| defStr | Default C string to return if stored is NULL |
Splits the string at a delimiter character
| separator | Character where to split the string |
| emptyOK | True if empty strings should be inserted in list |
Create an escaped string suitable for use in SQL queries
| str | String to convert to escaped format |
| extraEsc | Character to escape other than the default ones |
Create an escaped string suitable for use in SQL queries
| extraEsc | Character to escape other than the default ones |
References TelEngine::c_str(), and String::sqlEscape().
Referenced by String::sqlEscape().
| bool startSkip | ( | const char * | what, |
| bool | wordBreak = true, |
||
| bool | caseInsensitive = false |
||
| ) |
Checks if the string starts with a substring and removes it
| what | Substring to search for |
| wordBreak | Check 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 |
| caseInsensitive | Compare case-insensitive if set |
Referenced by ClientContact::getContactSection().
| bool startsWith | ( | const char * | what, |
| bool | wordBreak = false, |
||
| bool | caseInsensitive = false |
||
| ) | const |
Checks if the string starts with a substring
| what | Substring to search for |
| wordBreak | Check if a word boundary follows the substring |
| caseInsensitive | Compare case-insensitive if set |
Referenced by XmlElement::isXmlns().
Substring extraction
| offs | Offset of the substring, negative to count from end |
| len | Length of the substring, -1 for everything possible |
Referenced by ClientContact::splitContactId().
| bool toBoolean | ( | bool | defvalue = false | ) | const |
Convert the string to a boolean value.
| defvalue | Default to return if the string is not a bool |
Referenced by ExpOperation::ExpOperation().
| double toDouble | ( | double | defvalue = 0.0 | ) | const |
Convert the string to a floating point value.
| defvalue | Default to return if the string is not a number |
| 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.
| defvalue | Default to return if the string is not a number |
| base | Numeration base, 0 to autodetect |
| minvalue | Minimum value allowed |
| maxvalue | Maximum value allowed |
| clamp | Control the out of bound values: true to adjust to the nearest bound, false to return the default value |
Convert the string to an integer value looking up first a token table.
| tokens | Pointer to an array of tokens to lookup first |
| defvalue | Default to return if the string is not a token or number |
| base | Numeration base, 0 to autodetect |
| 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.
| defvalue | Default to return if the string is not a number |
| base | Numeration base, 0 to autodetect |
| minvalue | Minimum value allowed |
| maxvalue | Maximum value allowed |
| clamp | Control the out of bound values: true to adjust to the nearest bound, false to return the default value |
Turn the string to an all-lowercase string
Referenced by ClientContact::buildContactId(), and JBStream::buildSha1Digest().
Override GenObject's method to return this String
Reimplemented from GenObject.
Reimplemented in NamedString.
Referenced by ClientContact::accountName().
| String& trimBlanks | ( | ) |
Strip off leading and trailing blank characters
| String& trimSpaces | ( | ) |
Strip off leading and trailing whitespace characters (blank, tabs, form-feed, newlines)
Create an escaped string suitable for use in URIs
| str | String to convert to escaped format |
| extraEsc | Character to escape other than the default ones |
| noEsc | Optional pointer to string of characters that shouldn't be escaped |
Referenced by ClientContact::buildContactId(), and ClientContact::buildInstanceId().
Create an escaped string suitable for use in URI
| extraEsc | Character to escape other than the default ones |
| noEsc | Optional pointer to string of characters that shouldn't be escaped |
References TelEngine::c_str(), and String::uriEscape().
Referenced by String::uriEscape().
| static String uriUnescape | ( | const char * | str, |
| int * | errptr = 0 |
||
| ) | [static] |
Decode an URI escaped string back to its raw form
| str | String to convert to unescaped format |
| errptr | Pointer to an integer to receive the place of 1st error |
Referenced by ClientContact::getContactSection(), and ClientContact::splitContactId().
| String uriUnescape | ( | int * | errptr = 0 | ) | const [inline] |
Decode an URI escaped string back to its raw form
| errptr | Pointer to an integer to receive the place of 1st error |
References TelEngine::c_str(), and String::uriUnescape().
Referenced by String::uriUnescape().
1.7.6.1