BasicString< T > Class Template Reference

A flexible, reference counted, copy-on-write, thread-safe, nullable string. More...

#include <BasicString.h++>

Inheritance diagram for BasicString< T >:

Inheritance graph
[legend]
Collaboration diagram for BasicString< T >:

Collaboration graph
[legend]

List of all members.

Classes

class  StringBuf

Public Member Functions

 BasicString ()
 Construct a new, empty string.
 BasicString (T *str, size_t offset=0, size_t length=0, bool copy=true)
 Construct a new string from a C string.
 BasicString (const BasicString< T > &other)
 Copy constructor.
 BasicString (const T *other, size_t offset=0, size_t length=0)
 Construct a new string from a C string.
 BasicString (const byte_t *data, size_t length, const char *encoding)
 Construct a new string from a byte array.
virtual ~BasicString () throw ()
 Destructor.
bool endsWith (const BasicString< T > &str, bool ignoreCase=false) const throw ()
 Test if the string ends with the given string.
bool endsWith (T c, bool ignoreCase=false) const throw ()
 Test if the string ends with the given character.
bool endsWithAnyOf (const T *chars, bool ignoreCase=false) const throw ()
 Test if the string ends with any character in a given set of characters.
bool startsWith (const BasicString< T > &str, bool ignoreCase=false) const throw ()
 Test if the string starts with the given string.
bool startsWith (T c, bool ignoreCase=false) const throw ()
 Test if the string starts with the given character.
bool startsWithAnyOf (const T *chars, bool ignoreCase=false) const throw ()
 Test if the string starts with any character in a given set of characters.
size_t getLength () const throw ()
 Get the length of the string.
size_t length () const throw ()
 Get the length of the string.
void setLength (uint_t length)
 Set the length of the string.
void reserve (uint_t capacity)
 Reserve space in the string for the given number of characters.
size_t getCapacity () const throw ()
 Get the current capacity of the string, in characters.
void compact ()
 Compact the string so that it occupies the minimum amount of memory required.
BasicString< T > & clear ()
 Clear the string.
bool isEmpty () const throw ()
 Test if the string is empty.
bool isNull () const throw ()
 Test if the string is null.
bool isAlphaNumeric () const throw ()
 Test if the string consists solely of alphanumeric characters (A-Z, a-z, and 0-9).
bool isInteger () const throw ()
 Test if the string holds an integer.
int compareTo (const T *other, bool ignoreCase=false) const throw ()
 Compare the string to another.
int compareTo (const BasicString< T > &other, bool ignoreCase=false) const throw ()
 Compare the string to another.
BasicString< T > & trim (const T *chars=whitespaceChars, bool begin=true, bool end=true)
 Trim leading and trailing characters from the string.
BasicString< T > & trimBegin (const T *chars=whitespaceChars)
 Trim characters from the beginning of the string.
BasicString< T > & trimEnd (const T *chars=whitespaceChars)
 Trim characters from the end of the string.
BasicString< T > & chop (T c)
 Truncate the string at the first occurrence of the given character.
BasicString< T > & reverseChop (T c)
 Truncate the string at the last occurrence of the given character.
BasicString< T > & replace (T a, T b)
 Replace all occurences of one character with another.
BasicString< T > & replace (const BasicString< T > &a, const BasicString< T > &b)
 Replace all occurences of one substring with another.
BasicString< T > & replace (const T *a, const T *b)
 Replace all occurences of one substring with another.
BasicString< T > & printf (const T *format,...)
 Append a C-style formatted string to the string.
BasicString< T > & insert (T c, uint_t index=0)
 Insert a character into the string.
BasicString< T > & insert (const T *str, uint_t index=0, size_t length=0)
 Insert a string into this string.
BasicString< T > & insert (const BasicString< T > &str, uint_t index=0, size_t length=0)
 Insert a string into this string.
BasicString< T > & insert (const std::basic_string< T > &str, uint_t index=0, size_t length=0)
 Insert a string into this string.
BasicString< T > & append (bool v)
 Append a string representation of a boolean value to the end of the string.
BasicString< T > & append (int val)
 Append a string representation of an integer value onto the end of the string.
BasicString< T > & append (int val, uint_t base)
 Append a string representation of an integer value in the given base onto the end of the string.
BasicString< T > & append (uint_t val)
 Append a string representation of an unsigned integer value onto the end of the string.
BasicString< T > & append (uint_t val, uint_t base)
 Append a string representation of an unsigned integer value in the given base onto the end of the string.
BasicString< T > & append (int64_t val)
 Append a string representation of a long long (64-bit) integer onto the end of the string.
BasicString< T > & append (double val, uint_t precision=6)
 Append a string representation of double-precision floating point value onto the end of the string.
BasicString< T > & append (uint64_t val)
 Append a string representation of an unsigned long long (64-bit) integer onto the end of the string.
