QStringHandler Namespace Reference


Detailed Description

general purpose string manipulation functions

Author:
Alessandro Razeto

Sergio Di Domizio


Functions

void Escape (std::string &text, char toBeEscaped)
 escape text by adding backslash before each instance of toBeEscaped character
void UnEscape (std::string &text, char escaped)
 unescape text by removing backslash preceding each instance of escaped character
void Replace (std::string &text, char oldChar, char newChar)
 replace oldChar with newChar in text. Escaped characters are not replaced.
size_t Split (std::string source, std::list< std::string > &splitted, char separtator)
 split source into a list of substrings separated by separator
bool StringToInt (std::string in, int &out, bool strictCheck)
 convert string to integer
bool StringToBool (std::string in, bool &out)
 convert string to bool
bool StringToDouble (std::string in, double &out, bool strictCheck)
 convert string to double
bool StringToChar (const std::string &in, char &out)
 convert string to signed char (i.e. 8-bit int)
std::string IntToString (int val)
 convert int value to string
std::string BoolToString (bool val)
 convert bool value to string ("true" or "false")
std::string DoubleToString (double val, int nDigits=4)
 convert double value to string
std::string IntToHexString (int value)
 convert int value to string using hex representation
std::string & SwallowSpaces (std::string &s)
 remove spaces and tabs from the beginning of s
std::string & RSwallowSpaces (std::string &s)
 remove spaces and tabs from the end of s
std::string & DoubleSwallowSpaces (std::string &s)
 remove spaces and tabs from both the beginning and the end of s
bool StringToInt (const std::string &in, int &out)
 wrapper for StringToInt(in, out, true)
bool StringToDouble (const std::string &in, double &out)
 wrapper for StringToDouble(in, out, true)


Function Documentation

std::string QStringHandler::DoubleToString ( double  val,
int  nDigits = 4 
)

convert double value to string

Parameters:
nDigits total number of significant digits (defaults to 4)
The number is converted into scientific format with 1 digit before the decimal point and (nDigits - 1) digits after the decimal point. The converted value also contains the exponential part, composed by the letter e followed by an optional sign and three digits.

Referenced by QCommand::AddDoubleToAnswer(), QSlowControlClient::SetPSupplyIset(), and QSlowControlClient::SetPSupplyVset().

std::string QStringHandler::IntToHexString ( int  value  ) 

convert int value to string using hex representation

The returned string is prefixed with 0x

Referenced by QSlowControlServer::LoadElectronicsDevice(), and QSlowControlClient::WritePulser().

size_t QStringHandler::Split ( std::string  source,
std::list< std::string > &  splitted,
char  separtator 
)

split source into a list of substrings separated by separator

Parameters:
source string to be splitted
splitted list filled with splitted substrings
separator character used to split source
Returns:
number of elements contained in splitted
Escaped separators (i.e. preceded by backslash) are not considered.
DoubleSwallowSpaces() is executed on each substring before adding it to splitted list (empty substring are not added).

References DoubleSwallowSpaces().

Referenced by QBaseCmdParser::Parse(), QBaseCmdParser::ParseParameters(), and QBaseClient::ProcessAnswer().

bool QStringHandler::StringToBool ( std::string  in,
bool &  out 
)

convert string to bool

Returns:
true unless in is invalid (see detailed description)
Allowed values for true are: "true", "t", "TRUE", "T", "1"
Allowed values for false are: "false", "f", "FALSE", "F", "0"
Empty characters at the beginning and/or at the end of input string s are allowed.

References DoubleSwallowSpaces().

Referenced by QCommand::GetBool(), QBaseClient::GetBool(), and QCommand::GetBoolList().

bool QStringHandler::StringToChar ( const std::string &  in,
char &  out 
)

convert string to signed char (i.e. 8-bit int)

Returns:
true on success
Convert in to int using StringToInt(). If converted value is negative or is bigger than 256, return false. Otherwise, cast int value to char and return true.

References StringToInt().

Referenced by QNetworkString::GetCharParameter().

bool QStringHandler::StringToDouble ( std::string  in,
double &  out,
bool  strictCheck 
)

convert string to double

Does the same things as StringToInt() apart for the following:

  • strtod() is used instead of strtol() ...
  • it is not possible to use input string formatted as hex ...

References DoubleSwallowSpaces().

Referenced by QCommand::GetDouble(), QBaseClient::GetDouble(), QCommand::GetDoubleList(), and StringToDouble().

bool QStringHandler::StringToInt ( std::string  in,
int &  out,
bool  strictCheck 
)

convert string to integer

Parameters:
in can be formatted as decimal or hex (must start with "0x")
strictCheck determines the return value if only a part of input string can be converted
Returns:
true unless conversion fails (see detailed description)
This function calls DoubleSwallowSpaces() on in, therefore spaces at the beginning or at the end of input string are allowed.
It then calls strtol on input string.
  • if the conversion fails at the first character of input string, false is returned.
  • If the whole string is converted, true is returned
  • In case of partial conversion, (!strictCheck) is returned

References DoubleSwallowSpaces().

Referenced by QBaseClient::BuildError(), QCommand::GetInt(), QBaseClient::GetInt(), QCommand::GetIntList(), QNetworkString::GetIntParameter(), StringToChar(), and StringToInt().


Generated on Tue Nov 16 10:50:09 2010 for CUORE Software by  doxygen 1.5.6