Loading...
Searching...
No Matches
Namespaces | Functions
String manipulation
Collaboration diagram for String manipulation:

Namespaces

namespace  bitpit::utils::string
 Namespace for string utility functions.
 

Functions

template<class T , size_t n>
void bitpit::utils::string::convertString (std::string input, std::array< T, n > &output)
 
template<class T >
void bitpit::utils::string::convertString (std::string input, std::vector< T > &output)
 
template<class T >
void bitpit::utils::string::convertString (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]

template<class T , size_t n>
void bitpit::utils::string::convertString ( 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]inputis the input string
[out]outputon output contains the values extracted from the input string

Definition at line 274 of file stringUtils.tpp.

◆ convertString() [2/3]

template<class T >
void bitpit::utils::string::convertString ( 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 a void vector is returned. Values extracted from string are pushed at the end of the vector.

Parameters
[in]inputis the input string
[out]outputon output contains the values extracted from the input string

Definition at line 237 of file stringUtils.tpp.

◆ convertString() [3/3]

template<class T >
void bitpit::utils::string::convertString ( 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]inputis the input string
[out]outputon 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]lineinput string
[in]keysearch key
[in]deldelimiter char
[in,out]resulton 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()

bool bitpit::utils::string::keywordInString ( const std::string & line,
const std::string & key )
inline

Check whether a string contains the kwyword or not.

Parameters
[in]lineis the input string
[in]keyis the search key
Returns
Return true if the keyword has been found, false otherwise.

Definition at line 175 of file stringUtils.tpp.

◆ lfill()

std::string bitpit::utils::string::lfill ( int nchars,
const std::string & s,
char c )
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]ncharsis the final length of the string
[in]sis the input string
[in]cis the char used as filler

Definition at line 115 of file stringUtils.tpp.

◆ ltrim()

std::string & bitpit::utils::string::ltrim ( std::string & s)
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]son 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()

std::string bitpit::utils::string::rfill ( int nchars,
const std::string & s,
char c )
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]ncharsis the final length of the string
[in]sis the input string
[in]cis the char used as filler

Definition at line 135 of file stringUtils.tpp.

◆ rtrim()

std::string & bitpit::utils::string::rtrim ( std::string & s)
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]son 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()

std::string & bitpit::utils::string::trim ( std::string & s)
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]son 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()

std::string bitpit::utils::string::zeroPadNumber ( int nchars,
int num )
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]ncharsis the final length of the string
[in]numis the input integer
Returns
A string storing the input number in the format 000xxx.

Definition at line 158 of file stringUtils.tpp.

--- layout: doxygen_footer ---