]> git.lyx.org Git - features.git/commitdiff
More unicode work. Fixup some usages.
authorLars Gullik Bjønnes <larsbj@gullik.org>
Sun, 10 Sep 2006 18:34:24 +0000 (18:34 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Sun, 10 Sep 2006 18:34:24 +0000 (18:34 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14968 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt3/QLyXKeySym.C
src/frontends/qt3/qt_helpers.C
src/lyxlex_pimpl.C
src/support/docstring.C
src/support/unicode.C
src/support/unicode.h

index 27ab911f86ade88c80da3d19dc7b4c74dadc3633..fd01db4c51b1ad7b7998f43b43657d6af7f30586 100644 (file)
@@ -202,18 +202,18 @@ string QLyXKeySym::getSymbolName() const
 
 size_t QLyXKeySym::getUCSEncoded() const
 {
-    unsigned short const * ptr = text_.ucs2();
-    std::vector<unsigned short> tmp(ptr, ptr + text_.length());
+    if (text_.isEmpty())
+       return 0;
+
+    //unsigned short const * ptr = text_.ucs2();
+    //std::vector<unsigned short> tmp(ptr, ptr + text_.length());
 
     //lyxerr << "Data is " << tmp << endl;
     //lyxerr << "Length is " << text_.length() << endl;
 
-    if (text_.isEmpty())
-       return 0;
-
     //size_t res = utf8_to_ucs4(tmp, tmp.length());
     //lyxerr << "Res is " << res << endl;
-    return ucs2_to_ucs4(tmp)[0];
+    return ucs2_to_ucs4(text_.ucs2(), text_.length())[0];
 }
 
 
index 2f893355472daa491835c98ecf734b62657b7711..0458e9a17441f628e6df617ca844a886029b70a8 100644 (file)
@@ -120,7 +120,7 @@ QString const toqstr(string const & str)
 QString const toqstr(docstring const & str)
 {
        std::vector<unsigned short> ucs2 =
-               ucs4_to_ucs2(str.c_str(), str.length());
+               ucs4_to_ucs2(str.data(), str.length());
        ucs2.push_back('\0');
        return QString::fromUcs2(&ucs2[0]);
 }
@@ -149,8 +149,7 @@ string const fromqstr(QString const & str)
 docstring const qstring_to_ucs4(QString const & str)
 {
        unsigned short const * const ucs2 = str.ucs2();
-       std::vector<char_type> const ucs4 = ucs2_to_ucs4(
-               std::vector<unsigned short>(ucs2, ucs2 + str.length()));
+       std::vector<char_type> const ucs4 = ucs2_to_ucs4(ucs2, str.length());
        return docstring(ucs4.begin(), ucs4.end());
 }
 
index 3d66b7efd1c23d3b8d9762ed84ef2ec64f613c40..9007d31c44861c01be38fa803967b8139e59761f 100644 (file)
@@ -73,9 +73,9 @@ string const LyXLex::Pimpl::getString() const
 
 lyx::docstring const LyXLex::Pimpl::getDocString() const
 {
-        std::vector<boost::uint32_t> res = utf8_to_ucs4(buff);
-        lyx::docstring dstr(res.begin(), res.end());
-        return dstr;
+       std::vector<boost::uint32_t> res = utf8_to_ucs4(buff);
+       lyx::docstring dstr(res.begin(), res.end());
+       return dstr;
 }
 
 
index de3404c41e01c3b0fd13e1c763a76fc5e7b1156a..fb3115ba9aacb4e5ca047336f27c50c88be4c0ad 100644 (file)
@@ -41,7 +41,7 @@ docstring const from_ascii(std::string const & ascii)
 docstring const from_utf8(std::string const & utf8)
 {
        std::vector<boost::uint32_t> const ucs4 =
-               utf8_to_ucs4(std::vector<char>(utf8.begin(), utf8.end()));
+               utf8_to_ucs4(utf8.data(), utf8.size());
        return docstring(ucs4.begin(), ucs4.end());
 }
 
@@ -49,7 +49,7 @@ docstring const from_utf8(std::string const & utf8)
 std::string const to_utf8(docstring const & ucs4)
 {
        std::vector<char> const utf8 =
-               ucs4_to_utf8(std::vector<boost::uint32_t>(ucs4.begin(), ucs4.end()));
+               ucs4_to_utf8(ucs4.data(), ucs4.size());
        return std::string(utf8.begin(), utf8.end());
 }
 
index 5c09a0d73b4b50b898889b66e78716108458d28d..650962ab9b6293876b96c4f3610922b12e44c287 100644 (file)
@@ -125,19 +125,47 @@ iconv_convert(iconv_t * cd,
 
 
 std::vector<boost::uint32_t> utf8_to_ucs4(std::vector<char> const & utf8str)
+{
+       return utf8_to_ucs4(&utf8str[0], utf8str.size());
+}
+
+
+std::vector<boost::uint32_t>
+utf8_to_ucs4(char const * utf8str, size_t ls)
 {
        static iconv_t cd = (iconv_t)(-1);
        return iconv_convert<boost::uint32_t>(&cd, ucs4_codeset, "UTF-8",
-                                             &utf8str[0], utf8str.size());
+                                             utf8str, ls);
+}
+
+
+boost::uint32_t
+ucs2_to_ucs4(unsigned short c)
+{
+       return ucs2_to_ucs4(&c, 1)[0];
 }
 
 
 std::vector<boost::uint32_t>
 ucs2_to_ucs4(std::vector<unsigned short> const & ucs2str)
+{
+       return ucs2_to_ucs4(&ucs2str[0], ucs2str.size());
+}
+
+
+std::vector<boost::uint32_t>
+ucs2_to_ucs4(unsigned short const * ucs2str, size_t ls)
 {
        static iconv_t cd = (iconv_t)(-1);
        return iconv_convert<boost::uint32_t>(&cd, ucs4_codeset, ucs2_codeset,
-                                             &ucs2str[0], ucs2str.size());
+                                             ucs2str, ls);
+}
+
+
+unsigned short
+ucs4_to_ucs2(boost::uint32_t c)
+{
+       return ucs4_to_ucs2(&c, 1)[0];
 }
 
 
@@ -157,24 +185,25 @@ ucs4_to_ucs2(boost::uint32_t const * s, size_t ls)
 }
 
 
