Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
codecvte.h
Go to the documentation of this file.
1
29#ifndef CODECVTE_H_INCLUDED
30
31#include <locale> // for codecvt
32#include <cwchar> // for mbstate_t, size_t
33
34#include <examples.h>
35
36
37#define RWSTD_TABLE_SIZE 59
38
39// This facet performs a conversion from Latin Alphabet No. 1
40// (ISO 8859-1) to U.S. ASCII code page 437. Some conversions are
41// one way (from ISO to ASCII, but not back again) because this ASCII
42// code page has no equivilent to the ISO character.
43
44class ex_codecvt: public std::codecvt<char, char, std::mbstate_t>
45{
46 static const char table_[RWSTD_TABLE_SIZE][3];
47
48protected:
49
50 virtual result
51 do_in (std::mbstate_t&,
52 const char* from,
53 const char* from_end,
54 const char* &from_next,
55 char* to,
56 char* to_limit,
57 char* &to_next) const {
58
59 const std::size_t from_size = std::size_t (from_end - from);
60 const std::size_t to_size = std::size_t (to_limit - to);
61
62 std::size_t i = from_size < to_size ? from_size : to_size;
63
64 from_next = from;
65 to_next = to;
66
67 for (std::size_t j = 0; j < i; ++j, ++from_next, ++to_next) {
68
69 *to_next = *from_next;
70
71 for (int k = 0; k < RWSTD_TABLE_SIZE; ++k) {
72 if ( *from_next >= table_[k][0]
73 && *from_next <= table_[k][1]) {
74 *to_next = table_[k][2];
75 break;
76 }
77 }
78 }
79
80 return ok;
81 }
82
83 virtual result
84 do_out (std::mbstate_t&,
85 const char* from,
86 const char* from_end,
87 const char* &from_next,
88 char* to,
89 char* to_limit,
90 char* &to_next) const {
91
92 const std::size_t from_size = std::size_t (from_end - from);
93 const std::size_t to_size = std::size_t (to_limit - to);
94
95 std::size_t i = from_size < to_size ? from_size : to_size;
96
97 from_next = from;
98 to_next = to;
99
100 for (std::size_t j = 0; j < i; ++j, ++from_next, ++to_next) {
101
102 *to_next = *from_next;
103
104 for (std::size_t k = 0; k < RWSTD_TABLE_SIZE; ++k) {
105 if ( *from_next == table_[k][2]
106 && table_[k][0] == table_[k][1]) {
107 *to_next = table_[k][1];
108 break;
109 }
110 }
111 }
112
113 return ok;
114 }
115
116 virtual bool do_always_noconv () const _THROWS (()) {
117 return false;
118 }
119
120 virtual int do_encoding () const _THROWS (()) {
121 return 1;
122 }
123};
124
125
126const char ex_codecvt::table_[RWSTD_TABLE_SIZE][3] = {
127 { '\xa2', '\xa2', '\x9b' }, { '\xa3', '\xa3', '\x9c' },
128 { '\xa5', '\xa5', '\x9d' }, { '\xa7', '\xa7', '\x15' },
129 { '\xa8', '\xa8', '\x22' }, { '\xaa', '\xaa', '\xa6' },
130 { '\xab', '\xab', '\xae' }, { '\xb5', '\xb5', '\xe6' },
131 { '\xb6', '\xb6', '\x14' }, { '\xb7', '\xb7', '\xfa' },
132 { '\xba', '\xba', '\xa7' }, { '\xbb', '\xbb', '\xaf' },
133 { '\xbc', '\xbc', '\xac' }, { '\xbd', '\xbd', '\xab' },
134 { '\xbf', '\xbf', '\xa8' }, { '\xc0', '\xc3', '\x41' },
135 { '\xc4', '\xc4', '\x8e' }, { '\xc5', '\xc5', '\x41' },
136 { '\xc6', '\xc6', '\x92' }, { '\xc7', '\xc7', '\x80' },
137 { '\xc8', '\xc8', '\x45' }, { '\xc9', '\xc9', '\x90' },
138 { '\xca', '\xcb', '\x45' }, { '\xcc', '\xcf', '\x49' },
139 { '\xd1', '\xd1', '\xa5' }, { '\xd2', '\xd5', '\x4f' },
140 { '\xd6', '\xd6', '\x99' }, { '\xd8', '\xd8', '\xed' },
141 { '\xd9', '\xdb', '\x55' }, { '\xdc', '\xdc', '\x9a' },
142 { '\xdd', '\xdd', '\x59' }, { '\xdf', '\xdf', '\xe1' },
143 { '\xe0', '\xe0', '\x85' }, { '\xe1', '\xe1', '\xa0' },
144 { '\xe2', '\xe2', '\x83' }, { '\xe3', '\xe3', '\x61' },
145 { '\xe4', '\xe4', '\x84' }, { '\xe5', '\xe5', '\x86' },
146 { '\xe6', '\xe6', '\x91' }, { '\xe7', '\xe7', '\x87' },
147 { '\xe8', '\xe8', '\x8a' }, { '\xe9', '\xe9', '\x82' },
148 { '\xea', '\xea', '\x88' }, { '\xeb', '\xeb', '\x89' },
149 { '\xec', '\xec', '\x8d' }, { '\xed', '\xed', '\xa1' },
150 { '\xee', '\xee', '\x8c' }, { '\xef', '\xef', '\x8b' },
151 { '\xf1', '\xf1', '\xa4' }, { '\xf2', '\xf2', '\x95' },
152 { '\xf3', '\xf3', '\xa2' }, { '\xf4', '\xf4', '\x93' },
153 { '\xf5', '\xf5', '\x6f' }, { '\xf6', '\xf6', '\x94' },
154 { '\xf9', '\xf9', '\x97' }, { '\xfa', '\xfa', '\xa3' },
155 { '\xfb', '\xfb', '\x96' }, { '\xfc', '\xfc', '\x81' },
156 { '\xff', '\xff', '\x98' }
157};
158
159#endif // CODECVTE_H_INCLUDED
#define i
Definition 17.names.cpp:126
#define k
Definition 17.names.cpp:128
#define j
Definition 17.names.cpp:127
volatile int result
#define _THROWS()
virtual result do_in(std::mbstate_t &, const char *from, const char *from_end, const char *&from_next, char *to, char *to_limit, char *&to_next) const
Definition codecvte.h:51
virtual bool do_always_noconv() const _THROWS(())
Definition codecvte.h:116
virtual int do_encoding() const _THROWS(())
Definition codecvte.h:120
virtual result do_out(std::mbstate_t &, const char *from, const char *from_end, const char *&from_next, char *to, char *to_limit, char *&to_next) const
Definition codecvte.h:84
#define RWSTD_TABLE_SIZE
Definition codecvte.h:37