BasicString< T > & append (T c)
 Append a character to the end of the string.
BasicString< T > & append (const T *str, size_t length=0)
 Append a string to the end of the string.
BasicString< T > & append (const BasicString< T > &str, size_t length=0)
 Append a string to the end of the string.
BasicString< T > & append (const std::basic_string< T > &str, size_t length=0)
 Append a string to the end of the string.
BasicString< T > & prepend (T c)
 Prepend a character to the beginning of the string.
BasicString< T > & prepend (const T *str, size_t length=0)
 Prepend a string to the beginning of the string.
BasicString< T > & prepend (const BasicString< T > &str, size_t length=0)
 Prepend a string to the beginning of the string.
BasicString< T > & prepend (const std::basic_string< T > &str, size_t length=0)
 Prepend a string to the beginning of the string.
BasicString< T > & remove (uint_t fromIndex, uint_t toIndex=END)
 Remove a portion of the string.
uint_t hash (uint_t modulo=256) const throw ()
 Compute a hashcode for the string.
BasicString< T > substring (uint_t fromIndex, uint_t toIndex=END) const
 Extract a substring from the string.
int indexOf (T c, uint_t fromIndex=0) const throw ()
 Find the first occurrence of a given character in the string.
int indexOf (const T *str, uint_t fromIndex=0) const throw ()
 Find the first occurrence of a given string in this string.
int indexOfAnyOf (const T *chars, uint_t fromIndex=0) const throw ()
 Find the first occurrence in this string of any character in a set of characters.
int indexOf (const BasicString< T > &str, uint_t fromIndex=0) const throw ()
 Find the first occurrence of a given string in this string.
int indexOf (const std::basic_string< T > &str, uint_t fromIndex=0) const throw ()
 Find the first occurrence of a given string in this string.
int lastIndexOf (T c, uint_t fromIndex=END) const throw ()
 Find the last occurrence of a given character in this string.
int lastIndexOfAnyOf (const T *chars, uint_t fromIndex=END) const throw ()
 Find the last occurrence in the string of any character in a set of characters.
int lastIndexOf (const T *str, uint_t fromIndex=END) const throw ()
 Find the last occurrence of a given string in this string.
int lastIndexOf (const BasicString< T > &str, uint_t fromIndex=END) const throw ()
 Find the last occurrence of a given string in this string.
int lastIndexOf (const std::basic_string< T > &str, uint_t fromIndex=END) const throw ()
 Find the last occurrence of a given string in this string.
bool contains (T c) const throw ()
 Determine if the string contains a given character.
bool containsAnyOf (const T *chars) const throw ()
 Determine if the string contains any character in a given set of characters.
bool contains (const T *str) const throw ()
 Determine if the string contains a given substring.
bool contains (const BasicString< T > &str) const throw ()
 Determine if the string contains a given substring.
bool contains (const std::basic_string< T > &str) const throw ()
 Determine if the string contains a given substring.
BasicString< T > nextToken (uint_t &fromIndex, const T *delim=whitespaceChars) const
 Extract a token from the string.
uint_t split (BasicStringVec< T > &tokens, const T *delim=whitespaceChars, uint_t limit=0) const
 Split the string into a series of tokens, without modifying the string.
BasicString< T > & toLowerCase ()
 Convert the string to lower case.
BasicString< T > & toUpperCase ()
 Convert the string to upper case.
BasicString< T > & fill (T c, size_t length)
 Fill the string with a character.
BasicString< T > & pad (T c, size_t length)
 Pad the string with a character.
bool toBool (uint_t index=0) const throw ()
 Parse a boolean value from the string.
int toInt (uint_t index=0, uint_t base=10) const throw ()
 Parse an integer from the string.
uint_t toUInt (uint_t index=0, uint_t base=10) const throw ()
 Parse an unsigned integer from the string.
int64_t toInt64 (uint_t index=0, uint_t base=10) const throw ()
 Parse a 64-bit integer from the string.
uint64_t toUInt64 (uint_t index=0, uint_t base=10) const throw ()
 Parse an unsigned 64-bit integer from the string.
float toFloat (uint_t index=0) const throw ()
 Parse a floating point value from the string.
double toDouble (uint_t index=0) const throw ()
 Parse a double precision floating point value from the string.
 operator const void * () const throw ()
 Pointer cast operator.
const T * c_str () const throw ()
 Return the contents of the string as an immutable C string.
Blob getBytes (const char *encoding, size_t length=0, size_t maxEncodedLength=0) const
 Encode the string using the specified character encoding, returning the results as a Blob.
BasicString< T > & operator= (const T *other)
 Assignment operator.
BasicString< T > & operator= (const BasicString< T > &other)
 Assignment operator.
BasicString< T > & operator= (const std::basic_string< T > &other)
 Assignment operator.
