add uppercase string utility function (for symmetry)

This commit is contained in:
Axel Kohlmeyer
2021-10-07 00:00:33 -04:00
parent b8d6df6461
commit 059f450f1b
4 changed files with 25 additions and 2 deletions

View File

@ -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
------------------------------------------------------------------------- */

View File

@ -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