aboutsummaryrefslogtreecommitdiffstats
path: root/src/utility/stringUtils.cpp
diff options
context:
space:
mode:
authorVincent Richard <[email protected]>2006-11-08 18:33:18 +0000
committerVincent Richard <[email protected]>2006-11-08 18:33:18 +0000
commitf99fc84915e4bcd2750b7fadfb24f858ccc7e5ef (patch)
treeb3c8fa78d8b145ff04aca8b17a4a74dbc348cd15 /src/utility/stringUtils.cpp
parentFixed compilation problem with GCC 3.3. (diff)
downloadvmime-f99fc84915e4bcd2750b7fadfb24f858ccc7e5ef.tar.gz
vmime-f99fc84915e4bcd2750b7fadfb24f858ccc7e5ef.zip
Imbue classic 'C' locale for the output of message parts and protocol commands.
Diffstat (limited to 'src/utility/stringUtils.cpp')
-rw-r--r--src/utility/stringUtils.cpp25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/utility/stringUtils.cpp b/src/utility/stringUtils.cpp
index ea9ffec4..dab01f15 100644
--- a/src/utility/stringUtils.cpp
+++ b/src/utility/stringUtils.cpp
@@ -33,10 +33,13 @@ const bool stringUtils::isStringEqualNoCase
if (s1.length() < n)
return (false);
+ const std::ctype <unsigned char>& fac =
+ std::use_facet <std::ctype <unsigned char> >(std::locale::classic());
+
bool equal = true;
for (string::size_type i = 0 ; equal && i < n ; ++i)
- equal = (std::tolower(s1[i], std::locale()) == s2[i]);
+ equal = (fac.tolower(static_cast <unsigned char>(s1[i])) == s2[i]);
return (equal);
}
@@ -47,11 +50,14 @@ const bool stringUtils::isStringEqualNoCase(const string& s1, const string& s2)
if (s1.length() != s2.length())
return (false);
+ const std::ctype <unsigned char>& fac =
+ std::use_facet <std::ctype <unsigned char> >(std::locale::classic());
+
bool equal = true;
const string::const_iterator end = s1.end();
for (string::const_iterator i = s1.begin(), j = s2.begin(); i != end ; ++i, ++j)
- equal = (std::tolower(*i, std::locale()) == std::tolower(*j, std::locale()));
+ equal = (fac.tolower(static_cast <unsigned char>(*i)) == fac.tolower(static_cast <unsigned char>(*j)));
return (equal);
}
@@ -64,12 +70,15 @@ const bool stringUtils::isStringEqualNoCase
if (static_cast <string::size_type>(end - begin) < n)
return (false);
+ const std::ctype <unsigned char>& fac =
+ std::use_facet <std::ctype <unsigned char> >(std::locale::classic());
+
bool equal = true;
char* c = const_cast<char*>(s);
string::size_type r = n;
for (string::const_iterator i = begin ; equal && r && *c ; ++i, ++c, --r)
- equal = (std::tolower(*i, std::locale()) == *c);
+ equal = (fac.tolower(static_cast <unsigned char>(*i)) == static_cast <unsigned char>(*c));
return (r == 0 && equal);
}
@@ -77,11 +86,14 @@ const bool stringUtils::isStringEqualNoCase
const string stringUtils::toLower(const string& str)
{
+ const std::ctype <unsigned char>& fac =
+ std::use_facet <std::ctype <unsigned char> >(std::locale::classic());
+
string out;
out.resize(str.size());
for (string::size_type i = 0, len = str.length() ; i < len ; ++i)
- out[i] = std::tolower(str[i], std::locale());
+ out[i] = fac.tolower(static_cast <unsigned char>(str[i]));
return out;
}
@@ -89,11 +101,14 @@ const string stringUtils::toLower(const string& str)
const string stringUtils::toUpper(const string& str)
{
+ const std::ctype <unsigned char>& fac =
+ std::use_facet <std::ctype <unsigned char> >(std::locale::classic());
+
string out;
out.resize(str.size());
for (string::size_type i = 0, len = str.length() ; i < len ; ++i)
- out[i] = std::toupper(str[i], std::locale());
+ out[i] = fac.toupper(static_cast <unsigned char>(str[i]));
return out;
}