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 std::string of ASCII characters from a docstring
32 std::string const to_ascii(docstring const &);
34 /// Creates a docstring from a UTF8 string. This should go eventually.
35 docstring const from_utf8(std::string const &);
37 /// Creates a UTF8 string from a docstring. This should go eventually.
38 std::string const to_utf8(docstring const &);
40 /// Compare a docstring with a C string of ASCII characters
41 bool operator==(lyx::docstring const &, char const *);
43 /// Compare a C string of ASCII characters with a docstring
44 inline bool operator==(char const * l, lyx::docstring const & r) { return r == l; }
46 /// Compare a docstring with a C string of ASCII characters
47 inline bool operator!=(lyx::docstring const & l, char const * r) { return !(l == r); }
49 /// Compare a C string of ASCII characters with a docstring
50 inline bool operator!=(char const * l, lyx::docstring const & r) { return !(r == l); }
52 /// Concatenate a docstring and a C string of ASCII characters
53 lyx::docstring operator+(lyx::docstring const &, char const *);
55 /// Concatenate a C string of ASCII characters and a docstring
56 lyx::docstring operator+(char const *, lyx::docstring const &);
58 /// Concatenate a docstring and a single ASCII character
59 lyx::docstring operator+(lyx::docstring const & l, char r);
61 /// Concatenate a single ASCII character and a docstring
62 lyx::docstring operator+(char l, lyx::docstring const & r);
64 /// Append a C string of ASCII characters to a docstring
65 lyx::docstring & operator+=(lyx::docstring &, char const *);
67 /// Append a single ASCII character to a docstring
68 lyx::docstring & operator+=(lyx::docstring & l, char r);
73 #if SIZEOF_WCHAR_T != 4 && defined(__GNUC__) && defined(__GNUC_MINOR__) && __GNUC__ == 3 && __GNUC_MINOR__ < 4
74 // Missing char_traits methods in gcc 3.3 and older. Taken from gcc 4.2svn.
77 template<typename T> void
78 char_traits<T>::assign(char_type & c1, char_type const & c2)
84 template<typename T> bool
85 char_traits<T>::eq(char_type const & c1, char_type const & c2)
91 template<typename T> bool
92 char_traits<T>::lt(char_type const & c1, char_type const & c2)
98 template<typename T> int
99 char_traits<T>::compare(char_type const * s1, char_type const * s2, std::size_t n)
101 for (std::size_t i = 0; i < n; ++i)
102 if (lt(s1[i], s2[i]))
104 else if (lt(s2[i], s1[i]))
110 template<typename T> std::size_t
111 char_traits<T>::length(char_type const * p)
114 while (!eq(p[i], char_type()))
120 template<typename T> typename char_traits<T>::char_type const *
121 char_traits<T>::find(char_type const * s, size_t n, char_type const & a)
123 for (std::size_t i = 0; i < n; ++i)
130 template<typename T> typename char_traits<T>::char_type *
131 char_traits<T>::move(char_type * s1, char_type const * s2, std::size_t n)
133 return static_cast<T *>(std::memmove(s1, s2, n * sizeof(char_type)));
137 template<typename T> typename char_traits<T>::char_type *
138 char_traits<T>::copy(char_type * s1, char_type const * s2, std::size_t n)
140 std::copy(s2, s2 + n, s1);
145 template<typename T> typename char_traits<T>::char_type *
146 char_traits<T>::assign(char_type * s, std::size_t n, char_type a)
148 std::fill_n(s, n, a);
153 template<typename T> typename char_traits<T>::char_type
154 char_traits<T>::to_char_type(int_type const & c)
156 return static_cast<char_type>(c);
160 template<typename T> typename char_traits<T>::int_type
161 char_traits<T>::to_int_type(char_type const & c)
163 return static_cast<int_type>(c);
167 template<typename T> bool
168 char_traits<T>::eq_int_type(int_type const & c1, int_type const & c2)
174 template<typename T> typename char_traits<T>::int_type
175 char_traits<T>::eof()
177 return static_cast<int_type>(EOF);
181 template<typename T> typename char_traits<T>::int_type
182 char_traits<T>::not_eof(int_type const & c)
184 return !eq_int_type(c, eof()) ? c : to_int_type(char_type());