Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

lrt::String Class Reference

A sequence of characters. More...

#include <rtstring.h>

Inheritance diagram for lrt::String:

Inheritance graph
[legend]
List of all members.

Public Types

enum  SplitFlags { NONE = 0, CREATE_EMPTY = 1 }
 Flags for split(). More...


Public Methods

 String ()
 Creates an empty string.

 String (const char *cStr)
 Creates a string from an C-style character pointer. More...

 String (const char chr, int length)
 Creates a string consisting of length equal characters, namely chr. More...

 String (int num, int radix=10, int length=0)
 Creates a string representing a given integer number. More...

 String (double num, int minLength=13)
 Creates a string representing a given floating-point number. More...

 String (const String &str)
 Creates a copy of String str.

String & operator+= (const char)
 Appends a single character (or character literal) to this string. More...

String & operator+= (const int)
 Appends the numerical (decimal) representation of a number to this string. More...

String & operator+= (const String &)
 Appends another String to this String. More...

String & operator= (const String &)
 Clears this String, then copies the given String's contents over to this one. More...

String trim () const
 Returns a new string like this one, but with any whitespace from the beginning and end of the string removed. More...

String substring (int start, int end=Math::MAX_INT) const
 Returns a new string which represents a part of this string. More...

String lowerCase () const
 Returns a new string which is the lowercase equivalent of this string.

String upperCase () const
 Returns a new string which is the uppercase equivalent of this string.

int indexOf (char ch, int fromIndex=0) const
 Finds the first occurence of a given character in this string. More...

int indexOf (const String &str, int fromIndex=0) const
 Finds the first occurence of a given substring in this string. More...

int lastIndexOf (char ch, int fromIndex=Math::MAX_INT) const
 Finds the first occurence of a given character in this string, searching backwards from the end of this string. More...

int lastIndexOf (const String &str, int fromIndex=Math::MAX_INT) const
 Finds the first occurence of a given substring in this string, searching backwards from the end of this string. More...

bool operator== (const String &) const
 Returns true if all characters of this string are exactly equal to the given string.

bool operator!= (const String &) const
 Returns true if any character, or the length, of this string differ from the given string.

bool operator< (const String &) const
 Returns true if this string should be ordered before the given string. More...

int compare (const String &str) const
 Returns a negative, zero, or a positive number as this is less, equal, or greater than str. More...

int compareIgnoreCase (const String &str) const
 Returns a negative, zero, or a positive number as this is less, equal, or greater than str. More...

bool startsWith (const String &str) const
 Returns true if this string starts with the given substring str.

bool endsWith (const String &str) const
 Returns true if this string ends with the given substring str.

String replace (char oldCh, char newCh) const
 Returns a new string, in which all occurencies of oldCh are replaced by newCh.

String replace (const String &oldStr, const String &newStr) const
 Returns a new string, in which all occurencies of oldStr have been replaced by newStr.

Array< String > split (const String &separators=",", const String &combiners="\"\'", int maxParts=-1, SplitFlags flags=NONE) const
 Splits this string into parts. More...

const char * cStr () const
 Returns a constant pointer to this string's data. More...

int intValue (int def, int radix=10) const
 Parses this String as an integer. More...

double doubleValue (double def) const
 Parses this String as a floating-point value. More...

virtual ~String ()

Static Public Methods

int compare (const String &str1, const String &str2)
 Compares two strings. More...

int compareIgnoreCase (const String &str1, const String &str2)
 Compares two strings, ignoring case. More...

String join (const Array< String > &arr, const String &joiner=",", const int upTo=Math::MAX_INT)
 Joins an array of Strings together. More...


Detailed Description

A sequence of characters.

The String class of libRT implements many methods for comfortable handling of strings, including conversion from and to numbers, case conversions, substrings, searches, comparisons, etc.


Member Enumeration Documentation

enum lrt::String::SplitFlags
 

Flags for split().

Enumeration values:
CREATE_EMPTY  create empty parts between, if two separators follow immediately. Use this for CSV or similar data.


Constructor & Destructor Documentation

lrt::String::String (  const char *    cStr ) 
 

Creates a string from an C-style character pointer.

This constructor is also used to implicitely convert all string literals to libRT Strings.

lrt::String::String (  const char    chr,
int    length
) 
 

Creates a string consisting of length equal characters, namely chr.

Example: String('a', 7) becomes "aaaaaaa"

lrt::String::String (  int    num,
int    radix = 10,
int    length = 0
) 
 

Creates a string representing a given integer number.

Parameters:
num  The number to represent.
radix  (optional) The radix to use for number conversion (e.g. 2 for binary, 10 for decimal). radix may not be smaller than 2, nor larger than Char::MAX_RADIX.
length  (optional) The length the returned String should have. Places not used by the number conversion are filled with spaces.

lrt::String::String (  double    num,
int    minLength = 13
)  [explicit]
 

Creates a string representing a given floating-point number.

Parameters:
num  The number to represent.
minLength  (optional) The minimum length the returned String is required to have. The places are all filled with numbers.


Member Function Documentation

int lrt::String::compare (  const String &    str1,
const String &    str2
)  [inline, static]
 

Compares two strings.

This method is case sensitive, and will not work well for non-English text.

Returns:
A negative number, zero, or a positive number as the first string is less than, equal or more than the second.

int lrt::String::compare (  const String &    str )  const [inline]
 

Returns a negative, zero, or a positive number as this is less, equal, or greater than str.

This method is case sensitive, and will not work well for non-English text.

Returns:
A negative number, zero, or a positive number as this string is less than, equal or more than str.

int lrt::String::compareIgnoreCase (  const String &    str1,
const String &    str2
)  [inline, static]
 