T & operator[] (int index) throw (OutOfBoundsException)
 Array index operator.
BasicChar< T > operator[] (int index) const throw (OutOfBoundsException)
 Array index operator.
BasicString< T > operator() (uint_t fromIndex, uint_t toIndex=END) const
 Substring operator.
bool operator! () const throw ()
 Unary NOT operator.
BasicString< T > & operator+= (T c)
 Append a character onto the end of the string.
BasicString< T > & operator+= (const T *str)
 Append a string onto the end of this string.
BasicString< T > & operator+= (const BasicString< T > &str)
 Append a string onto the end of this string.
BasicString< T > & operator+= (const std::basic_string< T > &str)
 Append a string onto the end of this string.
BasicString< T > & operator+= (bool val)
 Append a string representation of a boolean value onto the end of the string.
BasicString< T > & operator+= (int val)
 Append a string representation of an integer value onto the end of the string.
BasicString< T > & operator+= (uint_t val)
 Append a string representation of an unsigned integer value onto the end of the string.
BasicString< T > & operator+= (double val)
 Append a string representation of double-precision floating point value onto the end of the string.
BasicString< T > & operator+= (int64_t val)
 Append a string representation of a long long (64-bit) integer onto the end of the string.
BasicString< T > & operator+= (uint64_t val)
 Append a string representation of an unsigned long long (64-bit) integer onto the end of the string.
BasicString< T > & operator<< (const T *str)
 Append operator.
BasicString< T > & operator<< (const BasicString< T > &str)
 Append operator.
BasicString< T > & operator<< (const std::basic_string< T > &str)
 Append operator.
BasicString< T > & operator<< (bool val)
 Append operator.
BasicString< T > & operator<< (T c)
 Append operator.
BasicString< T > & operator<< (int val)
 Append operator.
BasicString< T > & operator<< (uint_t val)
 Append operator.
BasicString< T > & operator<< (int64_t val)
 Append operator.
BasicString< T > & operator<< (uint64_t val)
 Append operator.
BasicString< T > & operator<< (double val)
 Append operator.
BasicString< T > & operator^= (T c)
 Prepend operator.
BasicString< T > & operator^= (const T *str)
 Prepend operator.
BasicString< T > & operator^= (const BasicString< T > &str)
 Prepend operator.
BasicString< T > & operator^= (const std::basic_string< T > &str)
 Prepend operator.
BasicString< T > operator+ (const BasicString< T > &str)
BasicString< T > operator+ (const T *str)
BasicString< T > operator+ (T c)

Static Public Member Functions

static BasicString< T > fromCharArray (const char *str, size_t length=0)
 Create a string from the given character array.
static BasicString< T > fromUTF8 (const char *str)
 Create a string from the given UTF-8 character array.
static BasicString< T > fromWCharArray (const wchar_t *str, size_t length=0)
 Create a string from the given wide character array.

Static Public Attributes

static const uint_t END = BasicCharTraits<T>::END
 A pseudo-index indicating the end of the string.
static const BasicString< T > null = BasicCharTraits<T>::null()
 The null string.
static const BasicString< T > empty = BasicCharTraits<T>::empty()
 The empty string.
static const T * whitespaceChars = BasicCharTraits<T>::whitespace()
 The set of whitespace delimiter characters.


Detailed Description

template<typename T>
class ccxx::BasicString< T >

A flexible, reference counted, copy-on-write, thread-safe, nullable string.

Author:
Mark Lindner

Constructor & Destructor Documentation

BasicString (  )  [inline]

Construct a new, empty string.

BasicString ( T *  str,
size_t  offset = 0,
size_t  length = 0,
bool  copy = true 
) [inline]

Construct a new string from a C string.

Parameters:
str The C string to copy or inherit.
offset The number of characters from the beginning of the string to skip over.
length The number of characters from the offset to use, or 0 to use all the characters to the end of the string.
copy If true, the C string is copied into the BasicString; otherwise the C string is inherited and the length parameter is ignored.

BasicString ( const BasicString< T > &  other  )  [inline]

Copy constructor.

BasicString ( const T *  other,
size_t  offset = 0,
size_t  length = 0 
) [inline]

Construct a new string from a C string.

Parameters:
other The C string to copy.
offset The number of characters from the beginning of the string to skip over.
length The number of characters from the offset to copy, or 0 to copy to the end of the string.

BasicString ( const byte_t data,
size_t  length,
const char *  encoding 
) [inline]

Construct a new string from a byte array.

Parameters:
data The byte array.
length The length of the array.
encoding The character encoding of the data in the array.

~BasicString (  )  throw () [inline, virtual]

Destructor.


Member Function Documentation

BasicString<T>& append ( const std::basic_string< T > &  str,
size_t  length = 0 
) [inline]

Append a string to the end of the string.

Parameters:
str The character to append.
length The maximum number of characters from str to append, or 0 to append all of str.

