4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
10 * Full author contact details are available in file CREDITS.
13 #ifndef LYX_DOCSTRING_H
14 #define LYX_DOCSTRING_H
16 #include <boost/cstdint.hpp>
21 /// String type for storing the main text in UCS4 encoding
22 typedef std::basic_string<boost::uint32_t> docstring;
24 /// Creates a docstring from a C string of ASCII characters
25 docstring const from_ascii(char const *);
27 /// Creates a docstring from a std::string of ASCII characters
28 docstring const from_ascii(std::string const &);
30 /// Creates a docstring from a UTF8 string. This should go eventually.
31 docstring const from_utf8(std::string const &);
33 /// Creates a UTF8 string from a docstring. This should go eventually.
34 std::string const to_utf8(docstring const &);
38 /// Compare a docstring with a C string of ASCII characters
39 bool operator==(lyx::docstring const &, char const *);
41 /// Compare a C string of ASCII characters with a docstring
42 inline bool operator==(char const * l, lyx::docstring const & r) { return r == l; }
44 /// Compare a docstring with a C string of ASCII characters
45 inline bool operator!=(lyx::docstring const & l, char const * r) { return !(l == r); }
47 /// Compare a C string of ASCII characters with a docstring
48 inline bool operator!=(char const * l, lyx::docstring const & r) { return !(r == l); }
50 #if defined(__GNUC__) && defined(__GNUC_MINOR__) && __GNUC__ == 3 && __GNUC_MINOR__ < 4
51 // Missing char_traits methods in gcc 3.3 and older. Taken from gcc 4.2svn.
54 template<typename T> void
55 char_traits<T>::assign(char_type & c1, char_type const & c2)
61 template<typename T> bool
62 char_traits<T>::eq(char_type const & c1, char_type const & c2)
68 template<typename T> bool
69 char_traits<T>::lt(char_type const & c1, char_type const & c2)
75 template<typename T> int
76 char_traits<T>::compare(char_type const * s1, char_type const * s2, std::size_t n)
78 for (std::size_t i = 0; i < n; ++i)
81 else if (lt(s2[i], s1[i]))
87 template<typename T> std::size_t
88 char_traits<T>::length(char_type const * p)
91 while (!eq(p[i], char_type()))
97 template<typename T> typename char_traits<T>::char_type const *
98 char_traits<T>::find(char_type const * s, size_t n, char_type const & a)
100 for (std::size_t i = 0; i < n; ++i)
107 template<typename T> typename char_traits<T>::char_type *
108 char_traits<T>::move(char_type * s1, char_type const * s2, std::size_t n)
110 return static_cast<T *>(std::memmove(s1, s2, n * sizeof(char_type)));
114 template<typename T> typename char_traits<T>::char_type *
115 char_traits<T>::copy(char_type * s1, char_type const * s2, std::size_t n)
117 std::copy(s2, s2 + n, s1);
122 template<typename T> typename char_traits<T>::char_type *
123 char_traits<T>::assign(char_type * s, std::size_t n, char_type a)
125 std::fill_n(s, n, a);
130 template<typename T> typename char_traits<T>::char_type
131 char_traits<T>::to_char_type(int_type const & c)
133 return static_cast<char_type>(c);
137 template<typename T> typename char_traits<T>::int_type
138 char_traits<T>::to_int_type(char_type const & c)
140 return static_cast<int_type>(c);
144 template<typename T> bool
145 char_traits<T>::eq_int_type(int_type const & c1, int_type const & c2)
151 template<typename T> typename char_traits<T>::int_type
152 char_traits<T>::eof()
154 return static_cast<int_type>(EOF);
158 template<typename T> typename char_traits<T>::int_type
159 char_traits<T>::not_eof(int_type const & c)
161 return !eq_int_type(c, eof()) ? c : to_int_type(char_type());