
Namespaces | |
namespace | bitpit::utils::string |
Namespace for string utility functions. | |
Functions | |
template<class T, size_t n> | |
void | bitpit::utils::string::convertString (const std::string &input, std::array< T, n > &output) |
template<class T> | |
void | bitpit::utils::string::convertString (const std::string &input, std::vector< T > &output) |
template<class T> | |
void | bitpit::utils::string::convertString (const std::string &input, T &output) |
bool | bitpit::utils::string::getAfterKeyword (const std::string &line, const std::string &key, char del, std::string &result) |
bool | bitpit::utils::string::keywordInString (const std::string &line, const std::string &key) |
std::string | bitpit::utils::string::lfill (int nchars, const std::string &s, char c) |
std::string & | bitpit::utils::string::ltrim (std::string &s) |
std::string | bitpit::utils::string::rfill (int nchars, const std::string &s, char c) |
std::string & | bitpit::utils::string::rtrim (std::string &s) |
std::string & | bitpit::utils::string::trim (std::string &s) |
std::string | bitpit::utils::string::zeroPadNumber (int nchars, int num) |
Detailed Description
Function Documentation
◆ convertString() [1/3]
void bitpit::utils::string::convertString | ( | const std::string & | input, |
std::array< T, n > & | output ) |
Convertes a string into a arrayof fundamental data type.
If no data of type T can be extracted from the input string a void array with null elements is returned. If the number of elements which can be extracted from the input string is larger than the array size, only the first n elements are saved in the array.
- Parameters
-
[in] input is the input string [out] output on output contains the values extracted from the input string
Definition at line 267 of file stringUtils.tpp.
◆ convertString() [2/3]
void bitpit::utils::string::convertString | ( | const std::string & | input, |
std::vector< T > & | output ) |
Convertes a string into a vector of fundamental data type.
If no data of type T can be extracted from the input string an empty vector is returned. Values extracted from string are pushed at the end of the vector.
- Parameters
-
[in] input is the input string [out] output on output contains the values extracted from the input string
Definition at line 233 of file stringUtils.tpp.
◆ convertString() [3/3]
void bitpit::utils::string::convertString | ( | const std::string & | input, |
T & | output ) |
Convertes a string into fundamental data type.
If no data of type T can be extracted from the input string a 0 value, will be stored in output. If multiple values can be extracted from the input string, only the first value will be saved in output.
- Parameters
-
[in] input is the input string [out] output on output contains the value extracted from the input string
Definition at line 195 of file stringUtils.tpp.
◆ getAfterKeyword()
bool bitpit::utils::string::getAfterKeyword | ( | const std::string & | line, |
const std::string & | key, | ||
char | del, | ||
std::string & | result ) |
Given an input string containing several fields separated by a delimiter, returns the field after the specified search key. For instance, if the input string is str = "field_1 ; field_2 ; field_3" getAfterKeyword(str, "field_1, ';', output) returns output = "field_2"
- Parameters
-
[in] line input string [in] key search key [in] del delimiter char [in,out] result on output stores the field after the search key
- Returns
- boolean flag, (true) if search key has been found, (false) otherwise
Definition at line 51 of file stringUtils.cpp.
◆ keywordInString()
|
inline |
Check whether a string contains the kwyword or not.
- Parameters
-
[in] line is the input string [in] key is the search key
- Returns
- Return true if the keyword has been found, false otherwise.
Definition at line 175 of file stringUtils.tpp.
◆ lfill()
|
inline |
String left-filler. Create a string composed of the input string left-filled with a specified character. E.g. given the input string s = "test", lfill(10, s, '_') will return "______test".
- Parameters
-
[in] nchars is the final length of the string [in] s is the input string [in] c is the char used as filler
Definition at line 115 of file stringUtils.tpp.
◆ ltrim()
|
inline |
Left-trim operator for std::string.
Remove left trailing spaces from string. For instance, if the input string is " test_string ", on output this function returns "test_string "
- Parameters
-
[in,out] s on input contains the input string, on output contains the trimmed string
- Returns
- A reference to the input string.
Definition at line 46 of file stringUtils.tpp.
◆ rfill()
|
inline |
String right-filler. Create a string composed of the input string right-filled with a specified character. E.g. given the input string s = "test", rfill(10, s, '_') will return "test______".
- Parameters
-
[in] nchars is the final length of the string [in] s is the input string [in] c is the char used as filler
Definition at line 135 of file stringUtils.tpp.
◆ rtrim()
|
inline |
Right-trim operator for std::string. Remove right blank spaces from string. For instance, if the input string is " test_string ", on output this function returns " test_string"
- Parameters
-
[in,out] s on input contains the input string, on output contains the trimmed string
- Returns
- A reference to the input string.
Definition at line 72 of file stringUtils.tpp.
◆ trim()
|
inline |
Trim operator for std::string. Remove left/right blank spaces from string. For instance, if the input string is " test_string ", on output this function returns "test_string"
- Parameters
-
[in,out] s on input contains the input string, on output contains the trimmed string
- Returns
- A reference to the input string.
- Examples
- POD_application_example_00001.cpp.
Definition at line 98 of file stringUtils.tpp.
◆ zeroPadNumber()
|
inline |
Given an integer, returns a string of length nchars, composed of the input number and nchars - ndigits '0' characters (where ndigits is the number of digits of the input integer) in the following format "000xxx". If ndigits > nchars, the output string will contaiens ndigits characters storing the digits of the input number. For instance, if nchars = 4 and num = 3, this function returns the string "0003". If nchars = 4, and num = 12345, this function returns "12345".
- Parameters
-
[in] nchars is the final length of the string [in] num is the input integer
- Returns
- A string storing the input number in the format 000xxx.
Definition at line 158 of file stringUtils.tpp.
