CARMA C++
carma::util::StringUtils Class Reference

Common string functions Additional string-related functions can be added here. More...

#include <carma/util/StringUtils.h>

Public Types

typedef enum
carma::util::StringUtils::sortTypeEnum 
sortType
 Sort type for sort( std::string, sortType ) method. More...
 
enum  sortTypeEnum { ASCENDING_SORT, DESCENDING_SORT }
 

Public Member Functions

 StringUtils ()
 Default constructor. More...
 
static::std::vector
< ::std::string > 
tokenize (const ::std::string &str, const ::std::string &delimiterSet=" ", bool skipNull=true)
 split a string into substrings based on a delimiter character set More...
 
static::std::vector
< ::std::string > 
tokenizeN (const ::std::string &str, const size_t maxTokens, const ::std::string &delimiterSet=" ", bool skipNull=true)
 split a string into substrings based on a delimiter character set stopping if a maximum number of substrings is found More...
 
virtual ~StringUtils ()
 Destructor. More...
 

Static Public Member Functions

::std::string collapse (const ::std::string &str, const ::std::vector< char > &chars)
 collapse consecutive repeats of a single character in specified character list to a single character More...
 
::std::string collapse (const ::std::string &str, char c)
 collapse consecutive repeats of a single character in specified character list to a single character More...
 
::std::string computeMessageDigest (const ::std::string &str, DigestType digestType)
 compute the specified message digest for the specified string More...
 
static bool containsOnly (const ::std::string &str, const ::std::string &allowedChars)
 Checks that the input string is made up of only the characters from a given list. More...
 
::std::string dms (double angle, int precision=3)
 
static bool equalsIgnoreCase (const std::string &aString, const std::string &anotherString)
 Compares two strings, ignoring case considerations. More...
 
::std::string erase (const ::std::string &str, const ::std::vector< char > &chars)
 erase specified characters from a string More...
 
