use boost.locale for charset conversions instead of iconv

This commit is contained in:
Andrzej Rybczak
2012-10-04 21:25:48 +02:00
parent 802886c2e5
commit e40edade0e
12 changed files with 53 additions and 202 deletions

View File

@@ -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)

View File

@@ -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);