net::halfdans::String Class Reference

String class with several ease-of-use methods, roughly mimicking Python's string class. More...

#include <hstring.hpp>

Inherits std::string.

Collaboration diagram for net::halfdans::String:

Collaboration graph
[legend]

List of all members.

Public Member Functions

template<typename T>
 String (T _value)
 Construct a string equal to _value converted to a string using operator<<.
 String (size_type _size, value_type _character)
 Construct a string _size long with all characters set to _character.
 String (const std::string &_value="")
 Default constructor, an optional initial value can be given.
template<typename T1>
 String (const String &format, T1 arg1)
 Construct a string with the value format, where 1 is replaced with the arg1.
template<typename T1, typename T2>
 String (const String &format, T1 arg1, T2 arg2)
template<typename T1, typename T2, typename T3>
 String (const String &format, T1 arg1, T2 arg2, T3 arg3)
template<typename T1, typename T2, typename T3, typename T4>
 String (const String &format, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
template<typename T1, typename T2, typename T3, typename T4, typename T5>
 String (const String &format, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
template<typename T>
void operator= (T _value)
String replace (const std::string &a, const std::string &b) const
 Replace all instances of a with b in this string and return the resulting string.
String rstrip (const std::string &_letters=" \t\n\r") const
 Works like strip, but only removes postfixed characters.
String lstrip (const std::string &_letters=" \t\n\r") const
 Works like strip, but only removes prefixed characters.
String strip (const std::string &_letters=" \t\n\r") const
 Return a string where all prefixed and postfixed characters in _letters have been removed.
template<typename TInsertIterator>
void split (TInsertIterator &_ii, const std::string &_delimiters) const
 Split this string into a smaller strings based on the _delimiters given.
StringList split (const std::string &_delimiters=" \t\n\r") const
 Convenience split method which returns a StringList without the client having to bother with creating an insert iterator.
bool isAlpha () const
 Returns true if all characters of the string are alphabetic characters (as determined by std::isalpha).
bool isAlphaNumeric () const
 Returns true if all characters of the string are alpha-numeric characters (as determined by std::isalnum).
bool isUpper () const
 Returns true if all characters of the string are upper-case (as determined by std::isupper).
bool isLower () const
 Returns true if all characters of the string are lower-case characters (as determined by std::islower).
bool isDigits () const
 Returns true if all characters of the string are digits (as determined by std::isdigit).
bool isWhitespace () const
 Returns true if all characters of the string are whitespace characters (as determined by std::isspace).
bool isHexadecimal () const
 Returns true if all characters of the string are hexadecimal characters (as determined by std::isxdigit).
String capitalize () const
 Return a capitalized version of the given string (the first character is upper-case'ed, the rest are lower-case'ed).
String upper () const
 Return a lower case version of this string.
String lower () const
 Return a lower case version of this string.
std::string::value_type & operator[] (int _index)
 Return the character at position _index.
std::string::value_type operator[] (int _index) const
 Contant version of operator[].

Static Public Member Functions

template<typename ListType>
static String join (const ListType &_list, const String &_seperator)
 Convenience method for joining STL containers, and other containers supporting the begin() to end() STL iterator design.
template<typename IteratorType>
static String join (const IteratorType &_begin, const IteratorType &_end, const String &_seperator)
 Return a string with the values from _begin to _end, seperated by _seperator.


Detailed Description

String class with several ease-of-use methods, roughly mimicking Python's string class.

Constructor & Destructor Documentation

template<typename T>
net::halfdans::String::String ( _value  )  [inline]

Construct a string equal to _value converted to a string using operator<<.

net::halfdans::String::String ( size_type  _size,
value_type  _character 
) [inline, explicit]

Construct a string _size long with all characters set to _character.

net::halfdans::String::String ( const std::string &  _value = ""  )  [inline, explicit]

Default constructor, an optional initial value can be given.

template<typename T1>
net::halfdans::String::String ( const String format,
T1  arg1 
) [inline, explicit]

Construct a string with the value format, where 1 is replaced with the arg1.

This constructor comes in 5 flavors, for taking from 1 to 5 parameters, named 1 to 5

template<typename T1, typename T2>
net::halfdans::String::String ( const String format,
T1  arg1,
T2  arg2 
) [inline, explicit]

See also:
String ( const String & format, T1 arg1 )

template<typename T1, typename T2, typename T3>
net::halfdans::String::String ( const String format,
T1  arg1,
T2  arg2,
T3  arg3 
) [inline, explicit]

See also:
String ( const String & format, T1 arg1 )

template<typename T1, typename T2, typename T3, typename T4>
net::halfdans::String::String ( const String format,
T1  arg1,
T2  arg2,
T3  arg3,
T4  arg4 
) [inline, explicit]

See also:
String ( const String & format, T1 arg1 )

template<typename T1, typename T2, typename T3, typename T4, typename T5>
net::halfdans::String::String ( const String format,
T1  arg1,
T2  arg2,
T3  arg3,
T4  arg4,
T5  arg5 
) [inline, explicit]

See also:
String ( const String & format, T1 arg1 )


Member Function Documentation

template<typename T>
void net::halfdans::String::operator= ( _value  )  [inline]

See also:
String ( T _value )

String net::halfdans::String::replace ( const std::string &  a,
const std::string &  b 
) const [inline]

Replace all instances of a with b in this string and return the resulting string.

String net::halfdans::String::rstrip ( const std::string &  _letters = " \t\n\r"  )  const [inline]

Works like strip, but only removes postfixed characters.

String net::halfdans::String::lstrip ( const std::string &  _letters = " \t\n\r"  )  const [inline]

Works like strip, but only removes prefixed characters.

String net::halfdans::String::strip ( const std::string &  _letters = " \t\n\r"  )  const [inline]

Return a string where all prefixed and postfixed characters in _letters have been removed.

   assert ( Strip("..test..").strip() == "test" );

template<typename TInsertIterator>
void net::halfdans::String::split ( TInsertIterator &  _ii,
const std::string &  _delimiters 
) const [inline]

Split this string into a smaller strings based on the _delimiters given.

This method behaves like Python's split method and returns empty items if several delimiters are positioned next to each other.

   // Returns three items: 1, 2 and 3
   String("1,2,3").split();
   // Returns four items 1, 2, the empty string and 3
   String("1,2,,3").split();

If you use the StringList to hold the returned values, you can use StringList::stripAndPurgeEmpty() to remove the excess empty values.

StringList net::halfdans::String::split ( const std::string &  _delimiters = " \t\n\r"  )  const [inline]

Convenience split method which returns a StringList without the client having to bother with creating an insert iterator.

See also:
void split ( TInsertIterator & _ii, const std::string & _delimiters )

bool net::halfdans::String::isAlpha (  )  const [inline]

Returns true if all characters of the string are alphabetic characters (as determined by std::isalpha).

bool net::halfdans::String::isAlphaNumeric (  )  const [inline]

Returns true if all characters of the string are alpha-numeric characters (as determined by std::isalnum).

bool net::halfdans::String::isUpper (  )  const [inline]

Returns true if all characters of the string are upper-case (as determined by std::isupper).

bool net::halfdans::String::isLower (  )  const [inline]

Returns true if all characters of the string are lower-case characters (as determined by std::islower).

bool net::halfdans::String::isDigits (  )  const [inline]

Returns true if all characters of the string are digits (as determined by std::isdigit).

bool net::halfdans::String::isWhitespace (  )  const [inline]

Returns true if all characters of the string are whitespace characters (as determined by std::isspace).

bool net::halfdans::String::isHexadecimal (  )  const [inline]

Returns true if all characters of the string are hexadecimal characters (as determined by std::isxdigit).

String net::halfdans::String::capitalize (  )  const [inline]

Return a capitalized version of the given string (the first character is upper-case'ed, the rest are lower-case'ed).

String net::halfdans::String::upper (  )  const [inline]

Return a lower case version of this string.

String net::halfdans::String::lower (  )  const [inline]

Return a lower case version of this string.

std::string::value_type& net::halfdans::String::operator[] ( int  _index  )  [inline]

Return the character at position _index.

Support Python-like negative indexes to index characters by their position from the end of the string, rather than from the beginning.

See code example, python docs or hstring's test-cases for a more detailed explanation.

   String test ( "test" );
   assert ( test[0] == 't' );
   assert ( test[1] == 'e' );
   assert ( test[-1] == 't' );
   assert ( test[-2] == 's' );

std::string::value_type net::halfdans::String::operator[] ( int  _index  )  const [inline]

Contant version of operator[].

See also:
std::string::value_type & operator[] ( int _index )

template<typename ListType>
static String net::halfdans::String::join ( const ListType &  _list,
const String _seperator 
) [inline, static]

Convenience method for joining STL containers, and other containers supporting the begin() to end() STL iterator design.

See also:
static String join ( const IteratorType & _begin, const IteratorType & _end, const String & _seperator )

template<typename IteratorType>
static String net::halfdans::String::join ( const IteratorType &  _begin,
const IteratorType &  _end,
const String _seperator 
) [inline, static]

Return a string with the values from _begin to _end, seperated by _seperator.

   // List is "1", "2", "3", "4", "5"
   StringList list;
   String result;
   result = String::join(list.begin(), list.end(), "#");
   assert ( result == "1#2#3#4#5" );


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

Generated on Thu Jul 10 23:30:20 2008 for hstring by  doxygen 1.5.6