STIRA  0.1
Public Member Functions | Static Public Member Functions | List of all members
stira::common::StringUtils Class Reference

A class with some handy functions to manipulate STL strings. More...

#include <StringUtils.h>

Public Member Functions

 StringUtils ()
 Constructor.
 
 ~StringUtils ()
 Constructor.
 

Static Public Member Functions

static std::string ConvertIntegerToString (int i)
 converts integer to std::string More...
 
static std::string ConvertFloatToString (float f)
 converts float to std::string More...
 
static std::string ConvertDoubleToString (double d)
 converts double to std::string More...
 
static std::string ConvertBoolToString (bool b)
 converts boolean to std::string More...
 
static bool ConvertStringToBoolean (std::string inputString)
 converts std::string to boolean More...
 
static int ConvertStringToInt (std::string inputString)
 converts std::string to integer More...
 
static float ConvertStringToFloat (std::string inputString)
 converts std::string to float More...
 
static double ConvertStringToDouble (std::string inputString)
 converts std::string to double More...
 
static std::string ExtractFileName (std::string inputString)
 extracts file name from a path string, thus removing all until the last slash Inherently uses position of last slash, so works only for Unix path names More...
 
static std::string ExtractFileNameRoot (std::string inputString)
 extracts the root filename for a file, so removes path and extension e.g., if a certain path to a file is "/home/UserName/Filedir/SomeFileName_XXXX.txt", this function extracts "SomeFileName_XXXX" More...
 
static long int GetIndexFromFileName (std::string inputString, bool useUnderscoreAsSeparator=true)
 gets the index from a string We often encounter file names of type "SomeName_XXXX.pnm" where "XXXX" represents a number. This function extracts that number from the file name More...
 
static std::string FindFileNameInListFromIndex (int myIndex, std::vector< std::string > fileList)
 
static int FindFirstDot (std::string inputString)
 finds the position of the first dot in a string More...
 
static int FindLastSlash (std::string inputString)
 finds the position of the last slash in a string that represents a path Uses macro WIN32 (sometimes it can be _WIN32, CYGWIN32, or _MSC_VER) to determine if slash (unix) or backslash (windows) is to be used. More...
 
static int FindLastUnderscore (std::string inputString)
 
static int FindLastMinus (std::string inputString)
 
static std::string ExtractFileExtension (std::string inputString, bool includeDot=true)
 extracts the extension from a filename for a file e.g., if a certain path to a file is "/home/UserName/Filedir/SomeFileName.txt", this function extracts if includeDot true ".txt" and "txt" otherwise More...
 
static std::string ExtractFilePrefix (std::string inputString, bool useUnderscoreAsSeparator=true)
 extracts the prefix filename for a file, so removes path, extension and file index e.g., if a certain path to a file is "/home/UserName/Filedir/SomeFileName_XXXX.txt", this function extracts "SomeFileName" More...
 
static std::string ExtractPathOfFileName (std::string inputString)
 extracts the path for a file e.g., if a certain path to a file is "/home/UserName/Filedir/SomeFileName.txt", this function extracts "/home/UserName/Filedir" More...
 
static std::string ExtractFileNameFromPathPlusFileName (std::string inputString)
 extracts the path for a file e.g., if a certain path to a file is "/home/UserName/Filedir/SomeFileName.txt", this function extracts "SomeFileName.txt" More...
 
static std::string GoOneLevelUpInPathName (std::string inputString)
 
static std::string ConstructPathAndFileName (std::string path, std::string preFix, int indexNr, std::string extension)
 synthesizes a file name from a prefix, a counter and an extension More...
 
static std::string ConstructPathAndFileName (std::string path, std::string preFix, int indexNr1, int indexNr2, std::string extension)
 composes a file name from a prefix, two counters and an extension More...
 
static bool IsDigit (std::string s, long int &myDigit)
 
static void SplitStringInIntegers (const std::string &s, char c, std::vector< int > &v)
 Splits a delimited string in integers http://www.blog.highub.com/c-plus-plus/c-parse-split-delimited-string/ http://www.cplusplus.com/forum/general/13135/.
 
static std::string GetCurrentTimeAsStringID ()
 creates a string based on current time to build experiment output folders or files using this string
 

Detailed Description

A class with some handy functions to manipulate STL strings.

Member Function Documentation

std::string stira::common::StringUtils::ConstructPathAndFileName ( std::string  path,
std::string  preFix,
int  indexNr,
std::string  extension 
)
static

synthesizes a file name from a prefix, a counter and an extension

Parameters
pathpath of the file name
preFixprefix of the file name
indexNrcounter for file name
extensionextension of file name
Returns
a string with the synthesized file name
std::string stira::common::StringUtils::ConstructPathAndFileName ( std::string  path,
std::string  preFix,
int  indexNr1,
int  indexNr2,
std::string  extension 
)
static