BasicString<T>& append ( const BasicString< T > &  str,
size_t  length = 0 
) [inline]

Append a string to the end of the string.

Parameters:
str The character to append.
length The maximum number of characters from str to append, or 0 to append all of str.

BasicString<T>& append ( const T *  str,
size_t  length = 0 
) [inline]

Append a string to the end of the string.

Parameters:
str The character to append.
length The maximum number of characters from str to append, or 0 to append all of str.

BasicString<T>& append ( c  )  [inline]

Append a character to the end of the string.

Parameters:
c The character to append.

BasicString< T > & append ( uint64_t  val  )  [inline]

Append a string representation of an unsigned long long (64-bit) integer onto the end of the string.

Parameters:
val The value to append.

BasicString< T > & append ( double  val,
uint_t  precision = 6 
) [inline]

Append a string representation of double-precision floating point value onto the end of the string.

Parameters:
val The value to append.
precision The precision (the number of digits to include after the radix).

BasicString< T > & append ( int64_t  val  )  [inline]

Append a string representation of a long long (64-bit) integer onto the end of the string.

Parameters:
val The value to append.

BasicString< T > & append ( uint_t  val,
uint_t  base 
) [inline]

Append a string representation of an unsigned integer value in the given base onto the end of the string.

Parameters:
val The value to append.
base The numerical base in which to output the value. The valid range is 2 - 36, inclusive.

BasicString< T > & append ( uint_t  val  )  [inline]

Append a string representation of an unsigned integer value onto the end of the string.

Parameters:
val The value to append.

BasicString< T > & append ( int  val,
uint_t  base 
) [inline]

Append a string representation of an integer value in the given base onto the end of the string.

Parameters:
val The value to append.
base The numerical base in which to output the value. The valid range is 2 - 36, inclusive.

BasicString< T > & append ( int  val  )  [inline]

Append a string representation of an integer value onto the end of the string.

Parameters:
val The value to append.

BasicString< T > & append ( bool  v  )  [inline]

Append a string representation of a boolean value to the end of the string.

Parameters:
v The value to append.

const T * c_str (  )  const throw () [inline]

Return the contents of the string as an immutable C string.

BasicString< T > & chop ( c  )  [inline]

Truncate the string at the first occurrence of the given character.

Parameters:
c The character at which to truncate.
Returns:
The string.

BasicString<T>& clear (  )  [inline]

Clear the string.

Sets the length of the string to 0.

Returns:
The string.

void compact (  )  [inline]

Compact the string so that it occupies the minimum amount of memory required.

int compareTo ( const BasicString< T > &  other,
bool  ignoreCase = false 
) const throw () [inline]

Compare the string to another.

Parameters:
other The string to compare to.
ignoreCase A flag indicating whether the compare should be case insensitive.
Returns:
A negative value if the string is lexicographically "less" than other, a positive value if it is "greater" than other, and 0 if they are "equal".

int compareTo ( const T *  other,
bool  ignoreCase = false 
) const throw () [inline]

Compare the string to another.

Parameters:
other The string to compare to.
ignoreCase A flag indicating whether the compare should be case insensitive.
Returns:
A negative value if the string is lexicographically "less" than other, a positive value if it is "greater" than other, and 0 if they are "equal".

bool contains ( const std::basic_string< T > &  str  )  const throw () [inline]

Determine if the string contains a given substring.

Parameters:
str The substring to search for.
Returns:
true if the string contains at least one occurrence of the substring, false otherwise.

bool contains ( const BasicString< T > &  str  )  const throw () [inline]

Determine if the string contains a given substring.

Parameters:
str The substring to search for.
Returns:
true if the string contains at least one occurrence of the substring, false otherwise.

bool contains ( const T *  str  )  const throw () [inline]

Determine if the string contains a given substring.

Parameters:
str The substring to search for.
Returns:
true if the string contains at least one occurrence of the substring, false otherwise.

bool contains ( c  )  const throw () [inline]

Determine if the string contains a given character.

Parameters:
c The character to search for.
Returns:
true if the string contains at least one occurrence of the character, false otherwise.

bool containsAnyOf ( const T *  chars  )  const throw () [inline]

Determine if the string contains any character in a given set of characters.

Parameters:
chars The set of characters.
Returns:
true if the string contains at least one occurrence of any character in the set, false otherwise.

bool endsWith ( c,
bool  ignoreCase = false 
) const throw () [inline]

Test if the string ends with the given character.

Parameters:
c The character.
ignoreCase A flag indicating whether the comparison should be case-insensitive.
Returns:
true if the string ends with c, false otherwise.

bool endsWith ( const BasicString< T > &  str,
bool  ignoreCase = false 
) const throw () [inline]

Test if the string ends with the given string.

