diff options
author | Andrzej Rybczak <electricityispower@gmail.com> | 2012-10-04 21:25:48 +0200 |
---|---|---|
committer | Andrzej Rybczak <electricityispower@gmail.com> | 2012-10-05 20:49:58 +0200 |
commit | e40edade0e005a28f7db0a7e6dc51a2acb734aae (patch) | |
tree | 42736c26aa4814a220ddf382187f6c6dcc3f62b3 /src/utility | |
parent | 802886c2e5184aadc663b311d13318240a137edf (diff) |
use boost.locale for charset conversions instead of iconv
Diffstat (limited to 'src/utility')
-rw-r--r-- | src/utility/wide_string.cpp | 24 | ||||
-rw-r--r-- | src/utility/wide_string.h | 4 |
2 files changed, 7 insertions, 21 deletions
diff --git a/src/utility/wide_string.cpp b/src/utility/wide_string.cpp index 71c2383a..193c9cf2 100644 --- a/src/utility/wide_string.cpp +++ b/src/utility/wide_string.cpp @@ -18,31 +18,17 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ +#include <boost/locale/encoding.hpp> #include "utility/wide_string.h" -std::string ToString(const std::wstring &ws) +std::string ToString(std::wstring ws) { - std::string result; - char s[MB_CUR_MAX]; - for (size_t i = 0; i < ws.length(); ++i) - { - int n = wcrtomb(s, ws[i], 0); - if (n > 0) - result.append(s, n); - } - return result; + return boost::locale::conv::utf_to_utf<char>(ws); } -std::wstring ToWString(const std::string &s) +std::wstring ToWString(std::string s) { - std::wstring result; - wchar_t *ws = new wchar_t[s.length()]; - const char *c_s = s.c_str(); - int n = mbsrtowcs(ws, &c_s, s.length(), 0); - if (n > 0) - result.append(ws, n); - delete [] ws; - return result; + return boost::locale::conv::utf_to_utf<wchar_t>(s); } size_t wideLength(const std::wstring &ws) diff --git a/src/utility/wide_string.h b/src/utility/wide_string.h index d3b3c9fa..58a013dd 100644 --- a/src/utility/wide_string.h +++ b/src/utility/wide_string.h @@ -23,8 +23,8 @@ #include <string> -std::string ToString(const std::wstring &ws); -std::wstring ToWString(const std::string &s); +std::string ToString(std::wstring ws); +std::wstring ToWString(std::string s); size_t wideLength(const std::wstring &ws); |