1212#include < algorithm>
1313#include < sstream>
1414
15+ #ifndef VA_STR
1516#define VA_STR (x ) static_cast <std::ostringstream&>(std::ostringstream().flush() << x).str()
17+ #endif
1618
1719struct String // a "namespace" not requiring a cpp nor inlining to avoid "unused function" warnings
1820{
19- static std::string& tolower (std::string& str)
21+ static void tolower (std::string& str)
2022 {
2123 std::transform (str.begin (), str.end (), str.begin (), ::tolower);
22- return str;
2324 }
2425
25- static std::string& toupper (std::string& str)
26+ static void toupper (std::string& str)
2627 {
2728 std::transform (str.begin (), str.end (), str.begin (), ::toupper);
28- return str;
2929 }
3030
31- static std::string& ltrim (std::string& str)
31+ static void ltrim (std::string& str)
3232 {
3333 std::string::iterator i = str.begin ();
3434 while (i != str.end ()) if (!std::isspace (*i)) break ; else ++i;
3535 str.erase (str.begin (), i);
36- return str;
3736 }
3837
39- static std::string& rtrim (std::string& str)
38+ static void rtrim (std::string& str)
4039 {
4140 std::string::iterator i = str.end ();
4241 while (i != str.begin ()) if (!std::isspace (*(--i))) { ++i; break ; }
4342 str.erase (i, str.end ());
44- return str;
4543 }
4644
47- static std::string& trim (std::string& str)
45+ static void trim (std::string& str)
4846 {
49- return ltrim (rtrim (str));
47+ rtrim (str);
48+ ltrim (str);
49+ }
50+
51+ static std::string trimmed (std::string str)
52+ {
53+ trim (str);
54+ return str;
5055 }
5156
5257 static std::string right (const std::string& str, std::string::size_type count)
5358 {
5459 return str.substr (str.size () - std::min (count, str.size ()));
5560 }
5661
57- static std::string& replaceAll (std::string& str, const std::string& sWhat , const std::string& sWith )
62+ static void replaceAll (std::string& str, const std::string& sWhat , const std::string& sWith )
5863 {
5964 std::string::size_type lookHere = 0 ;
6065 std::string::size_type foundHere;
@@ -63,7 +68,6 @@ struct String // a "namespace" not requiring a cpp nor inlining to avoid "unused
6368 str.replace (foundHere, sWhat .size (), sWith );
6469 lookHere = foundHere + sWith .size ();
6570 }
66- return str;
6771 }
6872
6973 template <typename T> static void split (const std::string& str, const char delimiter, T& result, bool trimmed = true )
0 commit comments