|
1 | 1 | #ifndef _GHLIBCPP_STRING
|
2 | 2 | #define _GHLIBCPP_STRING
|
| 3 | +#include "cwchar" |
3 | 4 | #include "initializer_list"
|
| 5 | +#include "ios.h" |
4 | 6 | #include "iosfwd.h"
|
5 | 7 | #include "iterator.h"
|
6 | 8 | #include "stddef.h"
|
7 | 9 |
|
8 | 10 | namespace std {
|
9 |
| -template <class charT> struct char_traits; |
| 11 | +template <class charT> struct char_traits { |
| 12 | + typedef charT char_type; |
| 13 | + typedef int int_type; |
| 14 | + typedef streamoff off_type; |
| 15 | + typedef streampos pos_type; |
| 16 | + typedef mbstate_t state_type; |
| 17 | + |
| 18 | + static void assign(char_type &c1, const char_type &c2); |
| 19 | + static bool eq(const char_type &c1, const char_type &c2); |
| 20 | + static bool lt(const char_type &c1, const char_type &c2); |
| 21 | + |
| 22 | + static int compare(const char_type *s1, const char_type *s2, size_t n); |
| 23 | + static size_t length(const char_type *s); |
| 24 | + static const char_type *find(const char_type *s, size_t n, |
| 25 | + const char_type &a); |
| 26 | + static char_type *move(char_type *s1, const char_type *s2, size_t n); |
| 27 | + static char_type *copy(char_type *s1, const char_type *s2, size_t n); |
| 28 | + static char_type *assign(char_type *s, size_t n, char_type a); |
| 29 | + |
| 30 | + static int_type not_eof(const int_type &c); |
| 31 | + static char_type to_char_type(const int_type &c); |
| 32 | + static int_type to_int_type(const char_type &c); |
| 33 | + static bool eq_int_type(const int_type &c1, const int_type &c2); |
| 34 | + static int_type eof(); |
| 35 | +}; |
| 36 | + |
| 37 | +// Specialization for char |
| 38 | +template <> struct char_traits<char> { |
| 39 | + typedef char char_type; |
| 40 | + typedef int int_type; |
| 41 | + typedef streamoff off_type; |
| 42 | + typedef streampos pos_type; |
| 43 | + typedef mbstate_t state_type; |
| 44 | + |
| 45 | + static void assign(char_type &c1, const char_type &c2); |
| 46 | + static bool eq(const char_type &c1, const char_type &c2); |
| 47 | + static bool lt(const char_type &c1, const char_type &c2); |
| 48 | + |
| 49 | + static int compare(const char_type *s1, const char_type *s2, size_t n); |
| 50 | + static size_t length(const char_type *s); |
| 51 | + static const char_type *find(const char_type *s, size_t n, |
| 52 | + const char_type &a); |
| 53 | + static char_type *move(char_type *s1, const char_type *s2, size_t n); |
| 54 | + static char_type *copy(char_type *s1, const char_type *s2, size_t n); |
| 55 | + static char_type *assign(char_type *s, size_t n, char_type a); |
| 56 | + |
| 57 | + static int_type not_eof(const int_type &c); |
| 58 | + static char_type to_char_type(const int_type &c); |
| 59 | + static int_type to_int_type(const char_type &c); |
| 60 | + static bool eq_int_type(const int_type &c1, const int_type &c2); |
| 61 | + static int_type eof(); |
| 62 | +}; |
| 63 | + |
| 64 | +// Specialization for wchar_t |
| 65 | +template <> struct char_traits<wchar_t> { |
| 66 | + typedef wchar_t char_type; |
| 67 | + typedef wint_t int_type; |
| 68 | + typedef streamoff off_type; |
| 69 | + typedef wstreampos pos_type; |
| 70 | + typedef mbstate_t state_type; |
| 71 | + |
| 72 | + static void assign(char_type &c1, const char_type &c2); |
| 73 | + static bool eq(const char_type &c1, const char_type &c2); |
| 74 | + static bool lt(const char_type &c1, const char_type &c2); |
| 75 | + |
| 76 | + static int compare(const char_type *s1, const char_type *s2, size_t n); |
| 77 | + static size_t length(const char_type *s); |
| 78 | + static const char_type *find(const char_type *s, size_t n, |
| 79 | + const char_type &a); |
| 80 | + static char_type *move(char_type *s1, const char_type *s2, size_t n); |
| 81 | + static char_type *copy(char_type *s1, const char_type *s2, size_t n); |
| 82 | + static char_type *assign(char_type *s, size_t n, char_type a); |
| 83 | + |
| 84 | + static int_type not_eof(const int_type &c); |
| 85 | + static char_type to_char_type(const int_type &c); |
| 86 | + static int_type to_int_type(const char_type &c); |
| 87 | + static bool eq_int_type(const int_type &c1, const int_type &c2); |
| 88 | + static int_type eof(); |
| 89 | +}; |
10 | 90 |
|
11 | 91 | template <class T> class allocator {
|
12 | 92 | public:
|
@@ -114,14 +194,15 @@ public:
|
114 | 194 | basic_string &replace(size_type pos, size_type n1, size_type n2, charT c);
|
115 | 195 | basic_string &replace(__const_iterator i1, __const_iterator i2,
|
116 | 196 | const basic_string &str);
|
117 |
| - basic_string &replace(__const_iterator i1, __const_iterator i2, const charT *s, |
118 |
| - size_type n); |
119 |
| - basic_string &replace(__const_iterator i1, __const_iterator i2, const charT *s); |
| 197 | + basic_string &replace(__const_iterator i1, __const_iterator i2, |
| 198 | + const charT *s, size_type n); |
| 199 | + basic_string &replace(__const_iterator i1, __const_iterator i2, |
| 200 | + const charT *s); |
120 | 201 | basic_string &replace(__const_iterator i1, __const_iterator i2, size_type n,
|
121 | 202 | charT c);
|
122 | 203 | template <class InputIterator>
|
123 |
| - basic_string &replace(__const_iterator i1, __const_iterator i2, InputIterator j1, |
124 |
| - InputIterator j2); |
| 204 | + basic_string &replace(__const_iterator i1, __const_iterator i2, |
| 205 | + InputIterator j1, InputIterator j2); |
125 | 206 | basic_string &replace(__const_iterator, __const_iterator,
|
126 | 207 | initializer_list<charT>);
|
127 | 208 |
|
|
0 commit comments