]> git.lyx.org Git - lyx.git/blobdiff - src/support/docstring.cpp
Make it compile again on systems that don't USE_WCHAR_T
[lyx.git] / src / support / docstring.cpp
index 6de9424c1b5822d2d963b4a0e22e3b93d2b5f426..eae38f19b698f234c156ed58c87ecd998998407c 100644 (file)
 
 #include <QFile>
 
+#if ! defined(USE_WCHAR_T) && defined(__GNUC__)
 #include <locale>
 #include <iostream>
 #include <typeinfo>
+#endif
 
 using namespace std;
 
+using lyx::support::isHexChar;
 
 namespace lyx {
 
 docstring const from_ascii(char const * ascii)
 {
        docstring s;
-       int n = strlen(ascii);
-       s.resize(n);
-       char_type *d = &s[0];
-       while (--n >= 0) {
-               d[n] = ascii[n];
-               LASSERT(static_cast<unsigned char>(ascii[n]) < 0x80, /**/);
+       if (int n = strlen(ascii)) {
+               s.resize(n);
+               char_type *d = &s[0];
+               while (--n >= 0) {
+                       d[n] = ascii[n];
+                       LASSERT(static_cast<unsigned char>(ascii[n]) < 0x80, /**/);
+               }
        }
        return s;
 }
@@ -131,7 +135,7 @@ string const to_local8bit(docstring const & s)
        if (s.empty())
                return string();
        QByteArray const local = toqstr(s).toLocal8Bit();
-       if (local.size() == 0)
+       if (local.isEmpty())
                throw to_local8bit_failure();
        return string(local.begin(), local.end());
 }
@@ -151,6 +155,22 @@ string const to_filesystem8bit(docstring const & s)
 }
 
 
+string const to_iconv_encoding(docstring const & s, string const & encoding)
+{
+       std::vector<char> const encoded =
+               ucs4_to_eightbit(s.data(), s.length(), encoding);
+       return string(encoded.begin(), encoded.end());
+}
+
+
+docstring const from_iconv_encoding(string const & s, string const & encoding)
+{
+       std::vector<char_type> const ucs4 =
+               eightbit_to_ucs4(s.data(), s.length(), encoding);
+       return docstring(ucs4.begin(), ucs4.end());
+}
+
+
 docstring const normalize_c(docstring const & s)
 {
        return qstring_to_ucs4(toqstr(s).normalized(QString::NormalizationForm_C));
@@ -736,9 +756,9 @@ private:
        bool isNumpunct(lyx::char_type const c) const
        {
                /// Only account for the standard numpunct "C" locale facet.
-               return c < 0x80 && (c == '-' || c == '+' || isdigit(c)
-                       || ('a' <= c && c <= 'f') || ('A' <= c && c <= 'F')
-                       || c == 'x' || c == 'X');
+               return c == '-' || c == '+'
+                       || c == 'x' || c == 'X'
+                       || isHexChar(c);
        }
 
        template <typename ValueType>