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 
42 #include <locale>
43 
44 #else // no locales
45 
46 namespace std {
47 
48 class codecvt_base
49 {
50  public:
51  enum { ok, partial, error, noconv };
52  typedef int result;
53 
54  virtual ~codecvt_base()
55  { }
56 };
57 
58 template <typename I, typename E, typename S>
59 class codecvt : public std::codecvt_base
60 {
61  public:
62  typedef I intern_type;
63  typedef E extern_type;
64  typedef S state_type;
65 
66  public:
67  codecvt(std::size_t ref = 0)
68  {}
69 
70  virtual ~codecvt()
71  { }
72 
73  codecvt_base::result out(state_type& state,
74  const intern_type* from,
75  const intern_type* from_end,
76  const intern_type*& from_next,
77  extern_type* to,
78  extern_type* to_end,
79  extern_type*& to_next) const
80  { return this->do_out(state, from, from_end, from_next, to, to_end, to_next); }
81 
82  codecvt_base::result unshift(state_type& state,
83  extern_type* to,
84  extern_type* to_end,
85  extern_type*& to_next) const
86  { return this->do_unshift(state, to, to_end, to_next); }
87 
88  codecvt_base::result in(state_type& state,
89  const extern_type* from,
90  const extern_type* from_end,
91  const extern_type*& from_next,
92  intern_type* to,
93  intern_type* to_end,
94  intern_type*& to_next) const
95  { return this->do_in(state, from, from_end, from_next, to, to_end, to_next); }
96 
97  int encoding() const
98  { return this->do_encoding(); }
99 
100  bool always_noconv() const
101  { return this->do_always_noconv(); }
102 
103  int length(state_type& state, const extern_type* from,
104  const extern_type* end, std::size_t max) const
105  { return this->do_length(state, from, end, max); }
106 
107  int max_length() const
108  { return this->do_max_length(); }
109 
110  protected:
111  virtual result do_in(state_type& s, const extern_type* fromBegin,
112  const extern_type* fromEnd, const extern_type*& fromNext,
113  intern_type* toBegin, intern_type* toEnd, intern_type*& toNext) const = 0;
114 
115  virtual result do_out(state_type& s, const intern_type* fromBegin,
116  const intern_type* fromEnd, const intern_type*& fromNext,
117  extern_type* toBegin, extern_type* toEnd, extern_type*& toNext) const = 0;
118 
119  virtual bool do_always_noconv() const = 0;
120 
121  virtual int do_length(state_type& s, const extern_type* fromBegin,
122  const extern_type* fromEnd, std::size_t max) const = 0;
123 
124  virtual int do_max_length() const = 0;
125 
126  virtual std::codecvt_base::result do_unshift(state_type&,
127  extern_type*,
128  extern_type*,
129  extern_type*&) const = 0;
130 
131  virtual int do_encoding() const = 0;
132 };
133 
134 class ctype_base
135 {
136  public:
137  enum {
138  alpha = 1 << 5,
139  cntrl = 1 << 2,
140  digit = 1 << 6,
141  lower = 1 << 4,
142  print = 1 << 1,
143  punct = 1 << 7,
144  space = 1 << 0,
145  upper = 1 << 3,
146  xdigit = 1 << 8,
147  alnum = alpha | digit,
148  graph = alnum | punct
149  };
150 
151  typedef unsigned short mask;
152 
153  ctype_base(std::size_t _refs = 0)
154  { }
155 };
156 
157 }
158 
159 #endif
160 
161 #endif