| 1 | /*
|
|---|
| 2 | * SPDX-FileCopyrightText: 2018 Jaroslav Jindrak
|
|---|
| 3 | *
|
|---|
| 4 | * SPDX-License-Identifier: BSD-3-Clause
|
|---|
| 5 | */
|
|---|
| 6 |
|
|---|
| 7 | #ifndef LIBCPP_BITS_LOCALE_NUMPUNCT
|
|---|
| 8 | #define LIBCPP_BITS_LOCALE_NUMPUNCT
|
|---|
| 9 |
|
|---|
| 10 | #include <__bits/locale/locale.hpp>
|
|---|
| 11 | #include <string>
|
|---|
| 12 |
|
|---|
| 13 | namespace std
|
|---|
| 14 | {
|
|---|
| 15 | /**
|
|---|
| 16 | * 22.4.3.1, class template numpunct:
|
|---|
| 17 | */
|
|---|
| 18 |
|
|---|
| 19 | template<class Char>
|
|---|
| 20 | class numpunct: public locale::facet
|
|---|
| 21 | {
|
|---|
| 22 | public:
|
|---|
| 23 | using char_type = Char;
|
|---|
| 24 | using string_type = basic_string<Char>;
|
|---|
| 25 |
|
|---|
| 26 | explicit numpunct(size_t refs = 0);
|
|---|
| 27 |
|
|---|
| 28 | char_type decimal_point() const
|
|---|
| 29 | {
|
|---|
| 30 | return do_decimal_point();
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | char_type thousands_sep() const
|
|---|
| 34 | {
|
|---|
| 35 | return do_thousands_sep();
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | string_type grouping() const
|
|---|
| 39 | {
|
|---|
| 40 | return do_grouping();
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | string_type truename() const
|
|---|
| 44 | {
|
|---|
| 45 | return do_truename();
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | string_type falsename() const
|
|---|
| 49 | {
|
|---|
| 50 | return do_falsename();
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | ~numpunct();
|
|---|
| 54 |
|
|---|
| 55 | protected:
|
|---|
| 56 | char_type do_decimal_point() const;
|
|---|
| 57 | char_type do_thousands_sep() const;
|
|---|
| 58 | string_type do_grouping() const;
|
|---|
| 59 | string_type do_truename() const;
|
|---|
| 60 | string_type do_falsename() const;
|
|---|
| 61 | };
|
|---|
| 62 |
|
|---|
| 63 | template<>
|
|---|
| 64 | class numpunct<char>: public locale::facet
|
|---|
| 65 | {
|
|---|
| 66 | public:
|
|---|
| 67 | using char_type = char;
|
|---|
| 68 | using string_type = basic_string<char>;
|
|---|
| 69 |
|
|---|
| 70 | explicit numpunct(size_t refs = 0)
|
|---|
| 71 | { /* DUMMY BODY */ }
|
|---|
| 72 |
|
|---|
| 73 | char_type decimal_point() const
|
|---|
| 74 | {
|
|---|
| 75 | return do_decimal_point();
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | char_type thousands_sep() const
|
|---|
| 79 | {
|
|---|
| 80 | return do_thousands_sep();
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | string_type grouping() const
|
|---|
| 84 | {
|
|---|
| 85 | return do_grouping();
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | string_type truename() const
|
|---|
| 89 | {
|
|---|
| 90 | return do_truename();
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | string_type falsename() const
|
|---|
| 94 | {
|
|---|
| 95 | return do_falsename();
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | ~numpunct()
|
|---|
| 99 | { /* DUMMY BODY */ }
|
|---|
| 100 |
|
|---|
| 101 | protected:
|
|---|
| 102 | char_type do_decimal_point() const
|
|---|
| 103 | {
|
|---|
| 104 | return '.';
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | char_type do_thousands_sep() const
|
|---|
| 108 | {
|
|---|
| 109 | return ',';
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | string_type do_grouping() const
|
|---|
| 113 | {
|
|---|
| 114 | return "";
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | string_type do_truename() const
|
|---|
| 118 | {
|
|---|
| 119 | return "true";
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | string_type do_falsename() const
|
|---|
| 123 | {
|
|---|
| 124 | return "false";
|
|---|
| 125 | }
|
|---|
| 126 | };
|
|---|
| 127 |
|
|---|
| 128 | template<>
|
|---|
| 129 | class numpunct<wchar_t>: public locale::facet
|
|---|
| 130 | {
|
|---|
| 131 | public:
|
|---|
| 132 | using char_type = wchar_t;
|
|---|
| 133 | using string_type = basic_string<wchar_t>;
|
|---|
| 134 |
|
|---|
| 135 | explicit numpunct(size_t refs = 0);
|
|---|
| 136 |
|
|---|
| 137 | char_type decimal_point() const
|
|---|
| 138 | {
|
|---|
| 139 | return do_decimal_point();
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | char_type thousands_sep() const
|
|---|
| 143 | {
|
|---|
| 144 | return do_thousands_sep();
|
|---|
| 145 | }
|
|---|
| 146 |
|
|---|
| 147 | string_type grouping() const
|
|---|
| 148 | {
|
|---|
| 149 | return do_grouping();
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 | string_type truename() const
|
|---|
| 153 | {
|
|---|
| 154 | return do_truename();
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 | string_type falsename() const
|
|---|
| 158 | {
|
|---|
| 159 | return do_falsename();
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | ~numpunct();
|
|---|
| 163 |
|
|---|
| 164 | protected:
|
|---|
| 165 | char_type do_decimal_point() const
|
|---|
| 166 | {
|
|---|
| 167 | return L'.';
|
|---|
| 168 | }
|
|---|
| 169 |
|
|---|
| 170 | char_type do_thousands_sep() const
|
|---|
| 171 | {
|
|---|
| 172 | return L',';
|
|---|
| 173 | }
|
|---|
| 174 |
|
|---|
| 175 | string_type do_grouping() const
|
|---|
| 176 | {
|
|---|
| 177 | return L"";
|
|---|
| 178 | }
|
|---|
| 179 |
|
|---|
| 180 | string_type do_truename() const
|
|---|
| 181 | {
|
|---|
| 182 | return L"true";
|
|---|
| 183 | }
|
|---|
| 184 |
|
|---|
| 185 | string_type do_falsename() const
|
|---|
| 186 | {
|
|---|
| 187 | return L"false";
|
|---|
| 188 | }
|
|---|
| 189 | };
|
|---|
| 190 | }
|
|---|
| 191 |
|
|---|
| 192 | #endif
|
|---|