From e6d6f3252f83c864b92376ae89a83b1ad1c38f1f Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Thu, 10 Feb 2022 21:56:02 +0100 Subject: [PATCH] Improved the StringUtil::toCapitalized function. --- es-core/src/utils/StringUtil.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/es-core/src/utils/StringUtil.cpp b/es-core/src/utils/StringUtil.cpp index 2e40e86f6..5eb54e49f 100644 --- a/es-core/src/utils/StringUtil.cpp +++ b/es-core/src/utils/StringUtil.cpp @@ -546,17 +546,19 @@ namespace Utils std::string line {stringArg}; bool active {true}; - for (int i = 0; line[i] != '\0'; ++i) { - if (std::isalpha(line[i])) { + for (auto& chr : line) { + if (std::isalnum(chr)) { if (active) { - line[i] = Utils::String::toUpper(std::string(1, line[i]))[0]; + chr = std::toupper(chr); active = false; } - else - line[i] = Utils::String::toLower(std::string(1, line[i]))[0]; + else { + chr = std::tolower(chr); + } } - else if (line[i] == ' ' || line[i] == '\n' || line[i] == '\r' || line[i] == '\t') + else if (chr == ' ' || chr == '-' || chr == '\n' || chr == '\r' || chr == '\t') { active = true; + } } return line;