|
16 | 16 | #include <locale>
|
17 | 17 | #include <string>
|
18 | 18 |
|
19 |
| -#include "test_macros.h" |
20 |
| - |
21 | 19 | struct Char {
|
22 | 20 | Char() = default;
|
23 | 21 | Char(char c) : underlying_(c) {}
|
@@ -73,15 +71,53 @@ struct char_traits<Char> {
|
73 | 71 | static int_type eof() { return char_traits<char>::eof(); }
|
74 | 72 | };
|
75 | 73 |
|
| 74 | +// This ctype specialization treats all characters as spaces |
76 | 75 | template <>
|
77 |
| -class ctype<Char> : public locale::facet { |
| 76 | +class ctype<Char> : public locale::facet, public ctype_base { |
78 | 77 | public:
|
| 78 | + using char_type = Char; |
79 | 79 | static locale::id id;
|
80 |
| - Char toupper(Char c) const { return Char(std::toupper(c.underlying_)); } |
81 |
| - const char* widen(const char* first, const char* last, Char* dst) const { |
82 |
| - for (; first != last;) |
83 |
| - *dst++ = Char(*first++); |
84 |
| - return last; |
| 80 | + explicit ctype(std::size_t refs = 0) : locale::facet(refs) {} |
| 81 | + |
| 82 | + bool is(mask m, char_type) const { return m & ctype_base::space; } |
| 83 | + const char_type* is(const char_type* low, const char_type* high, mask* vec) const { |
| 84 | + for (; low != high; ++low) |
| 85 | + *vec++ = ctype_base::space; |
| 86 | + return high; |
| 87 | + } |
| 88 | + |
| 89 | + const char_type* scan_is(mask m, const char_type* beg, const char_type* end) const { |
| 90 | + for (; beg != end; ++beg) |
| 91 | + if (this->is(m, *beg)) |
| 92 | + return beg; |
| 93 | + return end; |
| 94 | + } |
| 95 | + |
| 96 | + const char_type* scan_not(mask m, const char_type* beg, const char_type* end) const { |
| 97 | + for (; beg != end; ++beg) |
| 98 | + if (!this->is(m, *beg)) |
| 99 | + return beg; |
| 100 | + return end; |
| 101 | + } |
| 102 | + |
| 103 | + char_type toupper(char_type c) const { return c; } |
| 104 | + const char_type* toupper(char_type*, const char_type* end) const { return end; } |
| 105 | + |
| 106 | + char_type tolower(char_type c) const { return c; } |
| 107 | + const char_type* tolower(char_type*, const char_type* end) const { return end; } |
| 108 | + |
| 109 | + char_type widen(char c) const { return char_type(c); } |
| 110 | + const char* widen(const char* beg, const char* end, char_type* dst) const { |
| 111 | + for (; beg != end; ++beg, ++dst) |
| 112 | + *dst = char_type(*beg); |
| 113 | + return end; |
| 114 | + } |
| 115 | + |
| 116 | + char narrow(char_type c, char /*dflt*/) const { return c.underlying_; } |
| 117 | + const char_type* narrow(const char_type* beg, const char_type* end, char /*dflt*/, char* dst) const { |
| 118 | + for (; beg != end; ++beg, ++dst) |
| 119 | + *dst = beg->underlying_; |
| 120 | + return end; |
85 | 121 | }
|
86 | 122 | };
|
87 | 123 |
|
|
0 commit comments