|
|
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:
value | Initial value of the string |
len | Length of the data to copy, -1 for full string |
String (char value, unsigned int repeat = 1)
| String |
Creates a new initialized string.
Parameters:
value | Character to fill the string |
repeat | How many copies of the character to use |
String (int value)
| String |
Creates a new initialized string from an integer.
Parameters:
value | Value to convert to string |
String (unsigned int value)
| String |
Creates a new initialized string from an unsigned int.
Parameters:
value | Value to convert to string |
String (bool value)
| String |
Creates a new initialized string from a boolean.
Parameters:
value | Value to convert to string |
String (const String &value)
| String |
Copy constructor.
Parameters:
value | Initial value of the string |
String (const String *value)
| String |
Constructor from String pointer.
Parameters:
value | Initial value of the string |
~String ()
| ~String |
[virtual]
Destroys the string, disposes the memory.
const String & empty ()
| empty |
[static]
A static null String
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 "".
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:
index | Index 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:
offs | Offset of the substring, negative to count from end |
len | Length 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:
defvalue | Default to return if the string is not a number |
base | Numeration 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:
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 |
Returns: The integer interpretation or defvalue.
bool toBoolean (bool defvalue = false)
| toBoolean |
[const]
Convert the string to a boolean value.
Parameters:
defvalue | Default to return if the string is not a bool |
Returns: The boolean interpretation or defvalue.
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:
index | Index 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.
String& assign (const char *value, int len = -1)
| assign |
Assigns a new value to the string from a character block.
Parameters:
value | New value of the string |
len | Length of the data to copy, -1 for full 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
int find (char what, unsigned int offs = 0)
| find |
[const]
Locate the first instance of a character in the string
Parameters:
what | Character to search for |
offs | Offset 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:
what | Substring to search for |
offs | Offset 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:
what | Character to search for |
Returns: Offset of character or -1 if not found
bool startsWith (const char *what, bool wordBreak = false)
| startsWith |
[const]
Checks if the string starts with a substring
Parameters:
what | Substring to search for |
wordBreak | Check if a word boundary follows the substring |
Returns: True if the substring occurs at the beginning of the string
bool endsWith (const char *what, bool wordBreak = false)
| endsWith |
[const]
Checks if the string ends with a substring
Parameters:
what | Substring to search for |
wordBreak | Check if a word boundary precedes the substring |
Returns: True if the substring occurs at the end of the string
bool startSkip (const char *what, bool wordBreak = true)
| startSkip |
Checks if the string starts with a substring and removes it
Parameters:
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 |
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:
value | String 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:
rexp | Regular 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:
index | Index 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:
index | Index 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:
index | Index 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:
templ | Template 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:
separator | Character where to split the string |
emptyOK | True 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:
str | String to convert to escaped format |
extraEsc | Character 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:
extraEsc | Character 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:
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 |
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:
errptr | Pointer to an integer to receive the place of 1st error |
extraEsc | Character to unescape other than the default ones |
Returns: The string with special characters unescaped
void changed ()
| changed |
[protected virtual]
Called whenever the value changed (except in constructors).
Generated by: kk on nyx on Sat Jun 4 19:29:41 2005, using kdoc 2.0a54. |