]> git.lyx.org Git - lyx.git/blob - src/support/docstring.h
165772cdf28d4ad5b84fe82c56d763d81dbacfa3
[lyx.git] / src / support / docstring.h
1 // -*- C++ -*-
2 /**
3  * \file docstring.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author Georg Baum
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef LYX_DOCSTRING_H
14 #define LYX_DOCSTRING_H
15
16 #include "support/strfwd.h"
17
18 #include <string>
19
20 namespace lyx {
21
22 /// String type for storing the main text in UCS4 encoding
23 typedef std::basic_string<char_type> docstring;
24
25 } // namespace lyx
26
27
28 #if ! defined(USE_WCHAR_T) && defined(__GNUC__) && defined(__GNUC_MINOR__) && __GNUC__ == 3 && __GNUC_MINOR__ < 4
29 // Missing char_traits methods in gcc 3.3 and older. Taken from gcc 4.2svn.
30 namespace std {
31
32 template<typename T> void
33 char_traits<T>::assign(char_type & c1, char_type const & c2)
34 {
35         c1 = c2;
36 }
37
38
39 template<typename T> bool
40 char_traits<T>::eq(char_type const & c1, char_type const & c2)
41 {
42         return c1 == c2;
43 }
44
45
46 template<typename T> bool
47 char_traits<T>::lt(char_type const & c1, char_type const & c2)
48 {
49         return c1 < c2;
50 }
51
52
53 template<typename T> int
54 char_traits<T>::compare(char_type const * s1, char_type const * s2, std::size_t n)
55 {
56         for (std::size_t i = 0; i < n; ++i)
57                 if (lt(s1[i], s2[i]))
58                         return -1;
59                 else if (lt(s2[i], s1[i]))
60                         return 1;
61         return 0;
62 }
63
64
65 template<typename T> std::size_t
66 char_traits<T>::length(char_type const * p)
67 {
68         std::size_t i = 0;
69         while (!eq(p[i], char_type()))
70                 ++i;
71         return i;
72 }
73
74
75 template<typename T> typename char_traits<T>::char_type const *
76 char_traits<T>::find(char_type const * s, size_t n, char_type const & a)
77 {
78         for (std::size_t i = 0; i < n; ++i)
79                 if (eq(s[i], a))
80                         return s + i;
81         return 0;
82 }
83
84
85 template<typename T> typename char_traits<T>::char_type *
86 char_traits<T>::move(char_type * s1, char_type const * s2, std::size_t n)
87 {
88         return static_cast<T *>(std::memmove(s1, s2, n * sizeof(char_type)));
89 }
90
91
92 template<typename T> typename char_traits<T>::char_type *
93 char_traits<T>::copy(char_type * s1, char_type const * s2, std::size_t n)
94 {
95         std::copy(s2, s2 + n, s1);
96         return s1;
97 }
98
99
100 template<typename T> typename char_traits<T>::char_type *
101 char_traits<T>::assign(char_type * s, std::size_t n, char_type a)
102 {
103         std::fill_n(s, n, a);
104         return s;
105 }
106
107
108 template<typename T> typename char_traits<T>::char_type
109 char_traits<T>::to_char_type(int_type const & c)
110 {
111         return static_cast<char_type>(c);
112 }
113
114
115 template<typename T> typename char_traits<T>::int_type
116 char_traits<T>::to_int_type(char_type const & c)
117 {
118         return static_cast<int_type>(c);
119 }
120
121
122 template<typename T> bool
123 char_traits<T>::eq_int_type(int_type const & c1, int_type const & c2)
124 {
125         return c1 == c2;
126 }
127
128
129 template<typename T> typename char_traits<T>::int_type
130 char_traits<T>::eof()
131 {
132         return static_cast<int_type>(EOF);
133 }
134
135
136 template<typename T> typename char_traits<T>::int_type
137 char_traits<T>::not_eof(int_type const & c)
138 {
139         return !eq_int_type(c, eof()) ? c : to_int_type(char_type());
140 }
141
142 }
143 #endif
144 #endif