::std::string hms (double angle, int precision=2)
 convert a number into sexadecimal HMS/DMS notation, with or without a sign [+/-]HH:MM:SS.ss or [+/-]DDD:MM:SS.sss (precision# digits) More...
 
static bool isEmptyOrContainsWhiteSpace (const ::std::string &s)
 
::std::string lowASCIIAlphaNumericToLower (const ::std::string &str)
 convert a string containing low ASCII alphanumeric and punctionation characters (unicode 0x20 to 0x7E) to lower case More...
 
::std::string lowASCIIAlphaNumericToUpper (const ::std::string &str)
 convert a string containing low ASCII alphanumeric and punctionation characters (unicode 0x20 to 0x7E) to upper case More...
 
static bool miniGlob (const char *pattern, const char *checkString)
 
::std::string reallyUniq (const ::std::string &str)
 
::std::string replace (const ::std::string &str, const ::std::string &origStr, const ::std::string &replStr)
 replace a substring within a string with another substring More...
 
::std::string sdms (double angle, int precision=3)
 
::std::string sexa (double angle, bool sign, bool hms, int precision)
 
::std::string shms (double angle, int precision=2)
 
::std::string sort (const ::std::string &str, const sortType direction=ASCENDING_SORT)
 
static int stringToInt (const ::std::string &str)
 convert a string representation of an integer to an int More...
 
static void tokenizeInplace (::std::vector< ::std::string > &tokens, const ::std::string &str, const ::std::string &delimiterSet=" ", bool skipNull=true)
 split a string into substrings based on a delimiter character set More...
 
static void tokenizeNInplace (::std::vector< ::std::string > &tokens, const ::std::string &str, const size_t maxTokens, const ::std::string &delimiterSet=" ", bool skipNull=true)
 split a string into substrings based on a delimiter character set stopping if a maximum number of substrings is found More...
 
static void toLower (::std::vector< ::std::string > &v)
 In place conversion of a vector of string to lower case. More...
 
static void toUpper (::std::vector< ::std::string > &v)
 In place conversion of a vector of string to upper case. More...
 
::std::string trim (const ::std::string &str, const ::std::string &chars)
 erase specified characters from the beginning and end of a string More...
 
static void trimInplace (::std::string &str, const ::std::string &chars)
 erase specified characters from the beginning and end of a string More...
 
::std::string trimWhiteSpace (const ::std::string &str)
 Erase whitespace (' ',
,,) from beginning and end of string. More...
 
static void trimWhiteSpaceInplace (::std::string &str)
 Erase whitespace (' ',
,,) from beginning and end of string. More...
 
::std::string uniq (const ::std::string &str)
 

Detailed Description

Common string functions Additional string-related functions can be added here.

This class contains no state.

Definition at line 94 of file StringUtils.h.

Member Typedef Documentation

Sort type for sort( std::string, sortType ) method.

Member Enumeration Documentation

Enumerator
ASCENDING_SORT 

do an ascending sort

DESCENDING_SORT 

do an descending sort

Definition at line 101 of file StringUtils.h.

Constructor & Destructor Documentation

carma::util::StringUtils::StringUtils ( )

Default constructor.

virtual carma::util::StringUtils::~StringUtils ( )
virtual

Destructor.

Member Function Documentation

::std::string carma::util::StringUtils::collapse ( const ::std::string &  str,
const ::std::vector< char > &  chars 
)
static

collapse consecutive repeats of a single character in specified character list to a single character

"abc         def" -> "abc def"
Parameters
strthe string from which to collapse characters
charscharacters to collapse
Returns
string with the specified characters collapsed
::std::string carma::util::StringUtils::collapse ( const ::std::string &  str,
char  c 
)
static

collapse consecutive repeats of a single character in specified character list to a single character

"abc         def" -> "abc def"
Parameters
strthe string from which to collapse characters
crepeated character to collapse
Returns
string with the specified characters collapsed
::std::string carma::util::StringUtils::computeMessageDigest ( const ::std::string &  str,
DigestType  digestType 
)
static

compute the specified message digest for the specified string

Parameters
strthe string for which to compute the digest
digestTypethe type of digest to compute
Returns
the message digest
static bool carma::util::StringUtils::containsOnly ( const ::std::string &  str,
const ::std::string &  allowedChars 
)
static

Checks that the input string is made up of only the characters from a given list.

Match is case-insensitive.

Parameters
strthe string to check
allowedCharsstring containing characters allowed in str
Returns
true if the string is made up of only characters in the chars vector, false otherwise.
true if str is empty, because empty is a proper subset of anything.
false if allowedChars is empty and str is anything except empty
static bool carma::util::StringUtils::equalsIgnoreCase ( const std::string &  aString,
const std::string &  anotherString 
)
static

Compares two strings, ignoring case considerations.

Two strings are considered equal ignoring case if they are of the same length, and corresponding characters in the two strings are equal ignoring case.

Parameters
aStringFirst string to compare
anotherStringSecond string to compare
Returns
true if the strings are equal ignoring case, false otherwise.
::std::string carma::util::StringUtils::erase ( const ::std::string &  str,
const ::std::vector< char > &  chars 
)
static

erase specified characters from a string

Parameters
strthe string from which to remove characters
charscharacters to remove
Returns
string with the specified characters erased
::std::string carma::util::StringUtils::hms ( double  angle,
int  precision = 2 
)
static

convert a number into sexadecimal HMS/DMS notation, with or without a sign [+/-]HH:MM:SS.ss or [+/-]DDD:MM:SS.sss (precision# digits)

static bool carma::util::StringUtils::isEmptyOrContainsWhiteSpace ( const ::std::string &  s)
static
Returns
true if the input string contains the a white space character or is an empty string, false otherwise these are illegal chars for an obsblock ID.
Parameters
sThe input string to check
::std::string carma::util::StringUtils::lowASCIIAlphaNumericToLower ( const ::std::string &  str)
static

convert a string containing low ASCII alphanumeric and punctionation characters (unicode 0x20 to 0x7E) to lower case

Parameters
strThe string to be converted
Returns
the converted string
Exceptions
out_of_rangeif any character in the input string is not in the range 0x20 to 0x7E
::std::string carma::util::StringUtils::lowASCIIAlphaNumericToUpper ( const ::std::string &  str)
static

convert a string containing low ASCII alphanumeric and punctionation characters (unicode 0x20 to 0x7E) to upper case

Parameters
strThe string to be converted
Returns
the converted string
Exceptions
out_of_rangeif any character in the input string is not in the range 0x20 to 0x7E
::std::string carma::util::StringUtils::reallyUniq ( const ::std::string &  str)
static
Returns
the input string after eliminating any duplicate characters. Check is case-sensitive, e.g. 'U' is not a duplicate of 'u'. Example: input = abcdcefffghgi, output = abcdefghi
::std::string carma::util::StringUtils::replace ( const ::std::string &  str,
const ::std::string &  origStr,
const ::std::string &  replStr 
)
static

replace a substring within a string with another substring

Parameters
strthe string
origSubstrthe original substring to replace
replSubstrthe replacement substring
Returns
the resulting string
::std::string carma::util::StringUtils::sort ( const ::std::string &  str,
const sortType  direction = ASCENDING_SORT 
)
static
Returns
the input string sorted lexigraphically.
Parameters
strThe string to sort
directionEnum value indicating whether to do an ascending or descending sort. Default is ascending sort.
static int carma::util::StringUtils::stringToInt ( const ::std::string &  str)
static

convert a string representation of an integer to an int

* stringToInt("5893");
*

returns 5893

* stringToInt("5893z");
*

throws a carma::util::IllegalArgumentException

Parameters
strthe string representation of the int
Returns
the integer represented by the string
Exceptions
carma::util::IllegalArgumentExceptionif str isn't really the string representation of an int
static ::std::vector< ::std::string > carma::util::StringUtils::tokenize ( const ::std::string &  str,
const ::std::string &  delimiterSet = " ",
bool  skipNull = true 
)

split a string into substrings based on a delimiter character set

Parameters
strthe input string to tokenize
delimiterSetthe delimiter character set to use to tokenize the string
skipNullskip null tokens if true
Returns
vector of split substrings
static void carma::util::StringUtils::tokenizeInplace ( ::std::vector< ::std::string > &  tokens,
const ::std::string &  str,
const ::std::string &  delimiterSet = " ",
bool  skipNull = true 
)
static

split a string into substrings based on a delimiter character set

Parameters
tokensvector that will be filled in with the split substrings
strthe input string to tokenize
delimiterSetthe delimiter character set to use to tokenize the string
skipNullskip null tokens if true
static ::std::vector< ::std::string > carma::util::StringUtils::tokenizeN ( const ::std::string &  str,
const size_t  maxTokens,
const ::std::string &  delimiterSet = " ",
bool  skipNull = true 
)

split a string into substrings based on a delimiter character set stopping if a maximum number of substrings is found

Parameters
strthe input string to tokenize
maxTokensmaximum number of tokens to stop after
delimiterSetthe delimiter character set to use to tokenize the string
skipNullskip null tokens if true
Returns
vector of split substrings
static void carma::util::StringUtils::tokenizeNInplace ( ::std::vector< ::std::string > &  tokens,
const ::std::string &  str,
const size_t  maxTokens,
const ::std::string &  delimiterSet = " ",
bool  skipNull = true 
)
static

split a string into substrings based on a delimiter character set stopping if a maximum number of substrings is found

Parameters
tokensvector that will be filled in with the split substrings
strthe input string to tokenize
maxTokensmaximum number of tokens to stop after
delimiterSetthe delimiter character set to use to tokenize the string
skipNullskip null tokens if true
static void carma::util::StringUtils::toLower ( ::std::vector< ::std::string > &  v)
static

In place conversion of a vector of string to lower case.

Parameters
vThe vector<string> to be converted
See Also
lowASCIIAlphaNumericToLower(const ::std::string& str);
static void carma::util::StringUtils::toUpper ( ::std::vector< ::std::string > &  v)
static

In place conversion of a vector of string to upper case.

Parameters
vThe vector<string> to be converted
See Also
lowASCIIAlphaNumericToUpper(const ::std::string& str);
::std::string carma::util::StringUtils::trim ( const ::std::string &  str,
const ::std::string &  chars 
)
static

erase specified characters from the beginning and end of a string

Parameters
strthe string from which to remove characters
charsString with characters to remove from the beginning and end
Returns
string with the specified characters trimmed
static void carma::util::StringUtils::trimInplace ( ::std::string &  str,
const ::std::string &  chars 
)
static

erase specified characters from the beginning and end of a string

Parameters
strthe string from which to remove characters
charscharacters to remove from the beginning and end
::std::string carma::util::StringUtils::trimWhiteSpace ( const ::std::string &  str)
static

Erase whitespace (' ',
,,) from beginning and end of string.

This method calls StringUtils::trim(const ::std::string&,const ::std::vector<char>&) with an appropriate set of chars.

Parameters
strthe string from which to remove characters
Returns
string with the white space trimmed
static void carma::util::StringUtils::trimWhiteSpaceInplace ( ::std::string &  str)
static

Erase whitespace (' ',
,,) from beginning and end of string.

This method calls trim with the above set of chars.

Parameters
strthe string from which to remove characters
::std::string carma::util::StringUtils::uniq ( const ::std::string &  str)
static
Returns
the input string after eliminating adjacent duplicate characters. Check is case-sensitive, e.g. 'U' is not a duplicate of 'u'. Example: input = abcdcefffghgi, output = abcdcefghgi

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