![]() |
Diana Software
|
general purpose string manipulation functions More...
Functions | |
| std::string & | SwallowSpaces (std::string &s) |
| remove spaces and tabs from the beginning of s More... | |
| std::string & | RSwallowSpaces (std::string &s) |
| remove spaces and tabs from the end of s More... | |
| std::string & | DoubleSwallowSpaces (std::string &s) |
| remove spaces and tabs from both the beginning and the end of s More... | |
| std::string | RemoveFromString (const std::string &text, const char *chars) |
| Remove some characters from the string. More... | |
| std::string | ToLower (const std::string &text) |
| Convert to lower case. More... | |
| std::string | ToUpper (const std::string &text) |
| Convert to upper case. More... | |
| void | Escape (std::string &text, char toBeEscaped) |
| escape text by adding backslash before each instance of toBeEscaped character More... | |
| void | UnEscape (std::string &text, char escaped) |
| unescape text by removing backslash preceding each instance of escaped character More... | |
| void | Replace (std::string &text, char oldChar, char newChar) |
| replace oldChar with newChar in text. Escaped characters are not replaced. More... | |
| size_t | Split (std::string source, std::list< std::string > &splitted, char separtator) |
| split source into a list of substrings separated by separator More... | |
| bool | StringToInt (std::string in, int &out, bool strictCheck) |
| convert string to integer More... | |
| bool | StringToLong (std::string in, Long64_t &out, bool strictCheck) |
| convert string to Long64_t More... | |
| bool | StringToInt (const std::string &in, int &out) |
| wrapper for StringToInt(in, out, true) More... | |
| bool | StringToBool (std::string in, bool &out) |
| convert string to bool More... | |
| bool | StringToDouble (std::string in, double &out, bool strictCheck) |
| convert string to double More... | |
| bool | StringToDouble (const std::string &in, double &out) |
| wrapper for StringToDouble(in, out, true) More... | |
| bool | StringToChar (const std::string &in, char &out) |
| convert string to signed char (i.e. 8-bit int) More... | |
| std::string | IntToString (int val, int width=0, char pad='0') |
| convert int value to string More... | |
| std::string | LongToString (Long64_t val, int width=0, char pad='0') |
| convert long64 value to string More... | |
| std::string | BoolToString (bool val) |
| convert bool value to string ("true" or "false") More... | |
| std::string | DoubleToString (double val, int nDigits=4, bool scientific=true) |
| convert double value to string More... | |
| std::string | IntToHexString (int value) |
| convert int value to string using hex representation More... | |
| std::string | Resize (const std::string &s, size_t len) |
| resize a string to len, adding spaces if necessary More... | |
| std::string | TimeFormat (const char *fmt="%b %d %Y %H:%M:%S") |
| Get the current time formated as a string. More... | |
| std::string | TimeFormat (const char *fmt, time_t t0) |
| Convert an time struct to a formated time string. More... | |
| template<class T > | |
| std::string | SqlString (const Diana::QBaseType< T > &baseVal, bool modeSelect) |
| build string valid for sql select or insert query starting from a QBaseType variable More... | |
| std::string | SqlString (const Diana::QBool &boolVal, bool modeSelect) |
| build string valid for sql select or insert query starting from a QBool More... | |
| std::string | SqlString (const std::vector< int > &vecVal, bool modeSelect, bool writeEmptyBra) |
| build string valid for sql select or insert query starting from a std::vector<int> More... | |
| std::string | SqlString (const Diana::QString &strVal, const std::string &selectName="") |
| build string valid for sql select or insert query starting from a QString More... | |
| std::string | RandomString (UInt_t length, Bool_t caseSensitive=true, Bool_t startLetter=false) |
| Return a random string of lenght. More... | |
| template<class ForwardIterator > | |
| std::string | Join (const std::string &joiner, ForwardIterator begin, ForwardIterator end) |
| Join a list of things into a string. More... | |
general purpose string manipulation functions
| std::string QStringHandler::BoolToString | ( | bool | val | ) |
convert bool value to string ("true" or "false")
Definition at line 245 of file QStringHandler.cc.
|
inline |
remove spaces and tabs from both the beginning and the end of s
Definition at line 36 of file QStringHandler.hh.
References RSwallowSpaces(), and SwallowSpaces().
Referenced by QDLLLoader::Init(), Split(), StringToBool(), StringToDouble(), StringToInt(), and StringToLong().
| std::string QStringHandler::DoubleToString | ( | double | val, |
| int | nDigits = 4, |
||
| bool | scientific = true |
||
| ) |
convert double value to string
| nDigits | total number of significant digits (defaults to 4) |
| scientific | if true scientific notation |
If scientific is true 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.
If scientific is false the number is converted into float field format (i.e. human-readable notation, e.g. 34.49), and with a total number of nDigits significant digits.
Definition at line 251 of file QStringHandler.cc.
| void QStringHandler::Escape | ( | std::string & | text, |
| char | toBeEscaped | ||
| ) |
escape text by adding backslash before each instance of toBeEscaped character
Definition at line 41 of file QStringHandler.cc.
| std::string QStringHandler::IntToHexString | ( | int | value | ) |
convert int value to string using hex representation
The returned string is prefixed with 0x
Definition at line 268 of file QStringHandler.cc.
| std::string QStringHandler::IntToString | ( | int | val, |
| int | width = 0, |
||
| char | pad = '0' |
||
| ) |
convert int value to string
Definition at line 227 of file QStringHandler.cc.
Referenced by QChannelRunDataHandle::FillFromDB().
| std::string QStringHandler::Join | ( | const std::string & | joiner, |
| ForwardIterator | begin, | ||
| ForwardIterator | end | ||
| ) |
Join a list of things into a string.
Join a list of things together with a string. Join each element between begin and end with the string in joiner. Return as a string.
Definition at line 281 of file QStringHandler.hh.
| std::string QStringHandler::LongToString | ( | Long64_t | val, |
| int | width = 0, |
||
| char | pad = '0' |
||
| ) |
convert long64 value to string
Definition at line 236 of file QStringHandler.cc.
| std::string QStringHandler::RandomString | ( | UInt_t | length, |
| Bool_t | caseSensitive = true, |
||
| Bool_t | startLetter = false |
||
| ) |
Return a random string of lenght.
Return a random string of a given length. In the case of case sensitive: chooses characters from 0-9a-zA-Z, in the case of case insensitive: 0-9a-z.
By default, start with any of 0-9a-zA-Z. Sometimes you want to start with letter only, so if startLetter=true, the first character will be a letter.
Note on randomness: You can make strings of arbitrary length and probability of any given string is (1./62)**length or (1./36)**length (case insensitive), which has a p~1e-9 after 5 or 6 characters. BUT the random number generator takes a UInt_t as a seed, which has a range of 4e9, but the seed only comes from TTimeStamp::GetNanoSec(), which significantly limits the seeds.
Definition at line 368 of file QStringHandler.cc.
Referenced by QFileWriter::BuildFileName().
| std::string QStringHandler::RemoveFromString | ( | const std::string & | text, |
| const char * | chars | ||
| ) |
Remove some characters from the string.
Definition at line 19 of file QStringHandler.cc.
| void QStringHandler::Replace | ( | std::string & | text, |
| char | oldChar, | ||
| char | newChar | ||
| ) |
replace oldChar with newChar in text. Escaped characters are not replaced.
Definition at line 72 of file QStringHandler.cc.
| std::string QStringHandler::Resize | ( | const std::string & | s, |
| size_t | len | ||
| ) |
resize a string to len, adding spaces if necessary
Definition at line 275 of file QStringHandler.cc.
Referenced by QGCalibrationWindow::AddPeak(), QEvent::Dump(), QGlobalDataManager::Dump(), QGCanvasWindowButtonsFrame::HandleNameButton(), QGCanvasWindowButtonsFrame::HandleNameEntryBox(), QGCalibrationWindow::QGCalibrationWindow(), QGCanvasWindow::QGCanvasWindow(), QGCutsEditorWindow::QGCutsEditorWindow(), QGDMainFrame::QGDMainFrame(), QGHistogramEditWindow::QGHistogramEditWindow(), QGPlotListWindow::QGPlotListWindow(), QGPulseEditWindow::QGPulseEditWindow(), QGScatterPlotEditWindow::QGScatterPlotEditWindow(), QGCanvasSetupFrame::SetDisplay(), QGCanvasWindowButtonsFrame::ShowDefaultDisplay(), and QGCanvasWindowButtonsFrame::ShowSetupWindowDisplay().
|
inline |
remove spaces and tabs from the end of s
Definition at line 32 of file QStringHandler.hh.
Referenced by DoubleSwallowSpaces(), and QModuleFactory::Init().
| size_t QStringHandler::Split | ( | std::string | source, |
| std::list< std::string > & | splitted, | ||
| char | separtator | ||
| ) |
split source into a list of substrings separated by separator
| source | string to be splitted |
| splitted | list filled with splitted substrings |
| separator | character used to split source |
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).
Definition at line 89 of file QStringHandler.cc.
References DoubleSwallowSpaces().
Referenced by main().
| std::string QStringHandler::SqlString | ( | const Diana::QBaseType< T > & | baseVal, |
| bool | modeSelect | ||
| ) |
build string valid for sql select or insert query starting from a QBaseType variable
| modeSelect | if true, a select-like string will be built, otherwise a insert-like string will be built |
The insert-like string is the input value converted to string or "NULL". The select-like string is the same as insert-like string, but preceded by "=" (if the input value is defined) or "IS " (if the input value is NULL)
Definition at line 200 of file QStringHandler.hh.
| std::string QStringHandler::SqlString | ( | const Diana::QBool & | boolVal, |
| bool | modeSelect | ||
| ) |
build string valid for sql select or insert query starting from a QBool
| modeSelect | if true, a select-like string will be built, otherwise a insert-like string will be built |
The insert-like string is the input value converted to string or "NULL". The select-like string is the same as insert-like string, but preceded by "=" (if the input value is defined) or "IS " (if the input value is NULL)
Definition at line 303 of file QStringHandler.cc.
| std::string QStringHandler::SqlString | ( | const Diana::QString & | strVal, |
| const std::string & | selectName = "" |
||
| ) |
build string valid for sql select or insert query starting from a QString
| selectName | if empty, this method behaves as the same method for QBaseType with modeSelect = false; if not empty, this method beheves as the same method for QBaseType input and modeSelect = true, but also includes in the return string the name of the db field to be selected. |
Definition at line 344 of file QStringHandler.cc.
| std::string QStringHandler::SqlString | ( | const std::vector< int > & | vecVal, |
| bool | modeSelect, | ||
| bool | writeEmptyBra | ||
| ) |
build string valid for sql select or insert query starting from a std::vector<int>
| modeSelect | if true, a select-like string will be built, otherwise a insert-like string will be built |
The insert-like string is the input value converted to string or "NULL" (if useEmpty is false) or "{}" (if useEmpty is true). The select-like string is the same as insert-like string, but preceded by "=" (if the input value is defined or useEmpty is true) or "IS " (if the input value is NULL)
Definition at line 318 of file QStringHandler.cc.
| bool QStringHandler::StringToBool | ( | std::string | in, |
| bool & | out | ||
| ) |
convert string to bool
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.
Definition at line 165 of file QStringHandler.cc.
References DoubleSwallowSpaces().
| bool QStringHandler::StringToChar | ( | const std::string & | in, |
| char & | out | ||
| ) |
convert string to signed char (i.e. 8-bit int)
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.
Definition at line 211 of file QStringHandler.cc.
References StringToInt().
|
inline |
wrapper for StringToDouble(in, out, true)
Definition at line 130 of file QStringHandler.hh.
References StringToDouble().
| bool QStringHandler::StringToDouble | ( | std::string | in, |
| double & | out, | ||
| bool | strictCheck | ||
| ) |
convert string to double
Does the same things as StringToInt() apart for the following:
Definition at line 193 of file QStringHandler.cc.
References DoubleSwallowSpaces().
Referenced by StringToDouble().
|
inline |
wrapper for StringToInt(in, out, true)
Definition at line 106 of file QStringHandler.hh.
References StringToInt().
| bool QStringHandler::StringToInt | ( | std::string | in, |
| int & | out, | ||
| bool | strictCheck | ||
| ) |
convert string to integer
| 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 |
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.
Definition at line 128 of file QStringHandler.cc.
References DoubleSwallowSpaces().
Referenced by StringToChar(), and StringToInt().
| bool QStringHandler::StringToLong | ( | std::string | in, |
| Long64_t & | out, | ||
| bool | strictCheck | ||
| ) |
convert string to Long64_t
Behave exactly as StringToInt() but use strtoll instead of strtol for conversion.
Definition at line 146 of file QStringHandler.cc.
References DoubleSwallowSpaces().
|
inline |
remove spaces and tabs from the beginning of s
Definition at line 28 of file QStringHandler.hh.
Referenced by DoubleSwallowSpaces(), and QModuleFactory::Init().
| std::string QStringHandler::TimeFormat | ( | const char * | fmt, |
| time_t | t0 | ||
| ) |
Convert an time struct to a formated time string.
Definition at line 294 of file QStringHandler.cc.
References t0.
| std::string QStringHandler::TimeFormat | ( | const char * | fmt = "%b %d %Y %H:%M:%S" | ) |
Get the current time formated as a string.
Definition at line 289 of file QStringHandler.cc.
| std::string QStringHandler::ToLower | ( | const std::string & | text | ) |
Convert to lower case.
Definition at line 27 of file QStringHandler.cc.
| std::string QStringHandler::ToUpper | ( | const std::string & | text | ) |
Convert to upper case.
Definition at line 34 of file QStringHandler.cc.
| void QStringHandler::UnEscape | ( | std::string & | text, |
| char | escaped | ||
| ) |
unescape text by removing backslash preceding each instance of escaped character
Definition at line 55 of file QStringHandler.cc.