Utility classes and function implementation.
More...
Utility classes and function implementation.
|
template<typename Iter , typename Cont > |
bool | nmodl::utils::is_last (Iter iter, const Cont &cont) |
| Check if the iterator is pointing to last element in the container. More...
|
|
std::string | nmodl::utils::generate_random_string (int len, UseNumbersInString use_numbers) |
| Generate random std::string of length len based on a uniform distribution. More...
|
|
static std::string | nmodl::stringutils::ltrim (std::string text) |
|
static std::string | nmodl::stringutils::rtrim (std::string text) |
|
static std::string | nmodl::stringutils::trim (std::string text) |
|
static std::string | nmodl::stringutils::remove_character (std::string text, const char c) |
| Remove all occurrences of a given character in a text. More...
|
|
static std::string | nmodl::stringutils::trim_newline (std::string text) |
|
static std::string | nmodl::stringutils::escape_quotes (const std::string &text) |
| Escape double-quote in a text, useful for JSON pretty printer. More...
|
|
static std::vector< std::string > | nmodl::stringutils::split_string (const std::string &text, char delimiter) |
| Split a text in a list of words, using a given delimiter character. More...
|
|
static std::string | nmodl::stringutils::align_text (const std::string &text, int width, text_alignment type) |
| Aligns a text within a field of width width. More...
|
|
static std::string | nmodl::stringutils::tolower (std::string text) |
| To lower case. More...
|
|
std::string | nmodl::stringutils::to_string (double value, const std::string &format_spec="{:.16g}") |
| Convert double value to string without trailing zeros. More...
|
|
◆ text_alignment
text alignment when printing in the tabular form
Enumerator |
---|
left | |
right | |
center | |
Definition at line 35 of file string_utils.hpp.
◆ UseNumbersInString
Enum to wrap bool variable to select if random string should have numbers or not.
Enumerator |
---|
WithNumbers | |
WithoutNumbers | |
Definition at line 51 of file common_utils.hpp.
◆ align_text()
static std::string nmodl::stringutils::align_text |
( |
const std::string & |
text, |
|
|
int |
width, |
|
|
text_alignment |
type |
|
) |
| |
|
inlinestatic |
Aligns a text within a field of width width.
- Parameters
-
text | the string to manipulate |
width | the width of the field |
type | the kind of alignment Left, Right, or Center |
- Returns
- a copy of the string aligned
left and right spacing
count excess room to pad
if odd #, add one more space
Definition at line 137 of file string_utils.hpp.
◆ escape_quotes()
static std::string nmodl::stringutils::escape_quotes |
( |
const std::string & |
text | ) |
|
|
inlinestatic |
Escape double-quote in a text, useful for JSON pretty printer.
- Parameters
-
text | the string to manipulate |
- Returns
- a copy of the given string with every " and \ characters prefixed with an extra \
don't break here as we want to append actual character
Definition at line 92 of file string_utils.hpp.
◆ generate_random_string()
std::string nmodl::utils::generate_random_string |
( |
const int |
len, |
|
|
UseNumbersInString |
use_numbers |
|
) |
| |
Generate random std::string of length len based on a uniform distribution.
Definition at line 27 of file common_utils.cpp.
◆ is_last()
template<typename Iter , typename Cont >
bool nmodl::utils::is_last |
( |
Iter |
iter, |
|
|
const Cont & |
cont |
|
) |
| |
Check if the iterator is pointing to last element in the container.
Definition at line 37 of file common_utils.hpp.
◆ ltrim()
static std::string nmodl::stringutils::ltrim |
( |
std::string |
text | ) |
|
|
inlinestatic |
- Parameters
-
text | the string to manipulate |
- Returns
- a copy of the given string with leading ASCII space characters removed
Definition at line 41 of file string_utils.hpp.
◆ remove_character()
static std::string nmodl::stringutils::remove_character |
( |
std::string |
text, |
|
|
const char |
c |
|
) |
| |
|
inlinestatic |
Remove all occurrences of a given character in a text.
- Parameters
-
text | the string to manipulate |
c | the character to remove |
- Returns
- a copy the modified text
Definition at line 73 of file string_utils.hpp.
◆ rtrim()
static std::string nmodl::stringutils::rtrim |
( |
std::string |
text | ) |
|
|
inlinestatic |
- Parameters
-
text | the string to manipulate |
- Returns
- a copy of the given string with trailing characters removed.
Definition at line 51 of file string_utils.hpp.
◆ split_string()
static std::vector<std::string> nmodl::stringutils::split_string |
( |
const std::string & |
text, |
|
|
char |
delimiter |
|
) |
| |
|
inlinestatic |
Split a text in a list of words, using a given delimiter character.
- Parameters
-
text | the string to manipulate |
delimiter | the delimiter character |
- Returns
- a container holding copies of the substrings
Definition at line 116 of file string_utils.hpp.
◆ to_string()
std::string nmodl::stringutils::to_string |
( |
double |
value, |
|
|
const std::string & |
format_spec = "{:.16g}" |
|
) |
| |
Convert double value to string without trailing zeros.
When we use std::to_string with double value 1 then it gets printed as 1.000000
. This is not convenient for testing and testing/validation. To avoid this issue, we use to_string for integer values and stringstream for the rest.
Definition at line 18 of file string_utils.cpp.
◆ tolower()
static std::string nmodl::stringutils::tolower |
( |
std::string |
text | ) |
|
|
inlinestatic |
To lower case.
- Parameters
-
text | the string to manipulate |
- Returns
- a copy of string converted to lowercase
Definition at line 168 of file string_utils.hpp.
◆ trim()
static std::string nmodl::stringutils::trim |
( |
std::string |
text | ) |
|
|
inlinestatic |
- Parameters
-
text | the string to manipulate |
- Returns
- a copy of the given string with both leading and trailing ASCII space characters removed
Definition at line 63 of file string_utils.hpp.
◆ trim_newline()
static std::string nmodl::stringutils::trim_newline |
( |
std::string |
text | ) |
|
|
inlinestatic |
- Parameters
-
text | the string to manipulate |
- Returns
- a copy of the given string with all occurrences of the ASCII newline character removed
Definition at line 83 of file string_utils.hpp.
◆ envpathsep
constexpr char nmodl::utils::envpathsep {':'} |
|
staticconstexpr |
The character conventionally used by the operating system to separate search path components.
Definition at line 46 of file common_utils.hpp.