Parameters:
str The other string.
ignoreCase A flag indicating whether the comparison should be case-insensitive.
Returns:
true if this string ends with str, false otherwise.

bool endsWithAnyOf ( const T *  chars,
bool  ignoreCase = false 
) const throw () [inline]

Test if the string ends with any character in a given set of characters.

Parameters:
chars The set of characters.
ignoreCase A flag indicating whether the comparison should be case-insensitive.
Returns:
true if the string ends with one of the characters in the set, false otherwise.

BasicString< T > & fill ( c,
size_t  length 
) [inline]

Fill the string with a character.

Parameters:
c The fill character.
length The number of characters to fill.

BasicString< T > fromCharArray ( const char *  str,
size_t  length = 0 
) [inline, static]

Create a string from the given character array.

BasicString< T > fromUTF8 ( const char *  str  )  [inline, static]

Create a string from the given UTF-8 character array.

BasicString< T > fromWCharArray ( const wchar_t *  str,
size_t  length = 0 
) [inline, static]

Create a string from the given wide character array.

Blob getBytes ( const char *  encoding,
size_t  length = 0,
size_t  maxEncodedLength = 0 
) const [inline]

Encode the string using the specified character encoding, returning the results as a Blob.

Parameters:
encoding The character encoding to use.
length The number of characters to encode, or 0 to encode the entire string.
maxEncodedLength The maximum number of bytes to encode, or 0 if there is no limit. If a limit is specified, no more complete characters will be encoded than would fit in the specified number of bytes.
Returns:
The encoded string, as a Blob.

size_t getCapacity (  )  const throw () [inline]

Get the current capacity of the string, in characters.

This value takes into account the space required for the final NUL terminator.

size_t getLength (  )  const throw () [inline]

Get the length of the string.

Returns:
The length, in characters, or 0 if the BasicString is null.

uint_t hash ( uint_t  modulo = 256  )  const throw () [inline]

Compute a hashcode for the string.

Parameters:
modulo The desired range for the hashcode.
Returns:
A hashcode in the range [0, modulo).

int indexOf ( const std::basic_string< T > &  str,
uint_t  fromIndex = 0 
) const throw () [inline]

Find the first occurrence of a given string in this string.

Parameters:
str The string to search for.
fromIndex The start index from which to begin searching.
Returns:
The index of the first occurrence of the string, or -1 if the string was not found.

int indexOf ( const BasicString< T > &  str,
uint_t  fromIndex = 0 
) const throw () [inline]

Find the first occurrence of a given string in this string.

Parameters:
str The string to search for.
fromIndex The start index from which to begin searching.
Returns:
The index of the first occurrence of the string, or -1 if the string was not found.

int indexOf ( const T *  str,
uint_t  fromIndex = 0 
) const throw () [inline]

Find the first occurrence of a given string in this string.

Parameters:
str The string to search for.
fromIndex The start index from which to begin searching.
Returns:
The index of the first occurrence of the string, or -1 if the string was not found.

int indexOf ( c,
uint_t  fromIndex = 0 
) const throw () [inline]

Find the first occurrence of a given character in the string.

Parameters:
c The character to search for.
fromIndex The start index from which to begin searching.
Returns:
The index of the first occurrence of the character, or -1 if the character was not found.

int indexOfAnyOf ( const T *  chars,
uint_t  fromIndex = 0 
) const throw () [inline]

Find the first occurrence in this string of any character in a set of characters.

Parameters:
chars The set of characters search for.
fromIndex The start index from which to begin searching.
Returns:
The index of the first occurrence of any character in the set, or -1 if no occurrence was not found.

BasicString<T>& insert ( const std::basic_string< T > &  str,
uint_t  index = 0,
size_t  length = 0 
) [inline]

Insert a string into this string.

Parameters:
str The string to insert.
index The index at which to insert the string. If the index is out of range, the string is appended to the end of this string.
length The maximum number of characters from str to insert.

BasicString< T > & insert ( const BasicString< T > &  str,
uint_t  index = 0,
size_t  length = 0 
) [inline]

Insert a string into this string.

Parameters:
str The string to insert.
index The index at which to insert the string. If the index is out of range, the string is appended to the end of this string.
length The maximum number of characters from str to insert.

BasicString< T > & insert ( const T *  str,
uint_t  index = 0,
size_t  length = 0 
) [inline]

Insert a string into this string.

Parameters:
str The string to insert.
index The index at which to insert the string. If the index is out of range, the string is appended to the end of this string.
length The maximum number of characters from str to insert.

BasicString< T > & insert ( c,
uint_t  index = 0 
) [inline]

Insert a character into the string.

Parameters:
c The character to insert.
index The index at which to insert the character. If the index is out of range, the character is appended to the end of the string.

bool isAlphaNumeric (  )  const throw () [inline]

Test if the string consists solely of alphanumeric characters (A-Z, a-z, and 0-9).

