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 "support/types.h"
22 /// String type for storing the main text in UCS4 encoding
23 typedef std::basic_string<char_type> docstring;
25 /// Creates a docstring from a C string of ASCII characters
26 docstring const from_ascii(char const *);
28 /// Creates a docstring from a std::string of ASCII characters
29 docstring const from_ascii(std::string const &);
31 /// Creates a docstring from a UTF8 string. This should go eventually.
32 docstring const from_utf8(std::string const &);
34 /// Creates a UTF8 string from a docstring. This should go eventually.
35 std::string const to_utf8(docstring const &);
39 /// Compare a docstring with a C string of ASCII characters
40 bool operator==(lyx::docstring const &, char const *);
42 /// Compare a C string of ASCII characters with a docstring
43 inline bool operator==(char const * l, lyx::docstring const & r) { return r == l; }
45 /// Compare a docstring with a C string of ASCII characters
46 inline bool operator!=(lyx::docstring const & l, char const * r) { return !(l == r); }
48 /// Compare a C string of ASCII characters with a docstring
49 inline bool operator!=(char const * l, lyx::docstring const & r) { return !(r == l); }
51 /// Concatenate a docstring and a C string of ASCII characters
52 lyx::docstring operator+(lyx::docstring const &, char const *);
54 /// Concatenate a C string of ASCII characters and a docstring
55 lyx::docstring operator+(char const *, lyx::docstring const &);
57 /// Concatenate a docstring and a single ASCII character
58 lyx::docstring operator+(lyx::docstring const & l, char r);
60 /// Concatenate a single ASCII character and a docstring
61 lyx::docstring operator+(char l, lyx::docstring const & r);
64 #if SIZEOF_WCHAR_T != 4 && defined(__GNUC__) && defined(__GNUC_MINOR__) && __GNUC__ == 3 && __GNUC_MINOR__ < 4
65 // Missing char_traits methods in gcc 3.3 and older. Taken from gcc 4.2svn.
68 template<typename T> void
69 char_traits<T>::assign(char_type & c1, char_type const & c2)
75 template<typename T> bool
76 char_traits<T>::eq(char_type const & c1, char_type const & c2)
82 template<typename T> bool
83 char_traits<T>::lt(char_type const & c1, char_type const & c2)
89 template<typename T> int
90 char_traits<T>::compare(char_type const * s1, char_type const * s2, std::size_t n)
92 for (std::size_t i = 0; i < n; ++i)
95 else if (lt(s2[i], s1[i]))
101 template<typename T> std::size_t
102 char_traits<T>::length(char_type const * p)
105 while (!eq(p[i], char_type()))
111 template<typename T> typename char_traits<T>::char_type const *
112 char_traits<T>::find(char_type const * s, size_t n, char_type const & a)
114 for (std::size_t i = 0; i < n; ++i)
121 template<typename T> typename char_traits<T>::char_type *
122 char_traits<T>::move(char_type * s1, char_type const * s2, std::size_t n)
124 return static_cast<T *>(std::memmove(s1, s2, n * sizeof(char_type)));
128 template<typename T> typename char_traits<T>::char_type *
129 char_traits<T>::copy(char_type * s1, char_type const * s2, std::size_t n)
131 std::copy(s2, s2 + n, s1);
136 template<typename T> typename char_traits<T>::char_type *
137 char_traits<T>::assign(char_type * s, std::size_t n, char_type a)
139 std::fill_n(s, n, a);
144 template<typename T> typename char_traits<T>::char_type
145 char_traits<T>::to_char_type(int_type const & c)
147 return static_cast<char_type>(c);
151 template<typename T> typename char_traits<T>::int_type
152 char_traits<T>::to_int_type(char_type const & c)
154 return static_cast<int_type>(c);
158 template<typename T> bool
159 char_traits<T>::eq_int_type(int_type const & c1, int_type const & c2)
165 template<typename T> typename char_traits<T>::int_type
166 char_traits<T>::eof()
168 return static_cast<int_type>(EOF);
172 template<typename T> typename char_traits<T>::int_type
173 char_traits<T>::not_eof(int_type const & c)
175 return !eq_int_type(c, eof()) ? c : to_int_type(char_type());