DEADSOFTWARE

Properly detect locale's charset
authorGert van Valkenhoef <g.h.m.van.valkenhoef@rug.nl>
Mon, 14 Nov 2011 10:18:36 +0000 (10:18 +0000)
committerGert van Valkenhoef <g.h.m.van.valkenhoef@rug.nl>
Mon, 14 Nov 2011 10:18:36 +0000 (10:18 +0000)
odcread.cc

index fc210a8a10c59f5cc0e0660a711a702114b2bc9e..891ea990102ba11cd63da7e952d66b4c2a3c379f 100644 (file)
 #include <visitor.h>
 
 // Character encoding conversions
-#include <locale.h>
-#include <iconv.h>
-#include <errno.h>
-#include <string.h>
+#include <langinfo.h> // determine the current charset
+#include <locale.h> // locale support
+#include <iconv.h> // charset conversions
+#include <errno.h> // error codes
+#include <string.h> // 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);