1 | /*
|
---|
2 | * Copyright (c) 2018 Jaroslav Jindrak
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | #ifndef LIBCPP_BITS_LOCALE_MISC
|
---|
30 | #define LIBCPP_BITS_LOCALE_MISC
|
---|
31 |
|
---|
32 | #include <__bits/locale/locale.hpp>
|
---|
33 | #include <__bits/locale/ctype.hpp>
|
---|
34 | #include <__bits/locale/num_get.hpp>
|
---|
35 | #include <__bits/locale/num_put.hpp>
|
---|
36 | #include <__bits/locale/numpunct.hpp>
|
---|
37 | #include <cstdlib>
|
---|
38 | #include <ios>
|
---|
39 | #include <iosfwd>
|
---|
40 | #include <string>
|
---|
41 |
|
---|
42 | namespace std
|
---|
43 | {
|
---|
44 | /**
|
---|
45 | * Note: This is a very simplistic implementation of <locale>.
|
---|
46 | * We have a single locale that has all of its facets.
|
---|
47 | * This should behave correctly on the outside but will prevent
|
---|
48 | * us from using multiple locales so if that becomes necessary
|
---|
49 | * in the future, TODO: implement :)
|
---|
50 | */
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * 22.3.3, convenience interfaces:
|
---|
54 | */
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * 22.3.3.1, character classification:
|
---|
58 | */
|
---|
59 |
|
---|
60 | template<class Char>
|
---|
61 | bool isspace(Char c, const locale& loc)
|
---|
62 | {
|
---|
63 | return use_facet<ctype<Char>>(loc).is(ctype_base::space, c);
|
---|
64 | }
|
---|
65 |
|
---|
66 | template<class Char>
|
---|
67 | bool isprint(Char c, const locale& loc)
|
---|
68 | {
|
---|
69 | return use_facet<ctype<Char>>(loc).is(ctype_base::print, c);
|
---|
70 | }
|
---|
71 |
|
---|
72 | template<class Char>
|
---|
73 | bool iscntrl(Char c, const locale& loc)
|
---|
74 | {
|
---|
75 | return use_facet<ctype<Char>>(loc).is(ctype_base::cntrl, c);
|
---|
76 | }
|
---|
77 |
|
---|
78 | template<class Char>
|
---|
79 | bool isupper(Char c, const locale& loc)
|
---|
80 | {
|
---|
81 | return use_facet<ctype<Char>>(loc).is(ctype_base::upper, c);
|
---|
82 | }
|
---|
83 |
|
---|
84 | template<class Char>
|
---|
85 | bool islower(Char c, const locale& loc)
|
---|
86 | {
|
---|
87 | return use_facet<ctype<Char>>(loc).is(ctype_base::lower, c);
|
---|
88 | }
|
---|
89 |
|
---|
90 | template<class Char>
|
---|
91 | bool isalpha(Char c, const locale& loc)
|
---|
92 | {
|
---|
93 | return use_facet<ctype<Char>>(loc).is(ctype_base::alpha, c);
|
---|
94 | }
|
---|
95 |
|
---|
96 | template<class Char>
|
---|
97 | bool isdigit(Char c, const locale& loc)
|
---|
98 | {
|
---|
99 | return use_facet<ctype<Char>>(loc).is(ctype_base::digit, c);
|
---|
100 | }
|
---|
101 |
|
---|
102 | template<class Char>
|
---|
103 | bool ispunct(Char c, const locale& loc)
|
---|
104 | {
|
---|
105 | return use_facet<ctype<Char>>(loc).is(ctype_base::punct, c);
|
---|
106 | }
|
---|
107 |
|
---|
108 | template<class Char>
|
---|
109 | bool isxdigit(Char c, const locale& loc)
|
---|
110 | {
|
---|
111 | return use_facet<ctype<Char>>(loc).is(ctype_base::xdigit, c);
|
---|
112 | }
|
---|
113 |
|
---|
114 | template<class Char>
|
---|
115 | bool isalnum(Char c, const locale& loc)
|
---|
116 | {
|
---|
117 | return use_facet<ctype<Char>>(loc).is(ctype_base::alnum, c);
|
---|
118 | }
|
---|
119 |
|
---|
120 | template<class Char>
|
---|
121 | bool isgraph(Char c, const locale& loc)
|
---|
122 | {
|
---|
123 | return use_facet<ctype<Char>>(loc).is(ctype_base::graph, c);
|
---|
124 | }
|
---|
125 |
|
---|
126 | template<class Char>
|
---|
127 | bool isblank(Char c, const locale& loc)
|
---|
128 | {
|
---|
129 | return use_facet<ctype<Char>>(loc).is(ctype_base::blank, c);
|
---|
130 | }
|
---|
131 |
|
---|
132 | /**
|
---|
133 | * 22.3.3.2, conversions:
|
---|
134 | */
|
---|
135 |
|
---|
136 | /**
|
---|
137 | * 22.3.3.2.1, character conversions:
|
---|
138 | */
|
---|
139 |
|
---|
140 | template<class Char>
|
---|
141 | Char toupper(Char c, const locale& loc)
|
---|
142 | {
|
---|
143 | return use_facet<ctype<Char>>(loc).toupper(c);
|
---|
144 | }
|
---|
145 |
|
---|
146 | template<class Char>
|
---|
147 | Char tolower(Char c, const locale& loc)
|
---|
148 | {
|
---|
149 | return use_facet<ctype<Char>>(loc).tolower(c);
|
---|
150 | }
|
---|
151 |
|
---|
152 | /**
|
---|
153 | * 22.3.3.2.2, string conversions:
|
---|
154 | */
|
---|
155 |
|
---|
156 | // TODO: implement
|
---|
157 | }
|
---|
158 |
|
---|
159 | #endif
|
---|