-unsigned short
-ucs4_to_ucs2(boost::uint32_t c)
+std::vector<char>
+ucs4_to_utf8(boost::uint32_t c)
 {
-       boost::uint32_t tmp[] = { c, 0 };
-       return ucs4_to_ucs2(tmp, 1)[0];
+       static iconv_t cd = (iconv_t)(-1);
+       return iconv_convert<char>(&cd, "UTF-8", ucs4_codeset, &c, 1);
 }
 
 
-std::vector<char> ucs4_to_utf8(std::vector<boost::uint32_t> const & ucs4str)
+std::vector<char>
+ucs4_to_utf8(std::vector<boost::uint32_t> const & ucs4str)
 {
-       static iconv_t cd = (iconv_t)(-1);
-       return iconv_convert<char>(&cd, "UTF-8", ucs4_codeset,
-                                  &ucs4str[0], ucs4str.size());
+       return ucs4_to_utf8(&ucs4str[0], ucs4str.size());
 }
 
 
-std::vector<char> ucs4_to_utf8(boost::uint32_t c)
+std::vector<char>
+ucs4_to_utf8(boost::uint32_t const * ucs4str, size_t ls)
 {
        static iconv_t cd = (iconv_t)(-1);
-       return iconv_convert<char>(&cd, "UTF-8", ucs4_codeset, &c, 1);
+       return iconv_convert<char>(&cd, "UTF-8", ucs4_codeset,
+                                  ucs4str, ls);
 }
index 21ff21afb5d61fb5847abcaece15a46a1c96a65f..977ded6fd8d0377cc1c91cf5ce28541d2f72662c 100644 (file)
 #include <boost/cstdint.hpp>
 #include <vector>
 
+// utf8_to_ucs4
+
+// A single codepoint conversion for utf8_to_ucs4 does not make
+// sense, so that function is left out.
+
 std::vector<boost::uint32_t>
 utf8_to_ucs4(std::vector<char> const & utf8str);
 
+std::vector<boost::uint32_t>
+utf8_to_ucs4(char const * utf8str, size_t ls);
+
+// ucs2_to_ucs4
+
+boost::uint32_t
+ucs2_to_ucs4(unsigned short c);
+
 std::vector<boost::uint32_t>
 ucs2_to_ucs4(std::vector<unsigned short> const & ucs2str);
 
+std::vector<boost::uint32_t>
+ucs2_to_ucs4(unsigned short const * ucs2str, size_t ls);
+
+// ucs4_to_ucs2
+
+unsigned short
+ucs4_to_ucs2(boost::uint32_t c);
+
 std::vector<unsigned short>
 ucs4_to_ucs2(std::vector<boost::uint32_t> const & ucs4str);
 
 std::vector<unsigned short>
 ucs4_to_ucs2(boost::uint32_t const * s, size_t ls);
 
-unsigned short
-ucs4_to_ucs2(boost::uint32_t c);
+// ucs4_to_utf8
+
+std::vector<char>
+ucs4_to_utf8(boost::uint32_t c);
 
 std::vector<char>
 ucs4_to_utf8(std::vector<boost::uint32_t> const & ucs4str);
 
 std::vector<char>
-ucs4_to_utf8(boost::uint32_t c);
+ucs4_to_utf8(boost::uint32_t const * ucs4str, size_t ls);
 
 #endif