3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "docstring.h"
16 #include <boost/assert.hpp>
21 docstring const from_ascii(char const * ascii)
24 for (char const * c = ascii; *c; ++c) {
25 BOOST_ASSERT(static_cast<unsigned char>(*c) < 0x80);
32 docstring const from_ascii(std::string const & ascii)
34 int const len = ascii.length();
35 for (int i = 0; i < len; ++i)
36 BOOST_ASSERT(static_cast<unsigned char>(ascii[i]) < 0x80);
37 return docstring(ascii.begin(), ascii.end());
41 docstring const from_utf8(std::string const & utf8)
43 std::vector<boost::uint32_t> const ucs4 =
44 utf8_to_ucs4(std::vector<char>(utf8.begin(), utf8.end()));
45 return docstring(ucs4.begin(), ucs4.end());
49 std::string const to_utf8(docstring const & ucs4)
51 std::vector<char> const utf8 =
52 ucs4_to_utf8(std::vector<boost::uint32_t>(ucs4.begin(), ucs4.end()));
53 return std::string(utf8.begin(), utf8.end());
59 bool operator==(lyx::docstring const & l, char const * r)
61 int const len = l.length();
62 for (int i = 0; i < len; ++i) {
63 BOOST_ASSERT(static_cast<unsigned char>(r[i]) < 0x80);
66 if (l[i] != lyx::docstring::value_type(r[i]))
69 return r[len] == '\0';