Returns:
true if the string is alphanumeric, false otherwise.

bool isEmpty (  )  const throw () [inline]

Test if the string is empty.

Returns:
true if the string is null or has length 0, false otherwise.

bool isInteger (  )  const throw () [inline]

Test if the string holds an integer.

For example, "123", "+5", and "-123" are integers.

Returns:
true if the string is an integer, false otherwise.

bool isNull (  )  const throw () [inline]

Test if the string is null.

Returns:
true if the string is null, false otherwise.

int lastIndexOf ( const std::basic_string< T > &  str,
uint_t  fromIndex = END 
) const throw () [inline]

Find the last occurrence of a given string in this string.

Parameters:
str The string to search for.
fromIndex The index from which to begin searching backwards, or END to start at the end of the string.
Returns:
The index of the last occurrence of the string, or -1 if the string was not found.

int lastIndexOf ( const BasicString< T > &  str,
uint_t  fromIndex = END 
) const throw () [inline]

Find the last occurrence of a given string in this string.

Parameters:
str The string to search for.
fromIndex The index from which to begin searching backwards, or END to start at the end of the string.
Returns:
The index of the last occurrence of the string, or -1 if the string was not found.

int lastIndexOf ( const T *  str,
uint_t  fromIndex = END 
) const throw () [inline]

Find the last occurrence of a given string in this string.

Parameters:
str The string to search for.
fromIndex The index from which to begin searching backwards, or END to start at the end of the string.
Returns:
The index of the last occurrence of the string, or -1 if the string was not found.

int lastIndexOf ( c,
uint_t  fromIndex = END 
) const throw () [inline]

Find the last occurrence of a given character in this string.

Parameters:
c The character to search for.
fromIndex The index from which to begin searching backwards, or END to start at the end of the string.
Returns:
The index of the last occurrence of the character, or -1 if the character was not found.

int lastIndexOfAnyOf ( const T *  chars,
uint_t  fromIndex = END 
) const throw () [inline]

Find the last occurrence in the string of any character in a set of characters.

Parameters:
chars The set of characters search for.
fromIndex The index from which to begin searching backwards, or END to start at the end of the string.
Returns:
The index of the last occurrence of any character in the set, or -1 if no occurrence was not found.

size_t length (  )  const throw () [inline]

Get the length of the string.

Returns:
The length, in characters, or 0 if the string is null.

BasicString< T > nextToken ( uint_t fromIndex,
const T *  delim = whitespaceChars 
) const [inline]

Extract a token from the string.

Parameters:
fromIndex The start index at which to begin searching for a token. Will be modified on return to point to one character past the extracted token.
delim The set of possible token delimiter characters (the set of whitespace characters by default).
Returns:
The extracted token, or String::null if the end of the string has been reached.

operator const void * (  )  const throw () [inline]

Pointer cast operator.

bool operator! (  )  const throw () [inline]

Unary NOT operator.

Returns:
true if the string is null, false otherwise.

BasicString<T> operator() ( uint_t  fromIndex,
uint_t  toIndex = END 
) const [inline]

Substring operator.

Extract a substring from the string.

Parameters:
fromIndex The start index of the substring.
toIndex The end index of the substring, or END to indicate the end of the string.
Returns:
The substring as a new string. If fromIndex and toIndex are equal, an empty string is returned.

BasicString< T > operator+ ( c  )  [inline]

BasicString< T > operator+ ( const T *  str  )  [inline]

BasicString< T > operator+ ( const BasicString< T > &  str  )  [inline]

BasicString<T>& operator+= ( uint64_t  val  )  [inline]

Append a string representation of an unsigned long long (64-bit) integer onto the end of the string.

Parameters:
val The value to append.

BasicString<T>& operator+= ( int64_t  val  )  [inline]

Append a string representation of a long long (64-bit) integer onto the end of the string.

Parameters:
val The value to append.

BasicString<T>& operator+= ( double  val  )  [inline]

Append a string representation of double-precision floating point value onto the end of the string.

Parameters:
val The value to append.

BasicString<T>& operator+= ( uint_t  val  )  [inline]

Append a string representation of an unsigned integer value onto the end of the string.

Parameters:
val The value to append.

BasicString<T>& operator+= ( int  val  )  [inline]

Append a string representation of an integer value onto the end of the string.

Parameters:
val The value to append.

BasicString<T>& operator+= ( bool  val  )  [inline]

Append a string representation of a boolean value onto the end of the string.

Parameters:
val The value to append.

BasicString<T>& operator+= ( const std::basic_string< T > &  str  )  [inline]

Append a string onto the end of this string.

Parameters:
str The string to append.

BasicString<T>& operator+= ( const BasicString< T > &  str  )  [inline]

Append a string onto the end of this string.

Parameters:
str The string to append.

BasicString<T>& operator+= ( const T *  str  )  [inline]

