AnaMark Tuning Library
Functions
TUN::strx Namespace Reference

Functions

int IsLetterOrUnderscore (int c)
 
const char * WhiteSpaceChars ()
 
std::string & ToLower (std::string &str)
 
std::string GetAsLower (const std::string &str)
 
std::string & Trim (std::string &str)
 
std::string & RemoveSpaces (std::string &str)
 
std::string & Escape (std::string &str)
 
std::string & Unescape (std::string &str)
 
bool Eval (const std::string &input_string, std::string::size_type &pos, double &result)
 
bool Eval (const std::string &input_string, std::string::size_type &pos, long &result)
 
bool EvalKeyAndValue (std::string &input_string, std::string &key, std::string &value)
 
bool EvalSection (std::string &str)
 
bool EvalFunctionParam (std::string &str)
 
bool EvalString (std::string &str)
 
void Split (std::string &input_string, char separator, std::list< std::string > &resulting_strings, bool trim_resulting_strings, bool ignore_any_empty_split_strings)
 
std::string ltostr (long value)
 
std::string dtostr (double value)
 
std::string GetAsSection (const std::string &str)
 
std::string GetAsString (const std::string &str)
 

Function Documentation

std::string TUN::strx::dtostr ( double  value)

Converts double to string.

Parameters
valueDouble to convert.
Returns
String of the double.
std::string & TUN::strx::Escape ( std::string &  str)
bool TUN::strx::Eval ( const std::string &  input_string,
std::string::size_type &  pos,
double &  result 
)

Evaluate string as a double. Evaluation starts at input_string index pos.

Parameters
input_stringReferenced string to evaluate. String is not modified.
posIndex in input_string to start evaluating. Passed variable modified to be first character after the double (if function returns true).
resultDouble that was evaluated (if function returns true).
Returns
False if string at pos was unable to be evaluated as a double.
bool TUN::strx::Eval ( const std::string &  input_string,
std::string::size_type &  pos,
long &  result 
)

Evaluate string as a long. Evaluation starts at input_string index pos.

Parameters
input_stringReferenced string to evaluate. String is not modified.
posIndex in input_string to start evaluating. Passed variable modified to be first character after the long (if function returns true).
resultLong that was evaluated (if function returns true).
Returns
False if string starting at pos was unable to be evaluated as a long.
bool TUN::strx::EvalFunctionParam ( std::string &  str)

Get the function parameters from str.

Removes encompassing "()" characters.

Modification happens in-place (str is modiifed).

Parameters
strFunction parameters string. Of form "(function parameters)".
Returns
Returns false if the first character is not '(', the last character is not ')', or the string length is less than 2. Returns true otherwise.
bool TUN::strx::EvalKeyAndValue ( std::string &  input_string,
std::string &  key,
std::string &  value 
)

Split a input string to key and value parts via the character '='.

Parameters
input_stringString to extract key and value strings from.
keyUsed as output. String will be the key part of input_string.
valueUsed as output. String will be the value part of input_string.
Returns
Returns false if no '=' character in input_string, or the first character of input_string is not a letter or underscore. Returns true otherwise.
bool TUN::strx::EvalSection ( std::string &  str)

Get the section name from str.

Removes encompassing "[]" characters, and converts str to lowercase.

Modification happens in-place (str is modiifed).

Parameters
strSection name string. Of form "[Section Name]".
Returns
Returns false if the first character is not '[', the last character is not ']', or the string length is less than 2. Returns true otherwise.
bool TUN::strx::EvalString ( std::string &  str)

Get the string from str.

Removes encompassing quote characters (i.e. \"). Unescapes any characters preceeded with \

Modification happens in-place (str is modiifed).

Parameters
strFunction parameters string. Of form "(function parameters)".
Returns
Returns false if the first character is not '"', the last character is not '"', or the string length is less than 2. Returns true otherwise.
std::string TUN::strx::GetAsLower ( const std::string &  str)

Apply ToLower function on string. Return a copy, instead of a reference to the modified input.

Parameters
strReference to string that will be converted to lowercase.
Returns
Lowercase version of str, returned as a copy.
std::string TUN::strx::GetAsSection ( const std::string &  str)

Encompasses str with "[]".

Part of the TUN specification of having sections being declared with encompassing brackets.

Parameters
strString to add brackets around. Str is not modified.
Returns
Returns copy of str with brackets added at beginning and end.
std::string TUN::strx::GetAsString ( const std::string &  str)

Encompasses str with quotes, and converts all characters that must be escaped when programming (as defined in function Escape()) is prefaced with a \.

Parameters
strString to get as "string." Str is not modified.
Returns
Returns copy of str with quotes added to beginning and end, with special characters escaped.
int TUN::strx::IsLetterOrUnderscore ( int  c)

Replacement for Windows function __iscsymf.

Parameters
cThe character.
Returns
Non-zero value if c is a letter or an underscore, 0 if c is not a letter or an underscore.
std::string TUN::strx::ltostr ( long  value)

Convert long to string.

Parameters
valueLong to convert.
Returns
String of the long.
std::string & TUN::strx::RemoveSpaces ( std::string &  str)

Remove all spaces in str.

Space characters are from that of the "C" locale.

Conversion is done in-place. Input string reference will be modified! Make a copy of string first if you dont want to modify your source string.

Parameters
str[description]
Returns
[description]
void TUN::strx::Split ( std::string &  input_string,
char  separator,
std::list< std::string > &  resulting_strings,
bool  trim_resulting_strings,
bool  ignore_any_empty_split_strings 
)

Split input_string into a list of strings at each seperator character in input_string.

Parameters
input_stringString to split. Not modified.
separatorCharacter to split input_string at.
resulting_stringsEach seperate string as a list. List passed will be cleared to add the substrings!
trim_resulting_stringsSet to true to trim each split string.
ignore_any_empty_split_stringsSet to true to not add any substrings to resulting_strings if the substring is empty (i.e. no characters).
std::string & TUN::strx::ToLower ( std::string &  str)

Convert all characters to lower case using C++ function tolower.

Uses "C" locale regardless of global locale.

Conversion is done in-place. Input string reference will be modified! Make a copy of string first if you dont want to modify your source string.

Parameters
strReference to string that will be converted.
Returns
Reference of the modified input string.
std::string & TUN::strx::Trim ( std::string &  str)

Removes trailing and leading whitespace.

The whitespace considered is the whitespace in character array returned by WhiteSpaceChars().

Conversion is done in-place. Input string reference will be modified! Make a copy of string first if you dont want to modify your source string.

Parameters
strReference of string to trim.
Returns
Reference of the modified input string.
std::string & TUN::strx::Unescape ( std::string &  str)
const char * TUN::strx::WhiteSpaceChars ( )

Returns a string literal of the following whitespace characters in this order:

  • Horizontal tab (0x09, '\t')
  • Line feed (0x0a, '\n')
  • Vertical tab (0x0b, '\v')
  • Form feed (0x0c, '\f')
  • Carriage return (0x0d, '\r')
  • Space (0x20, ' ')

Returned string is the same regardless of locale.

Returns
String literal of the popular whitespace characters.