mirror of https://github.com/lammps/lammps.git
add utility to convert a string to lowercase
This commit is contained in:
parent
aab3e085a2
commit
a9bccee7b2
|
@ -103,6 +103,9 @@ and parsing files or arguments.
|
|||
.. doxygenfunction:: strdup
|
||||
:project: progguide
|
||||
|
||||
.. doxygenfunction:: lowercase
|
||||
:project: progguide
|
||||
|
||||
.. doxygenfunction:: trim
|
||||
:project: progguide
|
||||
|
||||
|
|
|
@ -694,6 +694,17 @@ char *utils::strdup(const std::string &text)
|
|||
return tmp;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
Return string converted to lowercase
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
std::string utils::lowercase(const std::string &text)
|
||||
{
|
||||
std::string converted;
|
||||
for (auto c : text) converted += ::tolower(c);
|
||||
return converted;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
Return string without leading or trailing whitespace
|
||||
------------------------------------------------------------------------- */
|
||||
|
|
|
@ -282,6 +282,13 @@ namespace utils {
|
|||
|
||||
char *strdup(const std::string &text);
|
||||
|
||||
/*! Convert string to lowercase
|
||||
*
|
||||
* \param line string that should be converted
|
||||
* \return new string with all lowercase characters */
|
||||
|
||||
std::string lowercase(const std::string &line);
|
||||
|
||||
/*! Trim leading and trailing whitespace. Like TRIM() in Fortran.
|
||||
*
|
||||
* \param line string that should be trimmed
|
||||
|
|
|
@ -64,6 +64,12 @@ TEST(Utils, trim)
|
|||
ASSERT_THAT(trimmed, StrEq(""));
|
||||
}
|
||||
|
||||
TEST(Utils, lowercase)
|
||||
{
|
||||
ASSERT_THAT(utils::lowercase("Gba35%*zAKgRvr"), StrEq("gba35%*zakgrvr"));
|
||||
ASSERT_THAT(utils::lowercase("A BC DEFG"), StrEq("a bc defg"));
|
||||
}
|
||||
|
||||
TEST(Utils, trim_comment)
|
||||
{
|
||||
auto trimmed = utils::trim_comment("some text # comment");
|
||||
|
|
Loading…
Reference in New Issue