Append a string onto the end of this string.

Parameters:
str The string to append.

BasicString<T>& operator+= ( c  )  [inline]

Append a character onto the end of the string.

Parameters:
c The character to append.

BasicString<T>& operator<< ( double  val  )  [inline]

Append operator.

BasicString<T>& operator<< ( uint64_t  val  )  [inline]

Append operator.

BasicString<T>& operator<< ( int64_t  val  )  [inline]

Append operator.

BasicString<T>& operator<< ( uint_t  val  )  [inline]

Append operator.

BasicString<T>& operator<< ( int  val  )  [inline]

Append operator.

BasicString<T>& operator<< ( c  )  [inline]

Append operator.

BasicString<T>& operator<< ( bool  val  )  [inline]

Append operator.

BasicString<T>& operator<< ( const std::basic_string< T > &  str  )  [inline]

Append operator.

BasicString<T>& operator<< ( const BasicString< T > &  str  )  [inline]

Append operator.

BasicString<T>& operator<< ( const T *  str  )  [inline]

Append operator.

BasicString<T>& operator= ( const std::basic_string< T > &  other  )  [inline]

Assignment operator.

BasicString< T > & operator= ( const BasicString< T > &  other  )  [inline]

Assignment operator.

BasicString< T > & operator= ( const T *  other  )  [inline]

Assignment operator.

BasicChar< T > operator[] ( int  index  )  const throw (OutOfBoundsException) [inline]

Array index operator.

Obtain a copy of the character at the given offset in the string.

Parameters:
index The index.
Returns:
The character at the specified index, as a Char.
Exceptions:
OutOfBoundsException If index is out of range.

T & operator[] ( int  index  )  throw (OutOfBoundsException) [inline]

Array index operator.

Obtain a reference to the character at the given offset in the string.

Parameters:
index The index.
Returns:
A reference to the character at the specified index.
Exceptions:
OutOfBoundsException If index is out of range.

BasicString<T>& operator^= ( const std::basic_string< T > &  str  )  [inline]

Prepend operator.

BasicString<T>& operator^= ( const BasicString< T > &  str  )  [inline]

Prepend operator.

BasicString<T>& operator^= ( const T *  str  )  [inline]

Prepend operator.

BasicString<T>& operator^= ( c  )  [inline]

Prepend operator.

BasicString< T > & pad ( c,
size_t  length 
) [inline]

Pad the string with a character.

Parameters:
c The pad character.
length The number of characters to pad.

BasicString<T>& prepend ( const std::basic_string< T > &  str,
size_t  length = 0 
) [inline]

Prepend a string to the beginning of the string.

Parameters:
str The character to prepend.
length The maximum number of characters from str to prepend, or 0 to prepend all of str.

BasicString<T>& prepend ( const BasicString< T > &  str,
size_t  length = 0 
) [inline]

Prepend a string to the beginning of the string.

Parameters:
str The character to prepend.
length The maximum number of characters from str to prepend, or 0 to prepend all of str.

BasicString<T>& prepend ( const T *  str,
size_t  length = 0 
) [inline]

Prepend a string to the beginning of the string.

Parameters:
str The character to prepend.
length The maximum number of characters from str to prepend, or 0 to prepend all of str.

BasicString<T>& prepend ( c  )  [inline]

Prepend a character to the beginning of the string.

Parameters:
c The character to prepend.

BasicString< T > & printf ( const T *  format,
  ... 
) [inline]

Append a C-style formatted string to the string.

The functionality is equivalent to that of sprintf().

Parameters:
format The format string.

BasicString< T > & remove ( uint_t  fromIndex,
uint_t  toIndex = END 
) [inline]

Remove a portion of the string.

Parameters:
fromIndex The start index of the range to remove.
toIndex The end index of the range to remove, or END to remove to the end of the string.

BasicString< T > & replace ( const T *  a,
const T *  b 
) [inline]

Replace all occurences of one substring with another.

Parameters:
a The substring to replace.
b The replacement substring.
Returns:
The string.

BasicString<T>& replace ( const BasicString< T > &  a,
const BasicString< T > &  b 
) [inline]

Replace all occurences of one substring with another.

Parameters:
a The substring to replace.
b The replacement substring.
Returns:
The string.

BasicString< T > & replace ( a,
b 
) [inline]

Replace all occurences of one character with another.

Parameters:
a The character to replace.
b The replacement character.
Returns:
The string.

void reserve ( uint_t  capacity  )  [inline]

Reserve space in the string for the given number of characters.

If the new capacity is less than or equal to the current capacity, the string is not modified.

Parameters:
capacity The new capacity.

BasicString< T > & reverseChop ( c  )  [inline]

Truncate the string at the last occurrence of the given character.

Parameters:
c The character at which to truncate.
Returns:
The string.

