]> git.lyx.org Git - lyx.git/blobdiff - src/support/docstring.C
* support/qstring_helpers.h: erase ucs4_to_qstring() method.
[lyx.git] / src / support / docstring.C
index 3c1c80abb20fcd37d713854b0ec4f4c066c6426d..89abf212991ebf5fec66865e629fb5b95f05f688 100644 (file)
@@ -17,6 +17,8 @@
 #include <locale>
 #include <iostream>
 
+#include <QFile>
+
 #include <boost/assert.hpp>
 
 
@@ -56,6 +58,14 @@ std::string const to_ascii(docstring const & ucs4)
 }
 
 
+IconvProcessor & utf8ToUcs4()
+{
+       static IconvProcessor iconv(ucs4_codeset, "UTF-8");
+       return iconv;
+}
+
+
+
 void utf8_to_ucs4(std::string const & utf8, docstring & ucs4)
 {
        size_t n = utf8.size();
@@ -116,6 +126,20 @@ std::string const to_local8bit(docstring const & s)
 }
 
 
+docstring const from_filesystem8bit(std::string const & s)
+{
+       QByteArray const encoded(s.c_str(), s.length());
+       return qstring_to_ucs4(QFile::decodeName(encoded));
+}
+
+
+std::string const to_filesystem8bit(docstring const & s)
+{
+       QByteArray const encoded = QFile::encodeName(toqstr(s));
+       return std::string(encoded.begin(), encoded.end());
+}
+
+
 bool operator==(lyx::docstring const & l, char const * r)
 {
        int const len = l.length();
@@ -439,15 +463,69 @@ public:
        };
 
 protected:
+       iter_type
+       do_put(iter_type oit, std::ios_base & b, char_type fill, bool v) const
+       {
+               return do_put_helper(oit, b, fill, v);
+       }
+
        iter_type
        do_put(iter_type oit, std::ios_base & b, char_type fill, long v) const
+       {
+               return do_put_helper(oit, b, fill, v);
+       }
+
+       iter_type
+       do_put(iter_type oit, std::ios_base & b, char_type fill, unsigned long v) const
+       {
+               return do_put_helper(oit, b, fill, v);
+       }
+
+#ifdef _GLIBCXX_USE_LONG_LONG
+       iter_type
+       do_put(iter_type oit, std::ios_base & b, char_type fill, long long v) const
+       {
+               return do_put_helper(oit, b, fill, v);
+       }
+
+       iter_type
+       do_put(iter_type oit, std::ios_base & b, char_type fill, unsigned long long v) const
+       {
+               return do_put_helper(oit, b, fill, v);
+       }
+#endif
+
+       iter_type
+       do_put(iter_type oit, std::ios_base & b, char_type fill, double v) const
+       {
+               return do_put_helper(oit, b, fill, v);
+       }
+
+       iter_type
+       do_put(iter_type oit, std::ios_base & b, char_type fill, long double v) const
+       {
+               return do_put_helper(oit, b, fill, v);
+       }
+
+       iter_type
+       do_put(iter_type oit, std::ios_base & b, char_type fill, void const * v) const
+       {
+               return do_put_helper(oit, b, fill, v);
+       }
+
+private:
+       template <typename ValueType>
+       iter_type
+       do_put_helper(iter_type oit, std::ios_base & b, char_type fill, ValueType v) const
        {
                if (fill >= 0x80)
                        throw num_put_failure();
 
-               std::string s;
-               // 64 is large enough
-               s.resize(64);
+               std::streamsize const sz = b.width() > b.precision() ?
+                                          b.width() : b.precision();
+               // 64 is large enough, unless width or precision are bigger
+               std::streamsize const wd = (sz > 56 ? sz : 56) + 8;
+               std::string s(wd, '\0');
                string_num_put_facet f;
                std::string::const_iterator cit = s.begin();
                std::string::const_iterator end =