From 1a618a42f841d4be3d8c87bde83852ba6e03f431 Mon Sep 17 00:00:00 2001 From: HanishKVC Date: Thu, 2 May 2024 18:48:29 +0530 Subject: [PATCH] SimpCfg: Update the func notes with alert --- common/simpcfg.hpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/common/simpcfg.hpp b/common/simpcfg.hpp index e82d58b5b..21ef372af 100644 --- a/common/simpcfg.hpp +++ b/common/simpcfg.hpp @@ -36,6 +36,13 @@ #endif +// Remove chars from begin and end of the passed string, provided the char belongs +// to one of the chars in trimChars. +// NOTE: Chars being trimmed (ie trimChars) needs to be 1byte encoded chars. +// NOTE: This will work provided the string being trimmed as well the chars being +// trimmed are made up of 1byte encoded chars including in utf8 encoding space. +// If the string being trimmed includes multibyte encoded characters at the end, +// then trimming can mess things up. std::string str_trim(std::string sin, std::string trimChars=" \t\n") { sin.erase(sin.find_last_not_of(trimChars)+1); sin.erase(0, sin.find_first_not_of(trimChars)); @@ -44,8 +51,11 @@ std::string str_trim(std::string sin, std::string trimChars=" \t\n") { // Remove atmost 1 char at the begin and 1 char at the end of the passed string, // provided the char belongs to one of the chars in trimChars. -// NOTE: Not sure this handles non english utf8 multibyte chars properly, -// need to cross check. +// NOTE: Chars being trimmed (ie trimChars) needs to be 1byte encoded chars. +// NOTE: This will work provided the string being trimmed as well the chars being +// trimmed are made up of 1byte encoded chars including in utf8 encoding space. +// If the string being trimmed includes multibyte encoded characters at the end, +// then trimming can mess things up. std::string str_trim_single(std::string sin, std::string trimChars=" \t\n") { if (sin.empty()) return sin; for(auto c: trimChars) { @@ -64,6 +74,8 @@ std::string str_trim_single(std::string sin, std::string trimChars=" \t\n") { return sin; } +// This works for 1byte encoded chars, including in utf8 encoding space. +// This wont work for multibyte encoded chars. std::string str_tolower(const std::string &sin) { std::string sout; sout.resize(sin.size());