]> git.lyx.org Git - lyx.git/blobdiff - src/support/docstring.cpp
InsetTabular.cpp: fix #6585 also for wrapped floats - thanks Vincent
[lyx.git] / src / support / docstring.cpp
index 6de9424c1b5822d2d963b4a0e22e3b93d2b5f426..86deda1d869de654064c2a38c661d47c08c93a48 100644 (file)
@@ -31,12 +31,13 @@ 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;
 }
@@ -151,6 +152,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));