org::xmlBlaster::util::StringTrim Class Reference

This template class is used to trim a std::string the same way the String.trim java method does. More...

List of all members.

Public Member Functions

 StringTrim ()
 Default constructor.

Static Public Member Functions

static std::string & toLowerCase (std::string &ref)
 This method converts a string to lowercase.
static std::string replaceAll (std::string &str, std::string &from, std::string &to)
 Replace all occurrences of "from" with to "to".
static bool isTrue (std::string &str)
 Checks string to be interpreted as true.
static bool isTrue (std::string &str, bool def)
 Evaluate trimmed boolean string.
static bool isTrueTrim (std::string &str)
 Use this method instead of isTrue(std::string&) if your input std::string may be manipulated (it performs a bit better then the other method).
static std::string trimStart (char *str)
 Trims the start of the std::string (whitespaces, newlines etc.
static std::string & trimStart (std::string &str)
 
Parameters:
str The given std::string will be trimmed (in - out parameter)

static std::string trimEnd (char *str)
 Trims all spaces from the end of the std::string (whitespaces, newlines etc).
static std::string & trimEnd (std::string &str)
 
Parameters:
str The given std::string will be trimmed (in - out parameter)

static std::string trim (char *str)
 Trims all spaces (like blanks and newlines) at the start and the end of the std::string.
static void trim (std::string &str)
 
Parameters:
str The given std::string will be trimmed (in - out parameter)

static std::string trim (std::string &str)


Detailed Description

This template class is used to trim a std::string the same way the String.trim java method does.

It can be instantiated with which character type you want and will therefore work even with xerces XMLCh* std::strings. This class is part of the package because the XMLString::trim(...) method in the xerces package does not fullfill our requirements.

Definition at line 31 of file StringTrim.h.


Constructor & Destructor Documentation

org::xmlBlaster::util::StringTrim::StringTrim (  ) 

Default constructor.

Does nothing

Definition at line 38 of file StringTrim.h.


Member Function Documentation

static std::string& org::xmlBlaster::util::StringTrim::toLowerCase ( std::string &  ref  )  [static]

This method converts a string to lowercase.

Note that the input string is modified and a reference to it is returned.

Definition at line 46 of file StringTrim.h.

static std::string org::xmlBlaster::util::StringTrim::replaceAll ( std::string &  str,
std::string &  from,
std::string &  to 
) [static]

Replace all occurrences of "from" with to "to".

Definition at line 59 of file StringTrim.h.

Referenced by org::xmlBlaster::client::qos::SubscribeQos::generateSubscriptionId().

static bool org::xmlBlaster::util::StringTrim::isTrue ( std::string &  str  )  [static]

Checks string to be interpreted as true.

If you don't need trimming please use lexical_cast<bool>(str) instead of this method.

Parameters:
str The checked std::string (is not modified)
Returns:
true if trimmed std::string is "TRUE" or "true" or "1" else false

Definition at line 88 of file StringTrim.h.

References org::xmlBlaster::util::lexical_cast().

static bool org::xmlBlaster::util::StringTrim::isTrue ( std::string &  str,
bool  def 
) [static]

Evaluate trimmed boolean string.

Parameters:
str The checked std::string (is not modified)
def Default value to use if str not one of described below
Returns:
true if trimmed std::string is "TRUE" or "true" or "1" else false false if trimmed "0", "false", "FALSE"

Definition at line 100 of file StringTrim.h.

static bool org::xmlBlaster::util::StringTrim::isTrueTrim ( std::string &  str  )  [static]

Use this method instead of isTrue(std::string&) if your input std::string may be manipulated (it performs a bit better then the other method).

NOTE: It returns true if the str is empty, this is nice for SAX parse where <persistent> also triggers an endElement() with empty character_ and means 'true'.

Parameters:
str The checked std::string (is trimmed!!)
Returns:
true if trimmed std::string is "TRUE" or "true" or "1" or "" else false

Definition at line 116 of file StringTrim.h.

References org::xmlBlaster::util::lexical_cast().

static std::string org::xmlBlaster::util::StringTrim::trimStart ( char *  str  )  [static]

Trims the start of the std::string (whitespaces, newlines etc.

).

Definition at line 138 of file StringTrim.h.

References EMPTY_STRING.

Referenced by org::xmlBlaster::test::TestStringTrim::testTrim().

static std::string& org::xmlBlaster::util::StringTrim::trimStart ( std::string &  str  )  [static]

Parameters:
str The given std::string will be trimmed (in - out parameter)

Parameters:
Returns the trimmed given parameter (the str instance)
See also:
trimStart(const char *)

Definition at line 158 of file StringTrim.h.

static std::string org::xmlBlaster::util::StringTrim::trimEnd ( char *  str  )  [static]

Trims all spaces from the end of the std::string (whitespaces, newlines etc).

Definition at line 180 of file StringTrim.h.

References EMPTY_STRING.

Referenced by org::xmlBlaster::test::TestStringTrim::testTrim().

static std::string& org::xmlBlaster::util::StringTrim::trimEnd ( std::string &  str  )  [static]

Parameters:
str The given std::string will be trimmed (in - out parameter)

Parameters:
Returns the trimmed given parameter (the str instance)
See also:
trimEnd(const char *)

Definition at line 193 of file StringTrim.h.

References EMPTY_STRING.

static std::string org::xmlBlaster::util::StringTrim::trim ( char *  str  )  [static]

Trims all spaces (like blanks and newlines) at the start and the end of the std::string.

 "  \t Hello \t World \n" -> "Hello \t World"
 
Parameters:
str The given std::string
Returns:
The trimmed std::string

Definition at line 217 of file StringTrim.h.

References EMPTY_STRING.

Referenced by org::xmlBlaster::util::parser::Sax2Parser::getStringValue(), and org::xmlBlaster::test::TestStringTrim::testTrim().

static void org::xmlBlaster::util::StringTrim::trim ( std::string &  str  )  [static]

Parameters:
str The given std::string will be trimmed (in - out parameter)

Parameters:
Returns the trimmed given parameter (the str instance)
See also:
trim(const char *)

Definition at line 229 of file StringTrim.h.

References EMPTY_STRING.

static std::string org::xmlBlaster::util::StringTrim::trim ( std::string &  str  )  [static]

Definition at line 257 of file StringTrim.h.


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