Locale.h
1/*
2 * Copyright (C) 2004-2011 Marc Boris Duerner
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * As a special exception, you may use this file as part of a free
10 * software library without restriction. Specifically, if other files
11 * instantiate templates or use macros or inline functions from this
12 * file, or you compile this file and link it with other files to
13 * produce an executable, this file does not by itself cause the
14 * resulting executable to be covered by the GNU General Public
15 * License. This exception does not however invalidate any other
16 * reasons why the executable file might be covered by the GNU Library
17 * General Public License.
18 *
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 */
28#ifndef PT_LOCALE_H
29#define PT_LOCALE_H
30
31#include <Pt/Api.h>
32#include <Pt/Types.h>
33
34#ifdef _WIN32_WCE
35 // WinCE does not provide locale-classes
36#else
37 #define PT_WITH_STD_LOCALE 1
38#endif
39
40#ifdef PT_WITH_STD_LOCALE
41#include <locale>
42#else
43
44namespace std {
45
46class codecvt_base
47{
48 public:
49 enum { ok, partial, error, noconv };
50 typedef int result;
51
52 virtual ~codecvt_base()
53 { }
54};
55
56template <typename I, typename E, typename S>
57class codecvt : public std::codecvt_base
58{
59 public:
60 typedef I intern_type;
61 typedef E extern_type;
62 typedef S state_type;
63
64 public:
65 codecvt(std::size_t ref = 0)
66 {}
67
68 virtual ~codecvt()
69 { }
70
71 codecvt_base::result out(state_type& state,
72 const intern_type* from,
73 const intern_type* from_end,
74 const intern_type*& from_next,
75 extern_type* to,
76 extern_type* to_end,
77 extern_type*& to_next) const
78 { return this->do_out(state, from, from_end, from_next, to, to_end, to_next); }
79
80 codecvt_base::result unshift(state_type& state,
81 extern_type* to,
82 extern_type* to_end,
83 extern_type*& to_next) const
84 { return this->do_unshift(state, to, to_end, to_next); }
85
86 codecvt_base::result in(state_type& state,
87 const extern_type* from,
88 const extern_type* from_end,
89 const extern_type*& from_next,
90 intern_type* to,
91 intern_type* to_end,
92 intern_type*& to_next) const
93 { return this->do_in(state, from, from_end, from_next, to, to_end, to_next); }
94
95 int encoding() const
96 { return this->do_encoding(); }
97
98 bool always_noconv() const
99 { return this->do_always_noconv(); }
100
101 int length(state_type& state, const extern_type* from,
102 const extern_type* end, std::size_t max) const
103 { return this->do_length(state, from, end, max); }
104
105 int max_length() const
106 { return this->do_max_length(); }
107
108 protected:
109 virtual result do_in(state_type& s, const extern_type* fromBegin,
110 const extern_type* fromEnd, const extern_type*& fromNext,
111 intern_type* toBegin, intern_type* toEnd, intern_type*& toNext) const = 0;
112
113 virtual result do_out(state_type& s, const intern_type* fromBegin,
114 const intern_type* fromEnd, const intern_type*& fromNext,
115 extern_type* toBegin, extern_type* toEnd, extern_type*& toNext) const = 0;
116
117 virtual bool do_always_noconv() const = 0;
118
119 virtual int do_length(state_type& s, const extern_type* fromBegin,
120 const extern_type* fromEnd, std::size_t max) const = 0;
121
122 virtual int do_max_length() const = 0;
123
124 virtual std::codecvt_base::result do_unshift(state_type&,
125 extern_type*,
126 extern_type*,
127 extern_type*&) const = 0;
128
129 virtual int do_encoding() const = 0;
130};
131
132class ctype_base
133{
134 public:
135 enum {
136 alpha = 1 << 5,
137 cntrl = 1 << 2,
138 digit = 1 << 6,
139 lower = 1 << 4,
140 print = 1 << 1,
141 punct = 1 << 7,
142 space = 1 << 0,
143 upper = 1 << 3,
144 xdigit = 1 << 8,
145 alnum = alpha | digit,
146 graph = alnum | punct
147 };
148
149 typedef unsigned short mask;
150
151 ctype_base(std::size_t _refs = 0)
152 { }
153};
154
155}
156
157#endif
158
159#endif