Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
charmap.h
Go to the documentation of this file.
1
30#ifndef _RWSTD_CHARMAP_H_INCLUDED
31#define _RWSTD_CHARMAP_H_INCLUDED
32
33#include <string>
34#include <list>
35#include <map>
36#include <set>
37
38#ifndef _RWSTD_NO_ICONV
39# include <iconv.h>
40#endif // _RWSTD_NO_ICONV
41
42
43#include "scanner.h"
44
46{
47public:
48 static const char* const portable_charset [];
49
50 Charmap(const char* /*corresponding C library locale*/,
51 const char* /*filename*/,
52 bool /*is utf8 encoding?*/,
53 bool /*create_forward_charmaps*/,
54 bool /*create_reverse_charmaps*/,
55 bool /*use UCS4 internally*/);
56
57 // returns the narrow character map which maps a symbolic character
58 // name to its narrow character value
59 const std::map<std::string, unsigned char>& get_n_cmap() const {
60 return n_cmap_;
61 }
62
63 // returns the reverse narrow character map which maps a narrow
64 // character value to its symbolic name
65 const std::map<unsigned char, std::string>& get_rn_cmap() const {
66 return rn_cmap_;
67 }
68
69 // returns the wide character map which maps a symbolic character
70 // name to its wide character value
71 const std::map<std::string, wchar_t>& get_w_cmap() const {
72 return w_cmap_;
73 }
74
75 // returns the reverse wide character map which maps a wide
76 // character value to its symbolic name
77 const std::map<wchar_t, std::string>& get_rw_cmap() const {
78 return rw_cmap_;
79 }
80
81 // returns the multibyte character map which maps a multibyte
82 // character to its corresponding wide character value
83 const std::map<std::string, wchar_t>& get_mb_cmap() const {
84 return mb_cmap_;
85 }
86
87 // returns the reverse multibyte character map which maps a wide
88 // character value to its corresponding multibyte character
89 const std::map<wchar_t, std::string>& get_rmb_cmap() const {
90 return rmb_cmap_;
91 }
92
93 // get the string value map
94 const std::list<std::string>& get_symnames_list() const {
95 return symnames_list_;
96 }
97
98 const std::map <std::string, wchar_t>& get_ucs4_cmap () const {
99 return ucs4_cmap_;
100 }
101
102 const std::map <wchar_t, std::string>& get_rucs4_cmap () const {
103 return rucs4_cmap_;
104 }
105
106 // return the value of mb_cur_max
107 int get_mb_cur_max() const {
108 return mb_cur_max_;
109 }
110
111 // return the name of the codeset
112 const std::string& get_code_set_name () const {
113 return code_set_name_;
114 }
115
116 // return the name of the character map
117 std::string get_charmap_name () const;
118
119 // return the full path to the charmap
120 std::string get_full_charmap_name () const {
121 return charmap_name_;
122 }
123
124 // convert the externally encoded string to the internal encoding
125 bool convert_to_wc (const std::string&, const std::string&, wchar_t&);
126
127 // convert the externally encoded string to UCS
128 bool convert_to_ucs (const std::string&, const std::string&, wchar_t&);
129
130 // convert the externally encoded string to UCS
131 wchar_t convert_sym_to_ucs (const std::string&) const;
132
133
134 // get the number of bytes in a single multi-byte character
135 std::size_t mbcharlen (const std::string&) const;
136
137 // convert the first byte in the multi-byte character to an unsigned char
138 unsigned char convert_char (const char*, const char** = 0) const;
139
140 unsigned char get_largest_nchar () const;
141
142 // increments the wide character value to the next encoded character
143 // in the current codeset; returns the incremented value or -1 on
144 // error
145 wchar_t increment_wchar (wchar_t) const;
146
147private:
148
149 // processes characters implicitly defined by an ellipsis denoted
150 // by two explicitly defined characters; returns the number of
151 // characters in the range, -1 on error
152 std::size_t process_ellipsis (const Scanner::token_t&, int);
153
154 // process the charmap file making the necessary mappings in the cmaps
155 void process_chars();
156
157 // increment the encoded multi byte character argument
158 bool increment_encoding (std::string&);
159
160 // verify that all the characters in the portable character set
161 // are defined in the character map
162 void verify_portable_charset () const;
163
164#ifndef _RWSTD_NO_ICONV
165 // open the iconv descriptor to convert to utf8
166 iconv_t open_iconv_to_utf8 () const;
167#endif // _RWSTD_NO_ICONV
168
169 // convert a human-readable encoding of a character
170 // to its raw multibyte character representation
171 std::string encoding_to_mbchar (const std::string&) const;
172
173 // convert a multi-byte string to a utf8 multi-byte string
174 char* convert_to_utf8 (const char *inbuf, std::size_t inbuf_s,
175 char *outbuf, std::size_t outbuf_s) const;
176
177#ifndef _RWSTD_NO_ICONV
178# ifndef _RWSTD_NO_ISO_10646_WCHAR_T
179
180 // open the iconv descriptor to convert from utf8 to the external encoding
181 iconv_t open_iconv_to_ext ();
182
183# endif // _RWSTD_NO_ISO_10646_WCHAR_T
184#endif // _RWSTD_NO_ICONV
185
186 // add the symbolic name of a character and the raw multibyte
187 // character corresponding to it to the character maps
188 void add_to_cmaps (const std::string&,
189 const std::string&,
190 bool = false);
191
192 // the scanner used to process the charmap file
193 Scanner scanner_;
194
195 // the name of the codeset
196 std::string code_set_name_;
197
198#if defined (_WIN32)
199 int codepage_;
200#endif // _WIN32
201
202 // n_cmap maps the symbolic name to a narrow character value
203 // rn_cmap does the opposite
204 std::map <std::string, unsigned char> n_cmap_;
205 std::map <unsigned char, std::string> rn_cmap_;
206
207 // mb_cmap maps a multibyte character representation to its
208 // corresponding wide character value
209 // rmb_cmap does the opposite
210 std::map <std::string, wchar_t> mb_cmap_;
211 std::map <wchar_t, std::string> rmb_cmap_;
212
213 typedef std::map <wchar_t, std::string>::const_iterator rmb_cmap_iter;
214 typedef std::map <std::string, wchar_t>::const_iterator mb_cmap_iter;
215
216 // w_cmap maps the symbolic name to a wide character value
217 // rw_cmap does exactly the opposite
218 std::map <std::string, wchar_t> w_cmap_;
219 std::map <wchar_t, std::string> rw_cmap_;
220
221 // ucs4_cmap maps the symbolic name to the UCS4 value for that name
222 std::map <std::string, wchar_t> ucs4_cmap_;
223 std::map <wchar_t, std::string> rucs4_cmap_;
224
225 // the number of bytes in the largest multi-byte value
226 int mb_cur_max_;
227
228#ifndef _RWSTD_NO_ICONV
229 // the iconv file descriptor that converts to utf8
230 iconv_t ic_to_utf8_;
231
232 // the iconv file descriptor that converts from utf8 to external
233 iconv_t ic_to_ext_;
234#endif // _RWSTD_NO_ICONV
235
236 // the name of the character map file
237 std::string charmap_name_;
238
239 // the name of the C library locale with same encoding
240 std::string Clocale_;
241
242 unsigned char largest_nchar_;
243
244 // are we in the utf8 encoding?
245 bool in_utf8_;
246
247 // should we create the forward character maps
248 bool forward_maps;
249
250 // should we create the reverse character maps
251 bool reverse_maps;
252
253 // should we use UCS4 as the internal representation
254 bool UCS4_internal_;
255
256 // list of all known symbolic character names
257 std::list<std::string> symnames_list_;
258
259 Scanner::token_t next;
261
262
263#endif // _RWSTD_CHARMAP_H_INCLUDED
264
265
bool convert_to_wc(const std::string &, const std::string &, wchar_t &)
Definition charmap.cpp:394
const std::list< std::string > & get_symnames_list() const
Definition charmap.h:94
const std::map< wchar_t, std::string > & get_rmb_cmap() const
Definition charmap.h:89
const std::map< unsigned char, std::string > & get_rn_cmap() const
Definition charmap.h:65
static const char *const portable_charset[]
Definition charmap.h:261
std::string get_full_charmap_name() const
Definition charmap.h:120
int get_mb_cur_max() const
Definition charmap.h:107
const std::string & get_code_set_name() const
Definition charmap.h:112
const std::map< std::string, unsigned char > & get_n_cmap() const
Definition charmap.h:59
const std::map< wchar_t, std::string > & get_rucs4_cmap() const
Definition charmap.h:102
std::string get_charmap_name() const
Definition charmap.cpp:475
const std::map< wchar_t, std::string > & get_rw_cmap() const
Definition charmap.h:77
bool convert_to_ucs(const std::string &, const std::string &, wchar_t &)
Definition charmap.cpp:664
unsigned char convert_char(const char *, const char **=0) const
unsigned char get_largest_nchar() const
wchar_t convert_sym_to_ucs(const std::string &) const
Definition charmap.cpp:641
const std::map< std::string, wchar_t > & get_w_cmap() const
Definition charmap.h:71
const std::map< std::string, wchar_t > & get_ucs4_cmap() const
Definition charmap.h:98
std::size_t mbcharlen(const std::string &) const
Definition charmap.cpp:241
const std::map< std::string, wchar_t > & get_mb_cmap() const
Definition charmap.h:83
wchar_t increment_wchar(wchar_t) const
Definition charmap.cpp:486