RobWorkProject  23.9.11-
Static Public Member Functions | Related Functions | List of all members
StringUtil Class Reference

Collection of string manipulation utilities. More...

#include <StringUtil.hpp>

Static Public Member Functions

static bool isAbsoluteFileName (const std::string &file)
 True if the file name file is an absolute file name.
 
static std::string replaceBackslash (const std::string &file)
 Replace '\' with '/' everywhere in the file name file.
 
static std::string removeWhiteSpace (const std::string &str)
 Removes space, tab and new line from string.
 
static std::string getDirectoryName (const std::string &path)
 The directory part of a path name. More...
 
static std::string getRelativeDirectoryName (const std::string &path, std::string dir_name)
 The directory part of a path name relative to a root directory. More...
 
static std::string getFileName (const std::string &pathAndFileName)
 Extract the file name (including extension) from a string containing full name including the directory. More...
 
static std::string getFileExtension (const std::string &filename)
 The extension of a file name. More...
 
static std::string toUpper (const std::string &str)
 The uppercase of a string. More...
 
static std::string toLower (const std::string &str)
 The lowercase of a string. More...
 
static std::string quote (const std::string &str)
 The string str enclosed in single-quotes. More...
 
static std::vector< std::string > words (const std::string &str)
 Split str into words at space borders.
 
static std::pair< bool, double > toDouble (const std::string &str)
 Return (true, val) if str parses as a double with value val and (false, 0) otherwise.
 
static std::pair< bool, int > toInt (const std::string &str)
 Return (true, val) if str parses as a int with value val and (false, 0) otherwise.
 
static std::pair< bool, unsigned int > toUInt (const std::string &str)
 Return (true, val) if str parses as a int with value val and (false, 0) otherwise.
 
static std::pair< bool, long > toLong (const std::string &str)
 Return (true, val) if str parses as a int with value val and (false, 0) otherwise.
 
static std::pair< bool, unsigned long > toULong (const std::string &str)
 Return (true, val) if str parses as a int with value val and (false, 0) otherwise.
 
static std::pair< bool, std::vector< double > > toDoubles (const std::vector< std::string > &words)
 Return (true, vals) if words parses as a sequence of doubles with values vals and (false, []) otherwise.
 
static std::pair< bool, std::vector< int > > toInts (const std::vector< std::string > &words)
 Return (true, vals) if words parses as a sequence of ints with values vals and (false, []) otherwise.
 
static std::pair< bool, std::vector< unsigned int > > toUInts (const std::vector< std::string > &words)
 Return (true, vals) if words parses as a sequence of ints with values vals and (false, []) otherwise.
 
static std::pair< bool, std::vector< long > > toLongs (const std::vector< std::string > &words)
 Return (true, vals) if words parses as a sequence of ints with values vals and (false, []) otherwise.
 
static std::pair< bool, std::vector< unsigned long > > toULongs (const std::vector< std::string > &words)
 Return (true, vals) if words parses as a sequence of ints with values vals and (false, []) otherwise.
 
static std::string patternToRegEx (const std::string &pattern)
 Converts a string pattern with wild card characters * and ? into a regular expression. More...
 
static std::string ranName (const std::string &prefix)
 creates a name based on a prefix and a random integer between 0xFF and 0xFFFFFF More...
 

Related Functions

(Note that these are not member functions.)

typedef std::pair< std::string, std::string > StringPair
 Convenient definition of a pair of strings.
 
typedef std::vector< StringPairStringPairList
 Convenient definition of a list of string pairs.
 

Detailed Description

Collection of string manipulation utilities.

Member Function Documentation

◆ getDirectoryName()

static std::string getDirectoryName ( const std::string &  path)
static

The directory part of a path name.

The function simply returns everything up to and including the last slash or backslash. If there is no such slash or backslash, the empty string is returned.

Parameters
path[in] The path name.
Returns
The directory name for the path.

◆ getFileExtension()

static std::string getFileExtension ( const std::string &  filename)
static

The extension of a file name.

The extension is everything that follows the last '.'.

The '.' is included in the extension returned, so that if that if the file has no extension, then the empty string can be returned.

Parameters
filename[in] The file name.
Returns
The file name extension.

◆ getFileName()

static std::string getFileName ( const std::string &  pathAndFileName)
static

Extract the file name (including extension) from a string containing full name including the directory.

The function simply returns everything efter the last slash or backslash. If there is no such slash or backslash, the original string is returned

Parameters
pathAndFileName[in] The path and filename .
Returns
The file name.

◆ getRelativeDirectoryName()

static std::string getRelativeDirectoryName ( const std::string &  path,
std::string  dir_name 
)
static

The directory part of a path name relative to a root directory.

The function returns everything up to and including the last slash or backslash. If there is no such slash or backslash, the empty string is returned.

Parameters
path[in] The path name.
dir_name[in] The root directory name.
Returns
The relative directory name for the path.

◆ patternToRegEx()

static std::string patternToRegEx ( const std::string &  pattern)
static

Converts a string pattern with wild card characters * and ? into a regular expression.

The format of the regular expression matches std::regex.

Parameters
pattern[in] pattern with wild card characters
Returns
patterns expressed as regular expression.

◆ quote()

static std::string quote ( const std::string &  str)
static

The string str enclosed in single-quotes.

Use this for quoting of strings in user error messages.

◆ ranName()

static std::string ranName ( const std::string &  prefix)
static

creates a name based on a prefix and a random integer between 0xFF and 0xFFFFFF

Parameters
prefix
Returns

◆ toLower()

static std::string toLower ( const std::string &  str)
static

The lowercase of a string.

Parameters
str[in] A string to lowercase.
Returns
str converted to lower case.

◆ toUpper()

static std::string toUpper ( const std::string &  str)
static

The uppercase of a string.

Parameters
str[in] A string to uppercase.
Returns
str converted to upper case.

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