Main Page   Class Hierarchy   Alphabetical List   Compound List   Compound Members  

util::String Class Reference

#include <String.h>

Inheritance diagram for util::String:

util::Computable util::Object List of all members.

Detailed Description

Contains static methods for many useful string handling needs.

String instances can also be used interchangeably with std::string.


Public Methods

 String ()
 Create an empty string.

 String (const String &other)
 Copy another String.

 String (const std::string &str)
 Copy an std::string.

 operator std::string & ()
 Typecast to a std::string&.

String & operator= (const String &other)
 Copy a String.

String & operator= (const std::string &str)
 Copy an std::string.

std::string toString () const
 Convert a String to an std::string.

Objectclone () const throw (NotCloneableException&)
 Clone a String.

SmartPtr< Computableplus (const Computable &c, bool switched=false) const throw (ComputationException&)
 Perform an addition operation on a string.

SmartPtr< Computablemultiply (const Computable &c, bool switched=false) const throw (ComputationException&)
 Perform a multiplication operation on a string.


Static Public Methods

std::string fix (const std::string &str)
 Remove all trailing and leading white spaces from a string.

std::string shrink (const std::string &str, int count=1)
 Replace all white spaces with ' ' and change sequences of spaces to single (or any other number of) spaces.

std::string backslashify (const std::string &str)
 Convert newlines, carriage returns and other special characters to their C correspondents.

std::string unslashify (const std::string &str)
 Convert all backslashed special characters to bytes.

std::string addXMLEntities (const std::string &str)
 Convert all occurences of &, <, >, " and ' to their corresponding XML entities (&amp;, &lt;, &gt;, &quot; and &apos;).

std::string removeXMLEntities (const std::string &str)
 Remove all XML 1.0 standard entities by converting them to characters.

std::string replace (const std::string &str, const std::string &from, const std::string &to, int n=0)
 Replace all occurences of from within str with to.

std::string reverseReplace (const std::string &str, const std::string &from, const std::string &to, int n=0)
 Replace all occurences of from within str with to.

std::string reverse (const std::string &str)
 Get a string that contains the characters in str in reverse order.

char * getData (const std::string &str)
 Get a newly allocated character array that contains a copy of the contents of str with a null at the end.

std::string substitute (const std::string &str, Map< std::string, std::string > &variables)
 Use the provided map of variable name - value pairs to replace all shell-syntax variables in str.

std::string readInteger (const char *ptr)
 Read an integer starting from ptr.

std::string readDouble (const char *ptr, const char decimalSeparator='.')
 Read a floating point number starting from ptr.

template<class T> std::string toString (T value)
 Convert any type to a string.

template<class T> T parse (const std::string &str)
 Get any type out of a string.

int parseInt (const std::string &str)
 Get an integer out of a string.

long parseLong (const std::string &str)
 Get a long integer out of a string.

double parseDouble (const std::string &str)
 Get a double out of a string.

template<class T> List< T > parseList (const std::string &str, std::string separatorChars)
 Convert a string to a list of elements of any type.

void tokenize (const std::string &msg, std::string separators, List< std::string > &result, int maxParts=-1)
 Tokenize a string.

List< std::string > tokenize (const std::string &msg, std::string separators, int maxParts=-1)
 Tokenize a string.

std::string join (const List< std::string > &parts, std::string glue)
 Join strings together.

std::string substr (const std::string &str, int start, int length=MAXINT)
 Take a part of a string.

bool startsWith (const std::string &str, std::string start)
 Check if str starts with start.

bool endsWith (const std::string &str, std::string end)
 Check if str ends with end.


Member Function Documentation

string util::String::addXMLEntities const std::string &    str [static]
 

Convert all occurences of &, <, >, " and ' to their corresponding XML entities (&amp;, &lt;, &gt;, &quot; and &apos;).

Parameters:
str  the string to convert
Returns:
a converted string

string util::String::backslashify const std::string &    str [static]
 

Convert newlines, carriage returns and other special characters to their C correspondents.

Parameters:
str  the string to be converted
Returns:
a new string with special characters backslashed

