class String

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

Full nameTelEngine::String
Definition#include <yateclass.h>
InheritsTelEngine::GenObject [public ]
Inherited byConfiguration, DataFormat, Message, MessageHandler, MessageRelay, NamedList, NamedString, Regexp, UIFactory, URI
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

Public Methods

Public Static Methods

Protected Methods


Detailed Description

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 ()

String

Creates a new, empty string.

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

String

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)

String

Creates a new initialized string.

Parameters:
valueCharacter to fill the string
repeatHow many copies of the character to use

 String (int value)

String

Creates a new initialized string from an integer.

Parameters:
valueValue to convert to string

 String (unsigned int value)

String

Creates a new initialized string from an unsigned int.

Parameters:
valueValue to convert to string

 String (bool value)

String

Creates a new initialized string from a boolean.

Parameters:
valueValue to convert to string

 String (const String& value)

String

Copy constructor.

Parameters:
valueInitial value of the string

 String (const String* value)

String

Constructor from String pointer.

Parameters:
valueInitial value of the string

 ~String ()

~String

[virtual]

Destroys the string, disposes the memory.

void*  getObject (const String& name)

getObject

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

const String&  empty ()

empty

[static]

A static null String

inline const char*  boolText (bool value)

boolText

[static]

A standard text representation of boolean values

Parameters:
valueBoolean value to convert

Returns: Pointer to a text representation of the value

inline const char*  c_str ()

c_str

[const]

Get the value of the stored string.

Returns: The stored C string which may be NULL.

inline const char*  safe ()

safe

[const]

Get a valid non-NULL C string.

Returns: The stored C string or a static "".

inline unsigned int  length ()

length

[const]

Get the length of the stored string.

Returns: The length of the stored string, zero for NULL.

inline bool  null ()

null

[const]

Checks if the string holds a NULL pointer.

Returns: True if the string holds NULL, false otherwise.

unsigned int  hash ()

hash

[const]

Get the hash of the contained string.

Returns: The hash of the string.

unsigned int  hash (const char* value)

hash

[static]

Get the hash of an arbitrary string.

Returns: The hash of the string.

void  clear ()

clear

Clear the string and free the memory

char  at (int index)

at

