Skip to content

Commit 8a76e1d

Browse files
committed
SimpCfg: Templatize str_lower
1 parent b98c1bf commit 8a76e1d

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

common/simpcfg.hpp

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,25 @@
2222
*
2323
* It tries to provide a crude expanded form of array wrt any of the above supported types.
2424
* For this one needs to define keys using the pattern TheKeyName-0, TheKeyName-1, ....
25+
*
26+
* ## Additional notes
27+
*
28+
* NativeCharSize encoded char refers to chars which fit within the size of char type in a given
29+
* type of c++ string or base bitsize of a encoding standard, like 1 byte in case of std::string,
30+
* utf-8, ...
31+
* * example english alphabets in utf-8 encoding space are 1byte chars, in its variable length
32+
* encoding space.
33+
*
34+
* MultiNativeCharSize encoded char refers to chars which occupy multiple base-char-bit-size of
35+
* a c++ string type or char encoding standard.
36+
* * example indian scripts alphabets in utf-8 encoding space occupy multiple bytes in its variable
37+
* length encoding space.
38+
*
39+
* Sane variable length encoding - refers to encoding where the values of NativeCharSized chars of
40+
* a char encoding space cant overlap with values in NativeCharSize subparts of MultiNativeCharSized
41+
* chars of the same char encoding standard.
42+
* * utf-8 shows this behaviour
43+
* * chances are utf-16 and utf-32 also show this behaviour (need to cross check once)
2544
*/
2645

2746
#include <map>
@@ -163,6 +182,7 @@ std::string str_trim_oversmart(std::string sIn, const std::string &trimChars=" \
163182
// NOTE: Chars being trimmed (ie in trimChars) needs to be part of NativeCharSize
164183
// subset of the string's encoded char space, to avoid mix up when working with
165184
// strings which can be utf-8/utf-16/utf-32/sane-variable-length encoded strings.
185+
//
166186
// NOTE:UTF8: This will work provided the string being trimmed as well the chars
167187
// being trimmed are made up of 1byte encoded chars in case of utf8 encoding space.
168188
// If the string being trimmed includes multibyte (ie MultiNativeCharSize) encoded
@@ -193,13 +213,17 @@ TString str_trim_single(TString sin, const TString& trimChars=" \t\n") {
193213
return sin;
194214
}
195215

196-
// This works for 1byte encoded chars, including in utf8 encoding space.
216+
// This works for NativeCharSize encoded chars, including in utf8 encoding space.
197217
// This wont work for multibyte encoded chars.
198-
std::string str_tolower(const std::string &sin) {
199-
std::string sout;
218+
template <typename TString>
219+
TString str_tolower(const TString &sin) {
220+
TString sout;
200221
sout.resize(sin.size());
201-
std::transform(sin.begin(), sin.end(), sout.begin(), [](char c)->char {return std::tolower(c);});
202-
//LDBUG_LN("DBUG:%s:%s:%s", __func__, sin.c_str(), sout.c_str());
222+
std::transform(sin.begin(), sin.end(), sout.begin(), [](auto c)->auto {return std::tolower(c);});
223+
#ifdef SC_DEBUG_VERBOSE
224+
dumphex_string(sin, std::format("DBUG:{}:in:", __func__));
225+
dumphex_string(sout, std::format("DBUG:{}:out:", __func__));
226+
#endif
203227
return sout;
204228
}
205229

0 commit comments

Comments
 (0)