Skip to content

Commit 989c6c0

Browse files
committed
SimpCfg:Fix/cleanup trim related test samples and flow
Use the commonality between Indian languages to show mixup issue with the simple minded trim_dump logic and how trim_oversmart could potentially avoid that. Given that I am using valid strings to show the pitfalls of fixed native char size driven logic, so no need to keep the dump and oversmart flows seperate, so merge into a common loop.
1 parent 8a76e1d commit 989c6c0

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

common/simpcfg.hpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -541,18 +541,15 @@ void check_nonenglish() {
541541
std::string sGotOSmart = str_trim_oversmart(sTest, {" \n\t"});
542542
std::cout << std::format("{}: Test1[{}] Dumb[{}] OverSmart[{}]", __func__, sTest, sGotDumb, sGotOSmart) << std::endl;
543543
}
544-
std::vector<std::string> vTest2 = { "\n\t this र remove 0s at end 000 ", "\n\tthis र remove 0s and अs at end 000रअ0अ ", "\n\tthis र remove 0s and अs at end 000रअ0\xa4"};
544+
// The string "\n\tthis र remove 0s and अs at end 000रअ0\xa4अ ",
545+
// * will mess up str_trim_dumb,
546+
// * but will rightly trigger a exception with oversmart.
547+
std::vector<std::string> vTest2 = { "\n\t this र remove 0s at end 000 ", "\n\tthis र remove 0s, अs, ഇs at end 000रअ0अ ", "\n\tthis र remove 0s, अs, ഇs at end 000रअ0इअ "};
548+
std::string trimChars = {" \n\tഇ0अ"};
545549
for (auto sTest: vTest2) {
546-
std::string sGotDumb = str_trim_dumb(sTest, {" \n\t0अ"});
547-
std::cout << std::format("{}: Test2[{}] Dumb[{}]", __func__, sTest, sGotDumb) << std::endl;
548-
}
549-
// This partly invalid utf8 string will mess up str_trim_dumb "\n\tthis र remove 0s and अs at end 000रअ0\xa4अ "
550-
// but will trigger a exception with oversmart.
551-
// std::vector<std::string> vTest3 = { "\n\t this र remove 0s at end 000 ", "\n\tthis र remove 0s and अs at end 000रअ0अ ", "\n\tthis र remove 0s and अs at end 000रअ0\xa4अ "};
552-
std::vector<std::string> vTest3 = { "\n\t this र remove 0s at end 000 ", "\n\tthis र remove 0s and अs at end 000रअ0अ ", "\n\tthis र remove 0s and अs at end 000रअ0\xe0\xa4\x30"}; // \xe0\xa4
553-
for (auto sTest: vTest3) {
554-
std::string sGotOSmart = str_trim_oversmart(sTest, {" \n\t0अ"});
555-
std::cout << std::format("{}: Test3[{}] OverSmart[{}]", __func__, sTest, sGotOSmart) << std::endl;
550+
std::string sGotDumb = str_trim_dumb(sTest, trimChars);
551+
std::string sGotOSmart = str_trim_oversmart(sTest, trimChars);
552+
std::cout << std::format("{}: Test2 [{}]\n\tDumb[{}]\n\tOverSmart[{}]", __func__, sTest, sGotDumb, sGotOSmart) << std::endl;
556553
}
557554
}
558555

0 commit comments

Comments
 (0)