]> git.lyx.org Git - lyx.git/blob - src/support/docstring.h
5b64a08d5c452bd2ad99d92f84cce529493e0f4d
[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  * Provide a set of typedefs for commonly used things like sizes and
8  * indices wile trying to stay compatible with types used
9  * by the standard containers.
10  *
11  * \author André Pönitz
12  *
13  * Full author contact details are available in file CREDITS.
14  */
15
16 #ifndef LYX_DOCSTRING_H
17 #define LYX_DOCSTRING_H
18
19 #include <boost/cstdint.hpp>
20 #include <string>
21
22 namespace lyx {
23
24 typedef std::basic_string<boost::uint32_t> docstring;
25
26 }
27
28
29 #if defined(__GNUC__) && defined(__GNUC_MINOR__) && __GNUC__ == 3 && __GNUC_MINOR__ < 4
30 // Missing char_traits methods in gcc 3.3 and older. Taken from gcc 4.2svn.
31 namespace std {
32
33 template<typename T> void
34 char_traits<T>::assign(char_type & c1, char_type const & c2)
35 {
36         c1 = c2;
37 }
38
39
40 template<typename T> bool
41 char_traits<T>::eq(char_type const & c1, char_type const & c2)
42 {
43         return c1 == c2;
44 }
45
46
47 template<typename T> bool
48 char_traits<T>::lt(char_type const & c1, char_type const & c2)
49 {
50         return c1 < c2;
51 }
52
53
54 template<typename T> int
55 char_traits<T>::compare(char_type const * s1, char_type const * s2, std::size_t n)
56 {
57         for (std::size_t i = 0; i < n; ++i)
58                 if (lt(s1[i], s2[i]))
59                         return -1;
60                 else if (lt(s2[i], s1[i]))
61                         return 1;
62         return 0;
63 }
64
65
66 template<typename T> std::size_t
67 char_traits<T>::length(char_type const * p)
68 {
69         std::size_t i = 0;
70         while (!eq(p[i], char_type()))
71                 ++i;
72         return i;
73 }
74
75
76 template<typename T> typename char_traits<T>::char_type const *
77 char_traits<T>::find(char_type const * s, size_t n, char_type const & a)
78 {
79         for (std::size_t i = 0; i < n; ++i)
80                 if (eq(s[i], a))
81                         return s + i;
82         return 0;
83 }
84
85
86 template<typename T> typename char_traits<T>::char_type *
87 char_traits<T>::move(char_type * s1, char_type const * s2, std::size_t n)
88 {
89         return static_cast<T *>(std::memmove(s1, s2, n * sizeof(char_type)));
90 }
91
92
93 template<typename T> typename char_traits<T>::char_type *
94 char_traits<T>::copy(char_type * s1, char_type const * s2, std::size_t n)
95 {
96         std::copy(s2, s2 + n, s1);
97         return s1;
98 }
99
100
101 template<typename T> typename char_traits<T>::char_type *
102 char_traits<T>::assign(char_type * s, std::size_t n, char_type a)
103 {
104         std::fill_n(s, n, a);
105         return s;
106 }
107
108
109 template<typename T> typename char_traits<T>::char_type
110 char_traits<T>::to_char_type(int_type const & c)
111 {
112         return static_cast<char_type>(c);
113 }
114
115
116 template<typename T> typename char_traits<T>::int_type
117 char_traits<T>::to_int_type(char_type const & c)
118 {
119         return static_cast<int_type>(c);
120 }
121
122
123 template<typename T> bool
124 char_traits<T>::eq_int_type(int_type const & c1, int_type const & c2)
125 {
126         return c1 == c2;
127 }
128
129
130 template<typename T> typename char_traits<T>::int_type
131 char_traits<T>::eof()
132 {
133         return static_cast<int_type>(EOF);
134 }
135
136
137 template<typename T> typename char_traits<T>::int_type
138 char_traits<T>::not_eof(int_type const & c)
139 {
140         return !eq_int_type(c, eof()) ? c : to_int_type(char_type());
141 }
142
143 }
144 #endif
145 #endif