void setLength ( uint_t  length  )  [inline]

Set the length of the string.

Allows the string to be truncated to an arbitrary length.

Parameters:
length The new length. The new length must be less than the current length; otherwise the string is left unmodified.

uint_t split ( BasicStringVec< T > &  tokens,
const T *  delim = whitespaceChars,
uint_t  limit = 0 
) const [inline]

Split the string into a series of tokens, without modifying the string.

Parameters:
tokens The vector in which to place the extracted tokens. If a non-empty vector is supplied, the tokens are added to the end of the vector.
delim The set of possible token delimiter characters (the set of whitespace characters by default).
limit The maximum number of tokens to extract, or 0 for no limit (the default).
Returns:
The number of tokens extracted.

bool startsWith ( c,
bool  ignoreCase = false 
) const throw () [inline]

Test if the string starts with the given character.

Parameters:
c The character.
ignoreCase A flag indicating whether the comparison should be case-insensitive.
Returns:
true if the string begins with c, false otherwise.

bool startsWith ( const BasicString< T > &  str,
bool  ignoreCase = false 
) const throw () [inline]

Test if the string starts with the given string.

Parameters:
str The other string.
ignoreCase A flag indicating whether the comparison should be case-insensitive.
Returns:
true if the BasicString begins with str, false otherwise.

bool startsWithAnyOf ( const T *  chars,
bool  ignoreCase = false 
) const throw () [inline]

Test if the string starts with any character in a given set of characters.

Parameters:
chars The set of characters.
ignoreCase A flag indicating whether the comparison should be case-insensitive.
Returns:
true if the string starts with one of the characters in the set, false otherwise.

BasicString< T > substring ( uint_t  fromIndex,
uint_t  toIndex = END 
) const [inline]

Extract a substring from the string.

Parameters:
fromIndex The start index of the substring.
toIndex The end index of the substring, or END to indicate the end of the string.
Returns:
The substring as a new string. If fromIndex and toIndex are equal, an empty string is returned.

bool toBool ( uint_t  index = 0  )  const throw () [inline]

Parse a boolean value from the string.

Parameters:
index The index to begin parsing at.
Returns:
The parsed value.

double toDouble ( uint_t  index = 0  )  const throw () [inline]

Parse a double precision floating point value from the string.

Parameters:
index The index to begin parsing at.
Returns:
The parsed value.

float toFloat ( uint_t  index = 0  )  const throw () [inline]

Parse a floating point value from the string.

Parameters:
index The index to begin parsing at.
Returns:
The parsed value.

int toInt ( uint_t  index = 0,
uint_t  base = 10 
) const throw () [inline]

Parse an integer from the string.

Parameters:
index The index to begin parsing at.
base The base (2 - 36).
Returns:
The parsed value.

int64_t toInt64 ( uint_t  index = 0,
uint_t  base = 10 
) const throw () [inline]

Parse a 64-bit integer from the string.

Parameters:
index The index to begin parsing at.
base The base (2 - 36).
Returns:
The parsed value.

BasicString< T > & toLowerCase (  )  [inline]

Convert the string to lower case.

uint_t toUInt ( uint_t  index = 0,
uint_t  base = 10 
) const throw () [inline]

Parse an unsigned integer from the string.

Parameters:
index The index to begin parsing at.
base The base (2 - 36).
Returns:
The parsed value.

uint64_t toUInt64 ( uint_t  index = 0,
uint_t  base = 10 
) const throw () [inline]

Parse an unsigned 64-bit integer from the string.

Parameters:
index The index to begin parsing at.
base The base (2 - 36).
Returns:
The parsed value.

BasicString< T > & toUpperCase (  )  [inline]

Convert the string to upper case.

BasicString< T > & trim ( const T *  chars = whitespaceChars,
bool  begin = true,
bool  end = true 
) [inline]

Trim leading and trailing characters from the string.

Returns:
The string.

BasicString<T>& trimBegin ( const T *  chars = whitespaceChars  )  [inline]

Trim characters from the beginning of the string.

Parameters:
chars The set of characters to trim (the set of whitespace characters by default).

BasicString<T>& trimEnd ( const T *  chars = whitespaceChars  )  [inline]

Trim characters from the end of the string.

Parameters:
chars The set of characters to trim (the set of whitespace characters by default).


Member Data Documentation

const BasicString< T > empty = BasicCharTraits<T>::empty() [inline, static]

The empty string.

const uint_t END = BasicCharTraits<T>::END [inline, static]

A pseudo-index indicating the end of the string.

const BasicString< T > null = BasicCharTraits<T>::null() [inline, static]

The null string.

const T * whitespaceChars = BasicCharTraits<T>::whitespace() [inline, static]

The set of whitespace delimiter characters.


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

Generated on Mon Jan 4 21:38:47 2010 for libcommonc++ by  doxygen 1.5.9