composes a file name from a prefix, two counters and an extension

Parameters
pathpath of the file name
preFixprefix of the file name
indexNr1first counter for file name
indexNr2second counter for file name
extensionextension of file name
Returns
a string with the synthesized file name
std::string stira::common::StringUtils::ConvertBoolToString ( bool  b)
static

converts boolean to std::string

Parameters
bboolean to convert to std::string
std::string stira::common::StringUtils::ConvertDoubleToString ( double  d)
static

converts double to std::string

Parameters
ddouble to convert to std::string
std::string stira::common::StringUtils::ConvertFloatToString ( float  f)
static

converts float to std::string

Parameters
ffloat to convert to std::string
std::string stira::common::StringUtils::ConvertIntegerToString ( int  i)
static

converts integer to std::string

Parameters
iinteger to convert to std::string
bool stira::common::StringUtils::ConvertStringToBoolean ( std::string  inputString)
static

converts std::string to boolean

Parameters
inputStringstd::string to convert to boolean
double stira::common::StringUtils::ConvertStringToDouble ( std::string  inputString)
static

converts std::string to double

Parameters
inputStringstd::string to convert to double
float stira::common::StringUtils::ConvertStringToFloat ( std::string  inputString)
static

converts std::string to float

Parameters
inputStringstd::string to convert to float
int stira::common::StringUtils::ConvertStringToInt ( std::string  inputString)
static

converts std::string to integer

Parameters
inputStringstd::string to convert to integer
std::string stira::common::StringUtils::ExtractFileExtension ( std::string  inputString,
bool  includeDot = true 
)
static

extracts the extension from a filename for a file e.g., if a certain path to a file is "/home/UserName/Filedir/SomeFileName.txt", this function extracts if includeDot true ".txt" and "txt" otherwise

Parameters
inputStringstring containing full path to file, like in example above
includeDotflag if the dot should be included in the file extension
std::string stira::common::StringUtils::ExtractFileName ( std::string  inputString)
static

extracts file name from a path string, thus removing all until the last slash Inherently uses position of last slash, so works only for Unix path names

Parameters
inputStringinput string from which to extract file name
std::string stira::common::StringUtils::ExtractFileNameFromPathPlusFileName ( std::string  inputString)
static

extracts the path for a file e.g., if a certain path to a file is "/home/UserName/Filedir/SomeFileName.txt", this function extracts "SomeFileName.txt"

Parameters
inputStringstring containing full path to file, like in example above
std::string stira::common::StringUtils::ExtractFileNameRoot ( std::string  inputString)
static

extracts the root filename for a file, so removes path and extension e.g., if a certain path to a file is "/home/UserName/Filedir/SomeFileName_XXXX.txt", this function extracts "SomeFileName_XXXX"

Parameters
inputStringstring containing full path to file, like in example above
std::string stira::common::StringUtils::ExtractFilePrefix ( std::string  inputString,
bool  useUnderscoreAsSeparator = true 
)
static

extracts the prefix filename for a file, so removes path, extension and file index e.g., if a certain path to a file is "/home/UserName/Filedir/SomeFileName_XXXX.txt", this function extracts "SomeFileName"

Parameters
inputStringstring containing full path to file, like in example above
std::string stira::common::StringUtils::ExtractPathOfFileName ( std::string  inputString)
static

extracts the path for a file e.g., if a certain path to a file is "/home/UserName/Filedir/SomeFileName.txt", this function extracts "/home/UserName/Filedir"

Parameters
inputStringstring containing full path to file, like in example above
int stira::common::StringUtils::FindFirstDot ( std::string  inputString)
static

finds the position of the first dot in a string

Parameters
inputStringstring containing a dot somewhere
Returns
the position of the first dot in the string; -1 if no dot was found
int stira::common::StringUtils::FindLastSlash ( std::string  inputString)
static

finds the position of the last slash in a string that represents a path Uses macro WIN32 (sometimes it can be _WIN32, CYGWIN32, or _MSC_VER) to determine if slash (unix) or backslash (windows) is to be used.

Parameters
inputStringstring that represents a path, containing slashes or backslashes
Returns
the position of the last slash in the string; -1 if no dot was found
long int stira::common::StringUtils::GetIndexFromFileName ( std::string  inputString,
bool  useUnderscoreAsSeparator = true 
)
static

gets the index from a string We often encounter file names of type "SomeName_XXXX.pnm" where "XXXX" represents a number. This function extracts that number from the file name

Parameters
inputStringstring containing a file name with a number before the extension, like in the example above

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