string util::String::fix const std::string &    str [static]
 

Remove all trailing and leading white spaces from a string.

Parameters:
str  the string to be fixed
Returns:
a fixed string

string util::String::join const List< std::string > &    parts,
std::string    glue
[static]
 

Join strings together.

Parameters:
parts  some strings
glue  the string to be placed between the parts

util::String::operator std::string &   [inline]
 

Typecast to a std::string&.

This method allows the use of a String instance where a std::string is expected.

template<class T>
List< T > util::String::parseList const std::string &    str,
std::string    separatorChars
[static]
 

Convert a string to a list of elements of any type.

Parameters:
msg  the string to be split into parts
separators  the characters that are to be treated as token separators, for example: " \t
\r".
Returns:
the tokens converted to the wanted type.

string util::String::readDouble const char *    ptr,
const char    decimalSeparator = '.'
[static]
 

Read a floating point number starting from ptr.

If your ptr points to, say, "123.56e10Abc", the returned string will contain "123.56e10". You may need this method in conjunction with parseInt or parseDouble.

Parameters:
ptr  the character string that contains a number
decimalSeparator  the character used to separate decimals

string util::String::readInteger const char *    ptr [static]
 

Read an integer starting from ptr.

If your ptr points to, say, "-123Abc", the returned string will contain "-123". You may need this method in conjunction with parseInt or parseLong.

Parameters:
ptr  the character string that contains a number

string util::String::removeXMLEntities const std::string &    str [static]
 

Remove all XML 1.0 standard entities by converting them to characters.

Parameters:
str  the string to convert
Returns:
a converted string

string util::String::replace const std::string &    str,
const std::string &    from,
const std::string &    to,
int    n = 0
[static]
 

Replace all occurences of from within str with to.

Parameters:
str  the string that is searched for matches
from  what to look for
to  if a match is found, replace it with this
n  the maximum number of replacements allowed. If this value is smaller than 1, all occurrences will be replaced.

string util::String::reverseReplace const std::string &    str,
const std::string &    from,
const std::string &    to,
int    n = 0
[static]
 

Replace all occurences of from within str with to.

This method is identical to replace, but it starts from the end of a string.

string util::String::shrink const std::string &    str,
int    count = 1
[static]
 

Replace all white spaces with ' ' and change sequences of spaces to single (or any other number of) spaces.

Parameters:
str  the string to be shrinked
count  replace sequences of spaces with this many spaces
Returns:
a shrinked string

string util::String::substitute const std::string &    str,
Map< std::string, std::string > &    variables
[static]
 

Use the provided map of variable name - value pairs to replace all shell-syntax variables in str.

Parameters:
str  the string that has variables inserted
variables  the variables that are to be used

string util::String::substr const std::string &    str,
int    start,
int    length = MAXINT
[static]
 

Take a part of a string.

If either start or length is negative, it is treated as a negative offset from the end of the string.

List< string > util::String::tokenize const std::string &    msg,
std::string    separators,
int    maxParts = -1
[static]
 

Tokenize a string.

Parameters:
msg  the string to be split into parts
separators  the characters that are to be treated as token separators, for example: " \t
\r".
maxParts  the maximum number of separated parts. maxParts <= 0 means all.
Returns:
separated tokens in a list

void util::String::tokenize const std::string &    msg,
std::string    separators,
List< std::string > &    result,
int    maxParts = -1
[static]
 

Tokenize a string.

Parameters:
msg  the string to be split into parts
separators  the characters that are to be treated as token separators, for example: " \t
\r".
result  the list that is to store the tokens
maxParts  the maximum number of separated parts. maxParts <= 0 means all.

string util::String::unslashify const std::string &    str [static]
 

Convert all backslashed special characters to bytes.

Parameters:
str  the string from which backslashes are to be removed
Returns:
a new string with backslashes removed


The documentation for this class was generated from the following files:
Documentation generated on 11.09.2003 with Doxygen.
The documentation is copyrighted material.
Copyright © Topi Mäenpää 2003. All rights reserved.