From: Gert van Valkenhoef Date: Mon, 14 Nov 2011 10:18:36 +0000 (+0000) Subject: Properly detect locale's charset X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=20613bcf69e139c028704661ad16536217f10990;p=odcread.git Properly detect locale's charset --- diff --git a/odcread.cc b/odcread.cc index fc210a8..891ea99 100644 --- a/odcread.cc +++ b/odcread.cc @@ -10,10 +10,11 @@ #include // Character encoding conversions -#include -#include -#include -#include +#include // determine the current charset +#include // locale support +#include // charset conversions +#include // error codes +#include // string descriptions of error codes namespace odc { class Context { @@ -87,10 +88,10 @@ namespace odc { terminateContext(); } char *getCharSet() { - return "UTF-8"; // FIXME setlocale(LC_CTYPE, 0) + processing + return nl_langinfo(CODESET); } virtual void textShortPiece(const ShortPiece *piece) { - iconv_t conv = iconv_open("UTF-8", "ISO-8859-1"); + iconv_t conv = iconv_open(getCharSet(), "ISO-8859-1"); if (conv == (iconv_t)-1) { std::string str("iconv initialization error: "); str += strerror(errno); @@ -121,7 +122,7 @@ namespace odc { d_context.top()->addPiece(str); */ //d_convLong = iconv_open(setlocale(LC_CTYPE, 0), "UCS-2"); - iconv_t conv = iconv_open("UTF-8", "UCS-2"); + iconv_t conv = iconv_open(getCharSet(), "UCS-2"); if (conv == (iconv_t)-1) { std::string str("iconv initialization error: "); str += strerror(errno);