Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

string_util Namespace Reference

some common string processing functions, for std::string More...

Functions

char localeToUpper (char c)
 uses the standard library's "locale" to convert case of a single character
char localeToLower (char c)
 uses the standard library's "locale" to convert case of a single character
string makeUpper (const std::string &s) ATTR_must_check
 returns upper case version of s
string makeLower (const std::string &s) ATTR_must_check
 returns lower case version of s
string removePrefix (const std::string &str, const std::string &pre) ATTR_must_check
 returns str with pre removed - if pre is not fully matched, str is returned unchanged
string tildeExpansion (const std::string &str) ATTR_must_check
 replaces ~USER prefix with specified user's home directory, or ~ prefix with current HOME environment setting; returns str if no valid expansion is found
string trim (const std::string &str) ATTR_must_check
 removes whitespace (as defined by isspace()) from the beginning and end of str, and returns the result
bool beginsWith (const std::string &str, const std::string &prefix)
 returns true if str begins with prefix
bool endsWith (const std::string &str, const std::string &suffix)
 returns true if str ends with suffix
std::string makePath (const std::string &rel, const std::string &path)
 Returns tgt if it is an absolute path or rel is empty, otherwise drops trailing file (if any) from rel and appends tgt.
std::vector< std::string > tokenize (const std::string &str, const std::string &delims=", \t")
 convert input string into vector of string tokens
bool parseArgs (const std::string &input, std::vector< std::string > &args, std::vector< unsigned int > &offsets)
 parses the input string into an arg list, with corresponding offsets of each arg in the original input
bool reMatch (const std::string &str, const std::string &regex)
 returns true if str matches re (assumes 'extended' regular expression, not 'basic'), false otherwise and throws std::string message on error
bool reMatch (const std::string &str, const std::string &regex, int flags)
 returns true if str matches re (with optional flags to control interpretation), false otherwise and throws std::string message on error
std::string intToStringIP (int ip)
 Converts a int representation of an IP to a string.
int stringToIntIP (std::string ip)
 Converts a string representation of an IP to an int.
size_t utf8len (const std::string &str)
 returns the number of utf8 code points found in the string
std::string demangle (const std::string &symbol)
 returns demangled version of a symbol name
std::string int2str (int const n)
 convert int to string so robot can speak numbers

Variables

static const std::locale & curLocale = std::locale::classic()
 reference to the current standard library 'locale'

Detailed Description

some common string processing functions, for std::string


Function Documentation

bool string_util::beginsWith ( const std::string &  str,
const std::string &  prefix 
)

returns true if str begins with prefix

std::string string_util::demangle ( const std::string &  symbol  ) 
bool string_util::endsWith ( const std::string &  str,
const std::string &  suffix 
)

returns true if str ends with suffix

std::string string_util::int2str ( int const   n  ) 

convert int to string so robot can speak numbers

std::string string_util::intToStringIP ( int  ip  ) 
char string_util::localeToLower ( char  c  ) 

uses the standard library's "locale" to convert case of a single character

char string_util::localeToUpper ( char  c  ) 

uses the standard library's "locale" to convert case of a single character

std::string string_util::makePath ( const std::string &  rel,
const std::string &  path 
)

Returns tgt if it is an absolute path or rel is empty, otherwise drops trailing file (if any) from rel and appends tgt.

This assumes final path component is a source file, referencing a self-relative path, so make sure rel is a path to a file, or has a trailing '/' otherwise the final directory component will be stripped. (Doesn't actually do any disk operations to test for the file.)

std::string string_util::makeUpper ( const string &  s  ) 

returns upper case version of s

Referenced by LogNode::postStart(), and WalkCalibration::setupReady().

bool string_util::parseArgs ( const string &  input,
vector< string > &  args,
vector< unsigned int > &  offsets 
)

parses the input string into an arg list, with corresponding offsets of each arg in the original input

Referenced by EchoBehavior::doEvent(), ControlBase::takeInput(), and Controller::takeLine().

bool string_util::reMatch ( const std::string &  str,
const std::string &  regex,
int  flags 
)

returns true if str matches re (with optional flags to control interpretation), false otherwise and throws std::string message on error

Parameters:
str The string to match
regex The regular expression which should be parsed and executed
flags pass flags for regex (e.g. REG_EXTENDED)

This compiles the regex and then executes it... for repeated usage of the same regular expression, you could be better off compiling it yourself and using the regex library directly.

bool string_util::reMatch ( const std::string &  str,
const std::string &  regex 
)

returns true if str matches re (assumes 'extended' regular expression, not 'basic'), false otherwise and throws std::string message on error

Parameters:
str The string to match
regex The (extended) regular expression which should be parsed and executed

This compiles the regex and then executes it... for repeated usage of the same regular expression, you could be better off compiling it yourself and using the regex library directly.

Referenced by PostureEngine::loadLine().

std::string string_util::removePrefix ( const string &  str,
const string &  pre 
)

returns str with pre removed - if pre is not fully matched, str is returned unchanged

int string_util::stringToIntIP ( std::string  ip_str  ) 

Converts a string representation of an IP to an int.

std::string string_util::tildeExpansion ( const string &  str  ) 

replaces ~USER prefix with specified user's home directory, or ~ prefix with current HOME environment setting; returns str if no valid expansion is found

Referenced by LogNode::postStart().

std::vector< std::string > string_util::tokenize ( const std::string &  str,
const std::string &  delims = ", \t" 
)

convert input string into vector of string tokens

Parameters:
input string to be parsed
delims list of delimiters.

Consecutive delimiters will be treated as single delimiter, delimiters are not included in return data. Thanks http://www.rosettacode.org/wiki/Tokenizing_A_String#C.2B.2B

Referenced by Kinematics::getInterestPoint(), and plist::RGBColor< T >::set().

std::string string_util::trim ( const string &  str  ) 
size_t string_util::utf8len ( const std::string &  str  ) 

returns the number of utf8 code points found in the string

This does not do any verification of the validity of the codepoints.

Referenced by plist::DictionaryBase::saveXMLNode().


Variable Documentation

const std::locale& string_util::curLocale = std::locale::classic() [static]

reference to the current standard library 'locale'

Definition at line 19 of file string_util.cc.


Tekkotsu v5.1CVS
Generated Mon May 9 04:59:26 2016 by Doxygen 1.6.3