Compares two strings, ignoring case.

This method is case insensitive, and will not work well for non-English text.

Returns:
A negative number, zero, or a positive number as the first string is less than, equal or more than the second.

int lrt::String::compareIgnoreCase (  const String &    str )  const [inline]
 

Returns a negative, zero, or a positive number as this is less, equal, or greater than str.

This method is case insensitive, and will not work well for non-English text.

Returns:
A negative number, zero, or a positive number as this string is less than, equal or more than str.

const char * lrt::String::cStr (    )  const
 

Returns a constant pointer to this string's data.

This string is zero-terminated before returning the pointer, but any subsequent String modifications (through the String methods, as you cannot modify the string using the returned pointer) will probably make the pointer useless.
Warning: If this String is destroyed, the pointer becomes invalid. So do never call this method on temporary objects!

double lrt::String::doubleValue (  double    def )  const
 

Parses this String as a floating-point value.

As many numbers as possible are parsed from the beginning of this String. If there are no valid numbers at the beginning of this String, the given default value is instead returned.

Parameters:
def  The default value, which is returned if this String cannot be interpreted as a number.

int lrt::String::indexOf (  const String &    str,
int    fromIndex = 0
)  const
 

Finds the first occurence of a given substring in this string.

Parameters:
str  The string you'd like to search for.
fromIndex  (optional) The position where the search starts. If fromIndex is not specified, the whole String will be searched.
Returns:
The index of the first occurence of str, or -1 if str is not present in this String.

int lrt::String::indexOf (  char    ch,
int    fromIndex = 0
)  const [inline]
 

Finds the first occurence of a given character in this string.

Parameters:
ch  The character you'd like to search for.
fromIndex  (optional) The position where the search starts. If fromIndex is not specified, the whole String will be searched.
Returns:
The index of the first occurence of ch, or -1 if ch is not present in this String.

int lrt::String::intValue (  int    def,
int    radix = 10
)  const
 

Parses this String as an integer.

As many numbers as possible are parsed from the beginning of this String. If there are no valid numbers at the beginning of this String (considering the given radix), the given default value is instead returned.

Parameters:
def  The default value, which is returned if this String cannot be interpreted as a number.
radix  (optional) The radix which is used to convert the String. Valid values are from 2 up to Char::MAX_RADIX.

String lrt::String::join (  const Array< String > &    arr,
const String &    joiner = ",",
const int    upTo = Math::MAX_INT
)  [static]
 

Joins an array of Strings together.

Parameters:
arr  The array to be joined together.
joiner  (optional) The joiner string which is inserted between every two array entries. Useful examples: ", " or "\n".
upTo  (optional) The maximum array index which is included in the returned string.

int lrt::String::lastIndexOf (  const String &    str,
int    fromIndex = Math::MAX_INT
)  const
 

Finds the first occurence of a given substring in this string, searching backwards from the end of this string.

Parameters:
str  The substring you'd like to search for.
fromIndex  (optional) The position where the search starts. If fromIndex is not specified, the whole String will be searched.
Returns:
The index of the last occurence of str, or -1 if str is not present in this String.

int lrt::String::lastIndexOf (  char    ch,
int    fromIndex = Math::MAX_INT
)  const
 

Finds the first occurence of a given character in this string, searching backwards from the end of this string.

Parameters:
ch  The character you'd like to search for.
fromIndex  (optional) The position where the search starts. If fromIndex is not specified, the whole String will be searched.
Returns:
The index of the last occurence of ch, or -1 if ch is not present in this String.

String & lrt::String::operator+= (  const String &    ) 
 

Appends another String to this String.

Returns:
A reference to this string.

String & lrt::String::operator+= (  const    int ) 
 

Appends the numerical (decimal) representation of a number to this string.

Returns:
A reference to this string.

String & lrt::String::operator+= (  const    char ) 
 

Appends a single character (or character literal) to this string.

Returns:
A reference to this string.

bool lrt::String::operator< (  const String &    )  const [inline]
 

Returns true if this string should be ordered before the given string.

This operator is case sensitive, and will not work well for non-English text.

String & lrt::String::operator= (  const String &    ) 
 

Clears this String, then copies the given String's contents over to this one.

Returns:
A reference to this string.

Array< String > lrt::String::split (  const String &    separators = ",",
const String &    combiners = "\"\'",
int    maxParts = -1,
SplitFlags    flags = NONE
)  const
 

Splits this string into parts.

The string is split into portions wherever one of the separators is found. However, matching pairs of combiners can be used to group words together. There is automatically any whitespace removed from the returned parts (as defined by Char::isSpace()). The separators themselves are not included in the returned parts.

Example: The string ""Hello, my ",dear , world!", using the separators " " and "," and the combiner """, will be split into the following parts: "Hello, my", "dear", "world!".

Parameters:
separators  (optional) A list of all separators which may be used to split the string.
combiners  (optional) A list of all combiners which may be used to group words together.
maxParts  (optional) The maximum number of parts the string will be split into. Normally, this value is unlimited.
flags  (optional) More flags to customize the split operation.

String lrt::String::substring (  int    start,
int    end = Math::MAX_INT
)  const
 

Returns a new string which represents a part of this string.

Parameters:
start  Begin index of the new string.
end  (optional) Position after the end index of the new string. If not specified, the new string extends until the end of this string.

String lrt::String::trim (    )  const
 

Returns a new string like this one, but with any whitespace from the beginning and end of the string removed.

For a definition of whitespace,

See also:
Char::isSpace()


The documentation for this class was generated from the following files:
This is the RoboTour API documentation version 0.1 • Copyright (C) by Florian Fischer