[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

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

substr

[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

String&  trimBlanks ()

trimBlanks

Strip off leading and trailing blank characters

const String&  toString ()

toString

[const virtual]

Override GenObject's method to return this String

Returns: A reference to this String

Reimplemented from GenObject.

int  toInteger (int defvalue = 0, int base = 0)

toInteger

[const]

Convert the string to an integer value.

Parameters:
defvalueDefault to return if the string is not a number
baseNumeration base, 0 to autodetect

Returns: The integer interpretation or defvalue.

int  toInteger (const TokenDict* tokens, int defvalue = 0, int base = 0)

toInteger

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

double  toDouble (double defvalue = 0.0)

toDouble

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

bool  toBoolean (bool defvalue = false)

toBoolean

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

bool  isBoolean ()

isBoolean

[const]

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

Returns: True if the string is a valid boolean.

String&  toUpper ()

toUpper

Turn the string to an all-uppercase string

Returns: A reference to this String

String&  toLower ()

toLower

Turn the string to an all-lowercase string

Returns: A reference to this String

inline char  operator[] (int index)

operator[]

[const]

Indexing operator

Parameters:
indexIndex of character in string

Returns: Character at given index or 0 if out of range

inline  operator const char* ()

operator const char*

[const]

Conversion to "const char *" operator.

Returns: Pointer to the internally stored string

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

assign

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)

assign

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

String&  hexify (void* data, unsigned int len, char sep = 0, bool upCase = false)

hexify

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

inline String&  operator= (const String& value)

operator=

Assignment operator.

inline String&  operator= (const String* value)

operator=

Assignment from String* operator.

See also: strcpy

String&  operator= (const char* value)

operator=

Assignment from char* operator.

See also: strcpy

String&  operator= (char value)

operator=

Assignment operator for single characters.

String&  operator= (int value)

operator=

Assignment operator for integers.

String&  operator= (unsigned int value)

operator=

Assignment operator for unsigned integers.

inline String&  operator= (bool value)

operator=

Assignment operator for booleans.

String&  operator+= (const char* value)

operator+=

Appending operator for strings.

See also: strcat

String&  operator+= (char value)

operator+=

Appending operator for single characters.

String&  operator+= (int value)

operator+=

Appending operator for integers.

String&  operator+= (unsigned int value)

operator+=

Appending operator for unsigned integers.

inline String&  operator+= (bool value)

operator+=

Appending operator for booleans.

bool  operator== (const char* value)

operator==

[const]

Equality operator.

bool  operator!= (const char* value)

operator!=

[const]

Inequality operator.

bool  operator== (const String& value)

operator==

[const]

Fast equality operator.

bool  operator!= (const String& value)

operator!=

[const]

Fast inequality operator.

bool  operator&= (const char* value)

operator&=

[const]

Case-insensitive equality operator.

bool  operator|= (const char* value)

operator|=

[const]

Case-insensitive inequality operator.

inline String&  operator<< (const char* value)

operator<<

Stream style appending operator for C strings

inline String&  operator<< (char value)

operator<<

Stream style appending operator for single characters

inline String&  operator<< (int value)

operator<<

Stream style appending operator for integers

inline String&  operator<< (unsigned int value)

operator<<

Stream style appending operator for unsigned integers

inline String&  operator<< (bool value)

operator<<

Stream style appending operator for booleans

String&  operator>> (const char* skip)

operator>>

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

String&  operator>> (char& store)

operator>>

Stream style extraction operator for single characters

String&  operator>> (int& store)

operator>>

Stream style extraction operator for integers

String&  operator>> (unsigned int& store)

operator>>

Stream style extraction operator for unsigned integers

String&  operator>> (bool& store)

operator>>

Stream style extraction operator for booleans

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

append

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)

append

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

inline String&  append (const ObjList& list, const char* separator = 0, bool force = false)

append

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

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

append

Explicit double append

Parameters:
valueValue to append
decimalsNumber of decimals

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

find

[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

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

find

[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  rfind (char what)

rfind

[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

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

startsWith

[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

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

endsWith

[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

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

startSkip

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

bool  matches (const String& value)

matches

[const virtual]

Checks if matches another string

Parameters:
valueString to check for match

Returns: True if matches, false otherwise

bool  matches (Regexp& rexp)

matches

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  matchOffset (int index = 0)

matchOffset

[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

int  matchLength (int index = 0)

matchLength

[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

inline String  matchString (int index = 0)

matchString

[const]

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

String  replaceMatches (const String& templ)

replaceMatches

[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  matchCount ()

matchCount

[const]

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

Returns: Number of matching subexpressions

ObjList*  split (char separator, bool emptyOK = true)

split

[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

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

msgEscape

[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

inline String  msgEscape (char extraEsc = 0)

msgEscape

[const]

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

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

msgUnescape

[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

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

msgUnescape

[const]

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

String  sqlEscape (const char* str, char extraEsc = 0)

sqlEscape

[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

inline String  sqlEscape (char extraEsc = 0)

sqlEscape

[const]

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

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

uriEscape

[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

Returns: The string with special characters escaped

inline String  uriEscape (char extraEsc = 0)

uriEscape

[const]

Create an escaped string suitable for use in URI

Parameters:
extraEscCharacter to escape other than the default ones

Returns: The string with special characters escaped

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

uriUnescape

[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

inline String  uriUnescape (int* errptr = 0)

uriUnescape

[const]

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

void  changed ()

changed

[protected virtual]

Called whenever the value changed (except in constructors).


Generated by: root on dragoshel on Fri Aug 24 11:49:48 2007, using kdoc 2.0a54.