add uppercase string utility function (for symmetry)
This commit is contained in:
@ -106,6 +106,9 @@ and parsing files or arguments.
|
||||
.. doxygenfunction:: lowercase
|
||||
:project: progguide
|
||||
|
||||
.. doxygenfunction:: uppercase
|
||||
:project: progguide
|
||||
|
||||
.. doxygenfunction:: trim
|
||||
:project: progguide
|
||||
|
||||
|
||||
@ -312,7 +312,7 @@ int utils::logical(const char *file, int line, const char *str, bool do_abort, L
|
||||
lmp->error->all(file, line, msg);
|
||||
}
|
||||
|
||||
// convert to ascii and lowercase
|
||||
// convert to ascii
|
||||
std::string buf(str);
|
||||
if (has_utf8(buf)) buf = utf8_subst(buf);
|
||||
|
||||
@ -705,6 +705,17 @@ std::string utils::lowercase(const std::string &text)
|
||||
return converted;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
Return string converted to uppercase
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
std::string utils::uppercase(const std::string &text)
|
||||
{
|
||||
std::string converted;
|
||||
for (auto c : text) converted += ::toupper(c);
|
||||
return converted;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
Return string without leading or trailing whitespace
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
@ -289,6 +289,13 @@ namespace utils {
|
||||
|
||||
std::string lowercase(const std::string &line);
|
||||
|
||||
/*! Convert string to uppercase
|
||||
*
|
||||
* \param line string that should be converted
|
||||
* \return new string with all uppercase characters */
|
||||
|
||||
std::string uppercase(const std::string &line);
|
||||
|
||||
/*! Trim leading and trailing whitespace. Like TRIM() in Fortran.
|
||||
*
|
||||
* \param line string that should be trimmed
|
||||
|
||||
@ -64,10 +64,12 @@ TEST(Utils, trim)
|
||||
ASSERT_THAT(trimmed, StrEq(""));
|
||||
}
|
||||
|
||||
TEST(Utils, lowercase)
|
||||
TEST(Utils, casemod)
|
||||
{
|
||||
ASSERT_THAT(utils::lowercase("Gba35%*zAKgRvr"), StrEq("gba35%*zakgrvr"));
|
||||
ASSERT_THAT(utils::lowercase("A BC DEFG"), StrEq("a bc defg"));
|
||||
ASSERT_THAT(utils::uppercase("Gba35%*zAKgRvr"), StrEq("GBA35%*ZAKGRVR"));
|
||||
ASSERT_THAT(utils::uppercase("a bc defg"), StrEq("A BC DEFG"));
|
||||
}
|
||||
|
||||
TEST(Utils, trim_comment)
|
||||
|
||||
Reference in New Issue
Block a user