#include <string.h>
Enums and Constants | |
enum | CompareMode { CASE_SENSITIVE = 0, CASE_INSENSITIVE = 1 } |
Constants to set the compare mode. More... | |
const Size | EndPos |
Constant indicating the end of the string. | |
String Operations | |
String | operator+ (const string &string) const throw () |
Concatenates two strings. | |
String | operator+ (const char *char_ptr) const throw () |
Concatenates a string and a C type string. | |
String | operator+ (char c) const throw () |
Concatenates a string and a character. | |
void | swap (String &s) throw () |
Swaps the contents with another String. | |
String & | reverse (Index from=0, Size len=EndPos) throw (Exception::IndexUnderflow, Exception::IndexOverflow) |
Reverses the string. | |
Size | substitute (const String &to_replace, const String &replacing) throw () |
Substitute the first occurence of to_replace by the content of replacing. | |
BALL_EXPORT friend String | operator+ (const char *char_ptr, const String &s) throw () |
Concatenates a C type string and a string. | |
BALL_EXPORT friend String | operator+ (char c, const String &s) throw () |
Concatenates a character and a string. | |
Predicates | |
bool | has (char c) const throw () |
True, if the string contains character c. | |
bool | hasSubstring (const String &s, Index from=0) const throw () |
True, if the string contains the substring s after index from. | |
bool | hasPrefix (const String &s) const throw () |
True, if the string starts with s. | |
bool | hasSuffix (const String &s) const throw () |
True, if the string ends with s. | |
bool | isEmpty () const throw () |
True, if the string has size 0. | |
bool | isAlpha () const throw () |
True, if the string only contains letters (any case). | |
bool | isAlnum () const throw () |
True, if the string only contains letters and digits. | |
bool | isDigit () const throw () |
True, if the string only contains digits. | |
bool | isFloat () const throw () |
True, if the string is a floating number. | |
bool | isSpace () const throw () |
True, if the string only contains spaces. | |
bool | isWhitespace () const throw () |
True, if the string only contains whitespace characters. | |
bool | isAlpha (char c) throw () |
True, if the character is a letter (any case). | |
bool | isAlnum (char c) throw () |
True, if the character is a letter or a digit. | |
bool | isDigit (char c) throw () |
True, if the character is a digit. | |
bool | isSpace (char c) throw () |
True, if the character is a space. | |
bool | isWhitespace (char c) throw () |
True, if the character is any whitespace character. | |
Comparators | |
int | compare (const String &string, Index from=0) const throw (Exception::IndexUnderflow, Exception::IndexOverflow) |
int | compare (const String &string, Index from, Size len) const throw (Exception::IndexUnderflow, Exception::IndexOverflow) |
int | compare (const char *char_ptr, Index from=0) const throw (Exception::NullPointer, Exception::IndexUnderflow, Exception::IndexOverflow) |
int | compare (const char *char_ptr, Index from, Size len) const throw (Exception::NullPointer, Exception::IndexUnderflow, Exception::IndexOverflow) |
int | compare (char c, Index from=0) const throw (Exception::IndexUnderflow, Exception::IndexOverflow) |
bool | operator== (const String &string) const throw () |
bool | operator!= (const String &string) const throw () |
bool | operator< (const String &string) const throw () |
bool | operator<= (const String &string) const throw () |
bool | operator>= (const String &string) const throw () |
bool | operator> (const String &string) const throw () |
bool | operator== (const char *char_ptr) const throw (Exception::NullPointer) |
bool | operator!= (const char *char_ptr) const throw (Exception::NullPointer) |
bool | operator< (const char *char_ptr) const throw (Exception::NullPointer) |
bool | operator<= (const char *char_ptr) const throw (Exception::NullPointer) |
bool | operator> (const char *char_ptr) const throw (Exception::NullPointer) |
bool | operator>= (const char *char_ptr) const throw (Exception::NullPointer) |
bool | operator== (char c) const throw () |
bool | operator!= (char c) const throw () |
bool | operator< (char c) const throw () |
bool | operator<= (char c) const throw () |
bool | operator> (char c) const throw () |
bool | operator>= (char c) const throw () |
BALL_EXPORT friend bool | operator== (const char *char_ptr, const String &string) throw (Exception::NullPointer) |
BALL_EXPORT friend bool | operator!= (const char *char_ptr, const String &string) throw (Exception::NullPointer) |
BALL_EXPORT friend bool | operator< (const char *char_ptr, const String &string) throw (Exception::NullPointer) |
BALL_EXPORT friend bool | operator<= (const char *char_ptr, const String &string) throw (Exception::NullPointer) |
BALL_EXPORT friend bool | operator> (const char *char_ptr, const String &string) throw (Exception::NullPointer) |
BALL_EXPORT friend bool | operator>= (const char *char_ptr, const String &string) throw (Exception::NullPointer) |
BALL_EXPORT friend bool | operator== (char c, const String &string) throw () |
BALL_EXPORT friend bool | operator!= (char c, const String &string) throw () |
BALL_EXPORT friend bool | operator< (char c, const String &string) throw () |
BALL_EXPORT friend bool | operator<= (char c, const String &string) throw () |
BALL_EXPORT friend bool | operator> (char c, const String &string) throw () |
bool | operator>= (char c, const String &string) throw () |
Stream Operations | |
std::istream & | getline (std::istream &s=std::cin, char delimiter= '\n') throw () |
std::istream & | getline (std::istream &s, String &string, char delimiter= '\n') throw () |
Public Member Functions | |
virtual void * | create (bool=true, bool empty=false) const throw () |
Constructors and Destructors | |
String () throw () | |
Default Constructor. | |
String (const String &string) throw () | |
Copy constructor. | |
String (const string &string) throw () | |
STL string copy constructor. | |
String (const String &s, Index from, Size len=EndPos) throw (Exception::IndexUnderflow, Exception::IndexOverflow) | |
Creates a new string from a given range of another string. | |
String (const char *char_ptr, Index from=0, Size len=EndPos) throw (Exception::NullPointer, Exception::IndexUnderflow, Exception::IndexOverflow) | |
Creates a new string from a C type string. | |
String (Size buffer_size, const char *format,...) throw (Exception::IndexUnderflow, Exception::NullPointer) | |
Creates a string using sprintf. | |
String (std::strstream &s) throw () | |
Create a new string from the contents of a stringstream. | |
String (const char c, Size len=1) throw () | |
Creates a new string from len copies of c. | |
String (const unsigned char uc) throw () | |
Creates a string just containing an unsigned character. | |
String (short s) throw () | |
Construct a String from a short. | |
String (unsigned short us) throw () | |
Construct a String from an unsigned short. | |
String (int i) throw () | |
Construct a String from an int. | |
String (unsigned int ui) throw () | |
Construct a String from an unsigned int. | |
String (long l) throw () | |
Construct a String from a long. | |
String (unsigned long) throw () | |
Construct a String from an unsigned long. | |
String (float f) throw () | |
Construct a String from a float value. | |
String (double d) throw () | |
Construct a String from a double value. | |
virtual | ~String () throw () |
Destructor. | |
void | destroy () throw () |
Clear the string (reset to the empty string). | |
virtual void | clear () throw () |
Clears the string (same as destroy). | |
Assignment methods | |
void | set (const String &s) |
Assign a string. | |
void | set (const String &string, Index from, Size len=EndPos) throw (Exception::IndexUnderflow, Exception::IndexOverflow) |
Assign a String from a range of another string. | |
void | set (const char *char_ptr, Index from=0, Size len=EndPos) throw (Exception::NullPointer, Exception::IndexUnderflow, Exception::IndexOverflow) |
Assign a String from a C type string. | |
void | set (Size buffer_size, const char *format,...) throw (Exception::IndexUnderflow, Exception::NullPointer) |
Assign a string to the result of a sprintf call. | |
void | set (std::strstream &s) throw () |
Assign a String from a stringstream. | |
void | set (char c, Size len=1) throw () |
Assign a String from the result of repeating c len times. | |
void | set (unsigned char uc) throw () |
Assign a String from an unsigned char. | |
void | set (short s) throw () |
Assign a String from a short. | |
void | set (unsigned short us) throw () |
Assign a String from an unsigned short. | |
void | set (int i) throw () |
Assign a String from an int. | |
void | set (unsigned int ui) throw () |
Assign a String from an unsigned int. | |
void | set (long l) throw () |
Assign a String from a long. | |
void | set (unsigned long ul) throw () |
Assign a String from an unsigned long. | |
void | set (float f) throw () |
Assign a String from a float value. | |
void | set (double d) throw () |
Assign a String from a double value. | |
void | get (char *char_ptr, Index from=0, Size len=EndPos) const throw (Exception::NullPointer, Exception::IndexUnderflow, Exception::IndexOverflow) |
Assign to a C type string. | |
const String & | operator= (const String &s) throw () |
Assign a String from another String. | |
const String & | operator= (const char *pc) throw (Exception::NullPointer) |
Assign a String from a C type string. | |
const String & | operator= (std::strstream &s) throw () |
Assign a string from a stringstream. | |
const String & | operator= (char c) throw () |
Assign a String from a single char. | |
const String & | operator= (unsigned char uc) throw () |
Assign a String from an unsigned char. | |
const String & | operator= (short s) throw () |
Assign a String from a short. | |
const String & | operator= (unsigned short us) throw () |
Assign a String from an unsigned short. | |
const String & | operator= (int i) throw () |
Assign a String from an int. | |
const String & | operator= (unsigned int ui) throw () |
Assign a String from an unsigned int. | |
const String & | operator= (long l) throw () |
Assign a String from a long. | |
const String & | operator= (unsigned long ul) throw () |
Assign a String from an unsigned long. | |
const String & | operator= (float f) throw () |
Assign a String from a float. | |
const String & | operator= (double d) throw () |
Assign a String from a double. | |
Converters | |
bool | toBool () const throw () |
Converts the string to a bool value. | |
char | toChar () const throw () |
Return the first character of the string. | |
unsigned char | toUnsignedChar () const throw () |
Return the first character of the string converted to an unsigned char. | |
short | toShort () const throw (Exception::InvalidFormat) |
Convert the string to a short. | |
unsigned short | toUnsignedShort () const throw (Exception::InvalidFormat) |
Convert the string to an unsigned short. | |
int | toInt () const throw (Exception::InvalidFormat) |
Convert the string to an int. | |
unsigned int | toUnsignedInt () const throw (Exception::InvalidFormat) |
Convert the string to an unsigned int. | |
long | toLong () const throw (Exception::InvalidFormat) |
Convert the string to a long. | |
unsigned long | toUnsignedLong () const throw (Exception::InvalidFormat) |
Convert the string to an unsigned long. | |
float | toFloat () const throw (Exception::InvalidFormat) |
Convert the string to a float. | |
double | toDouble () const throw (Exception::InvalidFormat) |
Convert the string to a double. | |
Case Conversion | |
void | toLower (Index from=0, Size len=EndPos) throw (Exception::IndexUnderflow, Exception::IndexOverflow) |
Convert all characters in the given range to lower case. | |
void | toUpper (Index from=0, Size len=EndPos) throw (Exception::IndexUnderflow, Exception::IndexOverflow) |
Convert all characters in the given range to upper case. | |
Substring Definition | |
Substring | getSubstring (Index from=0, Size len=EndPos) const throw (Exception::IndexUnderflow, Exception::IndexOverflow) |
Return a substring. | |
Substring | operator() (Index from, Size len=EndPos) const throw (Exception::IndexUnderflow, Exception::IndexOverflow) |
Return a substring. | |
Substring | before (const String &s, Index from=0) const throw () |
Return a substring containing the string before the first occurence of s. | |
Substring | through (const String &s, Index from=0) const throw () |
Return a substring containing the beginning of the string including the first occurence of s. | |
Substring | from (const String &s, Index from=0) const throw () |
Return a substring containing the string from the first occurence of s on. | |
Substring | after (const String &s, Index from=0) const throw () |
Return a substring containing the string after the first occurence of s. | |
AWK style field operations | |
Size | countFields (const char *delimiters=CHARACTER_CLASS__WHITESPACE) const throw (Exception::NullPointer) |
Count the fields that are separated by a defined set of delimiters. | |
Size | countFieldsQuoted (const char *delimiters=CHARACTER_CLASS__WHITESPACE, const char *quotes=CHARACTER_CLASS__QUOTES) const throw (Exception::NullPointer) |
Count the fields and respect quote characters. | |
String | getField (Index index, const char *delimiters=CHARACTER_CLASS__WHITESPACE, Index *from=0) const throw (Exception::IndexUnderflow, Exception::NullPointer) |
Return a given field as a substring. | |
String | getFieldQuoted (Index index, const char *delimiters=CHARACTER_CLASS__WHITESPACE, const char *quotes=CHARACTER_CLASS__QUOTES, Index *from=0) const throw (Exception::IndexUnderflow, Exception::NullPointer) |
Return a given field and respect quote characters. | |
Size | split (String string_array[], Size array_size, const char *delimiters=CHARACTER_CLASS__WHITESPACE, Index from=0) const throw (Exception::IndexUnderflow, Exception::NullPointer) |
Split the string into fields and assign these field to an array of strings. | |
Size | split (std::vector< String > &strings, const char *delimiters=CHARACTER_CLASS__WHITESPACE, Index from=0) const throw (Exception::IndexUnderflow, Exception::NullPointer) |
Split the string into fields and assign these field to a vector of strings. | |
Size | splitQuoted (std::vector< String > &strings, const char *delimiters=CHARACTER_CLASS__WHITESPACE, const char *quotes=CHARACTER_CLASS__QUOTES, Index from=0) const throw (Exception::IndexUnderflow, Exception::NullPointer) |
Split the string into fields and respect quote characters. | |
BASIC style string operations | |
String & | trimLeft (const char *trimmed=CHARACTER_CLASS__WHITESPACE) throw () |
Strips all characters in trimmed from the left of the string. | |
String & | trimRight (const char *trimmed=CHARACTER_CLASS__WHITESPACE) throw () |
Strips all characters in trimmed from the right of the string. | |
String & | trim (const char *trimmed=CHARACTER_CLASS__WHITESPACE) throw () |
Strips all characters in trimmed from both sides of the string. | |
String | trim (const char *trimmed=CHARACTER_CLASS__WHITESPACE) const throw () |
Strips all characters in trimmed from both sides of the string. | |
String & | truncate (Size size) throw () |
Truncate the string to length size. | |
Substring | left (Size len) const throw () |
Return a substring containing the len leftmost characters of the string. | |
Substring | right (Size len) const throw () |
Return a substring containing the len rightmost characters of the string. | |
Substring | instr (const String &pattern, Index from=0) const throw () |
Return a substring containing the first occurence of pattern in the string. | |
Base64 String methods | |
String | encodeBase64 () throw () |
Convert a string to a base 64 string. | |
String | decodeBase64 () throw () |
Decode a base 64 string. | |
Debugging and Diagnostics | |
bool | isValid () const throw () |
void | dump (std::ostream &s=std::cout, Size depth=0) const throw () |
Static Public Member Functions | |
Compare mode-related methods. | |
All string comparisons can be made case-sensitive or case insensitive.
The behavior can be toggled globally for all strings. | |
void | setCompareMode (CompareMode compare_mode) throw () |
Set the compareison mode for all string comparisons. | |
CompareMode | getCompareMode () throw () |
Return the current comparison mode. | |
Static Public Attributes | |
const String | EMPTY |
Constant empty string. | |
Predefined character classes | |
There exist several predefined character classes, that may be used in several functions (e.g.
trim methods) to represent a set of characters. | |
const char * | CHARACTER_CLASS__ASCII_ALPHA |
Character class containing all letters (lower and upper case). | |
const char * | CHARACTER_CLASS__ASCII_ALPHANUMERIC |
Character class containing all letters and digits. | |
const char * | CHARACTER_CLASS__ASCII_LOWER |
Character class containing all lower case letters. | |
const char * | CHARACTER_CLASS__ASCII_UPPER |
Character class containing all upper case letters. | |
const char * | CHARACTER_CLASS__ASCII_NUMERIC |
Character class containing the digits from 0 to 9. | |
const char * | CHARACTER_CLASS__ASCII_FLOAT |
Character class containing the digits from 0 to 9 and a dot. | |
const char * | CHARACTER_CLASS__WHITESPACE |
Character class containing all whitespace characters. | |
const char * | CHARACTER_CLASS__QUOTES |
Character class containing double quotes. | |
Protected Member Functions | |
void | validateIndex_ (Index &index) const throw (Exception::IndexUnderflow, Exception::IndexOverflow) |
void | validateRange_ (Index &from, Size &len) const throw (Exception::IndexUnderflow, Exception::IndexOverflow) |
Static Protected Member Functions | |
void | validateCharPtrRange_ (Index &from, Size &len, const char *char_ptr) throw (Exception::NullPointer, Exception::IndexUnderflow, Exception::IndexOverflow) |
void | valudateCharPtrIndex_ (Index &index) throw () |
Friends | |
class | Substring |
|
Constants to set the compare mode. Use one of these constants to set the mode you need. These modes affect all compare methods. As these methods are also used in the implementation of comparison operators, all comparison operations will get affected from a change.
|
|
Creates a new string from a given range of another string.
|
|
Creates a new string from a C type string. The new string contains the contents of s until it has reached a length of len or contains a zero character (whichever comes first). Default value for len is EndPos, meaning as long as possible. |
|
Creates a string using sprintf. This constructor creates a new string and sets its content to the result of a call to sprintf using format as a format string and all additional parameters as arguments.
|
|
Create a new string from the contents of a stringstream.
The contents of the |
|
Creates a new string from len copies of c.
|
|
Return a substring containing the string after the first occurence of s.
|
|
Decode a base 64 string. Return an empty string, if base64 string is not right encoded. |
|
Return a substring containing the first occurence of pattern in the string. If the pattern is not contained in the string, an empty Substring is returned. The search for the pattern may also start from an index different from zero, allowing incremental search.
|
|
True, if the string only contains letters and digits. It returns also true, if called for an empty string. |
|
True, if the string only contains letters (any case). It returns also true, if called for an empty string. |
|
True, if the string only contains digits. It returns also true, if called for an empty string. |
|
True, if the string is a floating number. (It contains only numbers and maybe a dot). It returns also true, if called for an empty string. |
|
True, if the string only contains spaces. It returns also true, if called for an empty string. |
|
True, if the character is any whitespace character. Whitespaces are defined in CHARACTER_CLASS__WHITESPACE |
|
True, if the string only contains whitespace characters. Whitespaces are defined in CHARACTER_CLASS__WHITESPACE. It returns also true, if called for an empty string. |
|
Assign a string from a stringstream.
The contents of the |
|
Reverses the string. If called without arguments, this method simply reverses the character sequence of the string. By giving arguments for the indices, only a subsequence of the string may be reversed.
|
|
Assign a String from a stringstream.
The contents of the |
|
Assign a string to the result of a sprintf call.
|
|
Assign a String from a C type string.
|
|
Assign a String from a range of another string.
|
|
Split the string into fields and assign these field to a vector of strings. The vector of strings is cleared in any case. Its final size is returned.
|
|
Split the string into fields and respect quote characters. Similar to split , but delimiters that are inside quote characters (default is CHARACTER_CLASS__QUOTES ) are not considered to split the string. The vector of strings is cleared in any case. Its final size is returned.
|
|
Substitute the first occurence of to_replace by the content of replacing.
|
|
Converts the string to a bool value.
This method returns false, if the string contains the string |
|
Strips all characters in trimmed from both sides of the string.
trim calls |
|
Strips all characters in trimmed from both sides of the string.
trim calls |
|
Strips all characters in trimmed from the left of the string.
trimLeft stops at the first character encountered that is not in trimmed. Using its default parameter CHARACTER_CLASS__WHITESPACE, it is usually handy to remove blanks from the beginning of a string. Strings consisting of character from |
|
Strips all characters in trimmed from the right of the string.
trimRight stops at the first character encountered that is not in trimmed. Using its default parameter CHARACTER_CLASS__WHITESPACE, it is usually handy to remove blanks from the end of a string. Strings consisting of character from |
|
Character class containing double quotes.
|
|
Character class containing all whitespace characters. Whitespace characters are:
|
|
Constant indicating the end of the string.
Use this constant instead of |