tfel
Loading...
Searching...
No Matches
StringAlgorithms.hxx File Reference

03 mar 2011 More...

#include <vector>
#include <string>
#include <string_view>
#include "TFEL/Config/TFELConfig.hxx"

Namespaces

namespace  tfel
 the namespace tfel encloses all the TFEL project. This namespace is empty.

Functions

TFELUTILITIES_VISIBILITY_EXPORT bool tfel::utilities::starts_with (std::string_view, std::string_view)
TFELUTILITIES_VISIBILITY_EXPORT bool tfel::utilities::ends_with (std::string_view, std::string_view)
TFELUTILITIES_VISIBILITY_EXPORT std::vector< std::string > tfel::utilities::tokenize (std::string_view, const char, const bool=false)
TFELUTILITIES_VISIBILITY_EXPORT std::vector< std::string > tfel::utilities::tokenize (std::string_view, std::string_view)
TFELUTILITIES_VISIBILITY_EXPORT std::string tfel::utilities::replace_all (std::string_view, std::string_view, std::string_view, const std::string::size_type=0u)
 replace all occurences of substring s1 by s2
TFELUTILITIES_VISIBILITY_EXPORT void tfel::utilities::replace_all (std::string &, std::string_view, std::string_view, std::string_view, const std::string::size_type=0u)
 replace all occurences of substring s1 by s2
TFELUTILITIES_VISIBILITY_EXPORT std::string tfel::utilities::replace_all (std::string_view, const char, const char)
 replace all occurences of character c1 by c2
TFELUTILITIES_VISIBILITY_EXPORT void tfel::utilities::replace_all (std::string &, const char, std::string_view)
 replace all occurences of character c by n
template<typename T>
T tfel::utilities::convert (const std::string &)
 convert a string to the given type
template<>
TFELUTILITIES_VISIBILITY_EXPORT double tfel::utilities::convert (const std::string &)
 partial specialisation for double
template<>
TFELUTILITIES_VISIBILITY_EXPORT long double tfel::utilities::convert (const std::string &)
 partial specialisation for double
TFELUTILITIES_VISIBILITY_EXPORT std::string tfel::utilities::convert (const float &)
 convert a float to string using scientific notation and a 14 digit precision.
TFELUTILITIES_VISIBILITY_EXPORT std::string tfel::utilities::convert (const double &)
 convert a double to string using scientific notation and a 14 digit precision.
TFELUTILITIES_VISIBILITY_EXPORT std::string tfel::utilities::convert (const long double &)
 convert a long double to string using scientific notation and a 14 digit precision.

Detailed Description

03 mar 2011

Author
Thomas Helfer

Function Documentation

◆ convert() [1/6]

TFELUTILITIES_VISIBILITY_EXPORT std::string tfel::utilities::convert ( const double & )

convert a double to string using scientific notation and a 14 digit precision.

Parameters
[in]vstring to be converted

◆ convert() [2/6]

TFELUTILITIES_VISIBILITY_EXPORT std::string tfel::utilities::convert ( const float & )

convert a float to string using scientific notation and a 14 digit precision.

Parameters
[in]vstring to be converted

◆ convert() [3/6]

TFELUTILITIES_VISIBILITY_EXPORT std::string tfel::utilities::convert ( const long double & )

convert a long double to string using scientific notation and a 14 digit precision.

Parameters
[in]vstring to be converted

◆ convert() [4/6]

template<>
TFELUTILITIES_VISIBILITY_EXPORT long double tfel::utilities::convert ( const std::string & )

partial specialisation for double

Parameters
[in]sstring to be converted

◆ convert() [5/6]

template<>
TFELUTILITIES_VISIBILITY_EXPORT double tfel::utilities::convert ( const std::string & )

partial specialisation for double

Parameters
[in]sstring to be converted

◆ convert() [6/6]

template<typename T>
T tfel::utilities::convert ( const std::string & )

convert a string to the given type

Parameters
[in]sstring to be converted

◆ ends_with()

TFELUTILITIES_VISIBILITY_EXPORT bool tfel::utilities::ends_with ( std::string_view ,
std::string_view  )
Parameters
[in]s1first string
[in]s2second string
Returns
true if the first string ends with the second

◆ replace_all() [1/4]

TFELUTILITIES_VISIBILITY_EXPORT void tfel::utilities::replace_all ( std::string & ,
const char ,
std::string_view  )

replace all occurences of character c by n

Parameters
[in,out]s: original string
[in]c: character to be changed
[in]n: replacement character
Returns
a copy of c where all occurences of c have been replaced by n

◆ replace_all() [2/4]

TFELUTILITIES_VISIBILITY_EXPORT void tfel::utilities::replace_all ( std::string & ,
std::string_view ,
std::string_view ,
std::string_view ,
const std::string::size_type = 0u )

replace all occurences of substring s1 by s2

Parameters
r: result
s: original string
s1: substring to be changed
s2: replacement string
ps: beginning of the search

◆ replace_all() [3/4]

TFELUTILITIES_VISIBILITY_EXPORT std::string tfel::utilities::replace_all ( std::string_view ,
const char ,
const char  )

replace all occurences of character c1 by c2

Parameters
c: original string
c1: character to be changed
c2: replacement character
Returns
a copy of c where all occurences of c1 have been replaced by c2

◆ replace_all() [4/4]

TFELUTILITIES_VISIBILITY_EXPORT std::string tfel::utilities::replace_all ( std::string_view ,
std::string_view ,
std::string_view ,
const std::string::size_type = 0u )

replace all occurences of substring s1 by s2

Parameters
s: original string
s1: substring to be changed
s2: replacement string
ps: beginning of the search
Returns
a copy of s where all occurences of substring s1 have been replaced by s2

◆ starts_with()

TFELUTILITIES_VISIBILITY_EXPORT bool tfel::utilities::starts_with ( std::string_view ,
std::string_view  )
Parameters
[in]s1first string
[in]s2second string
Returns
true if the first string starts with the second

◆ tokenize() [1/2]

TFELUTILITIES_VISIBILITY_EXPORT std::vector< std::string > tfel::utilities::tokenize ( std::string_view ,
const char ,
const bool = false )

split a string into tokens using the specified delimiter

Parameters
sstring to be splitted
cdelimiter
keep_empty_stringif true, the empty strings before, between and after the delimiters are kept
Returns
the tokens

◆ tokenize() [2/2]

TFELUTILITIES_VISIBILITY_EXPORT std::vector< std::string > tfel::utilities::tokenize ( std::string_view ,
std::string_view  )

split a string into tokens using the specified delimiter

Parameters
s: string to be splitted
delim: delimiter
Returns
the tokens
Note
the empty strings before and between the delimiters are kept, but not the one after the last delimiter: tokenize(":a::b:", ":") returns {"", "a", "", "b"}. An empty string gives no token. If the delimiter is empty, the string is not split.