65#define UTF8_MAX_SIZE 6
70std::string Def::convert_to_ext (
wchar_t val)
80 "unable to convert character %d to external "
81 "representation\n",
val);
83 return std::string(
"");
88std::string Def::utf8_encode (
wchar_t wc)
107 if ((wc_int & (~(
wchar_t)0 << (5 *
b + 1))) == 0)
111 *bufp = (
unsigned char) (~0xff >>
b);
115 bufp[
b] = 0x80 | (wc_int & 0x3f);
122 for (
unsigned int i = 0;
i <
size;
i++)
128void Def::copy_file (
const std::string&
name,
const std::string& outname)
131 assert (outname.size() > 0);
133 std::ifstream from (
name.c_str(), std::ios::binary);
136 &next,
"unable to open locale database %s\n",
139 from.exceptions (std::ios::badbit);
141 std::ofstream to (outname.c_str(), std::ios::binary);
144 &next,
"unable to create locale database %s\n",
147 to.exceptions (std::ios::failbit | std::ios::badbit);
154void Def::copy_category(
int category, std::string
name)
159 std::string outname (output_name_);
171 copy_file (
name, outname);
172 ctype_written_ =
true;
178 copy_file(
name, outname);
179 collate_written_ =
true;
185 copy_file(
name, outname);
193 copy_file(
name, outname);
200 copy_file(
name, outname);
201 time_written_ =
true;
209 copy_file(
name, outname);
210 messages_written_ =
true;
221void Def::strip_pair (
const std::string &tok, std::string &sym,
228 while (tok[
i] !=
'>'){
231 sym.push_back(tok[
i++]);
235 sym.push_back(tok[
i++]);
238 "invalid pair %s\n", tok.c_str());
240 while (tok[
i] !=
'>'){
242 sym2.push_back(tok[
i++]);
244 sym2.push_back(tok[
i++]);
247 "invalid pair %s\n", tok.c_str());
252 sym2.push_back(tok[
i++]);
261std::string Def::convert_string (
const std::string &str1)
271 const char*
str = str1.c_str();
272 while (
str[idx] !=
'\"') {
276 if (
str[idx] ==
'\0') {
285 if (
str[idx] ==
'<') {
286 while (
str [idx] &&
str [idx] !=
'>') {
296 w_cmap_iter w_pos = charmap_.
get_w_cmap().find (sym);
298 ret += convert_to_ext(w_pos->second);
301 return std::string();
309 ret += (char)
str[idx++];
319#ifndef _RWSTD_NO_WCHAR_T
329 StringVector::const_iterator it = sym_array.begin ();
330 while (it != sym_array.end ()) {
332 w_cmap_iter w_pos = charmap_.
get_w_cmap().find (*it);
334 ret += w_pos->second;
351Def::convert_wstring (
const token_t&
t)
356 std::string str1 (
t.name);
360 const char*
str = str1.c_str();
363 if (
str[idx] ==
'\"') {
367 while (
str[idx] != term) {
372 if (
str[idx] ==
'<') {
373 while (
str[idx] !=
'>') {
379 if (
'\0' !=
str[idx])
383 "end of symbolic name not found\n");
390 w_cmap_iter w_pos = charmap_.
get_w_cmap().find (sym);
392 ret += w_pos->second;
418void Def::auto_fill ()
424 if ( ctype_out_.mask_tab[
i] & std::ctype_base::upper
425 || ctype_out_.mask_tab[
i] & std::ctype_base::lower
426 || ctype_out_.mask_tab[
i] & std::ctype_base::alpha
427 || ctype_out_.mask_tab[
i] & std::ctype_base::digit
428 || ctype_out_.mask_tab[
i] & std::ctype_base::xdigit
429 || ctype_out_.mask_tab[
i] & std::ctype_base::punct)
431 ctype_out_.mask_tab[
i] |= std::ctype_base::print;
433 if ( ctype_out_.mask_tab[
i] & std::ctype_base::upper
434 || ctype_out_.mask_tab[
i] & std::ctype_base::lower)
436 ctype_out_.mask_tab[
i] |= std::ctype_base::alpha;
438 if ( ctype_out_.mask_tab[
i] & std::ctype_base::upper
439 || ctype_out_.mask_tab[
i] & std::ctype_base::lower
440 || ctype_out_.mask_tab[
i] & std::ctype_base::alpha
441 || ctype_out_.mask_tab[
i] & std::ctype_base::digit
442 || ctype_out_.mask_tab[
i] & std::ctype_base::xdigit
443 || ctype_out_.mask_tab[
i] & std::ctype_base::punct)
445 ctype_out_.mask_tab[
i] |= std::ctype_base::graph;
448 for (mask_pos = mask_.begin(); mask_pos != mask_.end(); mask_pos++) {
452 if ( mask_pos->second & std::ctype_base::upper
453 || mask_pos->second & std::ctype_base::lower
454 || mask_pos->second & std::ctype_base::alpha
455 || mask_pos->second & std::ctype_base::digit
456 || mask_pos->second & std::ctype_base::xdigit
457 || mask_pos->second & std::ctype_base::punct)
460 mask_pos->second |= std::ctype_base::print;
463 if ( mask_pos->second & std::ctype_base::upper
464 || mask_pos->second & std::ctype_base::lower)
466 mask_pos->second |= std::ctype_base::alpha;
470 if ( mask_pos->second & std::ctype_base::upper
471 || mask_pos->second & std::ctype_base::lower
472 || mask_pos->second & std::ctype_base::alpha
473 || mask_pos->second & std::ctype_base::digit
474 || mask_pos->second & std::ctype_base::xdigit
475 || mask_pos->second & std::ctype_base::punct)
477 mask_pos->second |= std::ctype_base::graph;
488 switch (next.
token) {
533 : warnings_occurred_ (
false),
536 output_name_ (out_name),
538 ctype_written_ (
false),
539 codecvt_written_ (
false),
540 collate_written_ (
false),
541 time_written_ (
false),
542 num_written_ (
false),
543 mon_written_ (
false),
544 messages_written_ (
false),
545 ctype_def_found_ (
false),
546 collate_def_found_ (
false),
547 time_def_found_ (
false),
548 num_def_found_ (
false),
549 mon_def_found_ (
false),
550 messages_def_found_ (
false),
551 undefined_keyword_found_ (
false),
552 no_position_ (no_position)
556 std::memset (&ctype_out_, 0,
sizeof (ctype_out_));
557 std::memset (&time_out_, 0,
sizeof (time_out_));
561 mon_out_.frac_digits [0] =
CHAR_MAX;
562 mon_out_.frac_digits [1] =
CHAR_MAX;
563 mon_out_.p_cs_precedes [0] =
CHAR_MAX;
564 mon_out_.p_sep_by_space [0] =
CHAR_MAX;
565 mon_out_.n_cs_precedes [0] =
CHAR_MAX;
566 mon_out_.n_sep_by_space [0] =
CHAR_MAX;
567 mon_out_.p_sign_posn [0] =
CHAR_MAX;
568 mon_out_.n_sign_posn [0] =
CHAR_MAX;
573 mon_out_.p_cs_precedes [1] =
CHAR_MAX;
574 mon_out_.p_sep_by_space [1] =
CHAR_MAX;
575 mon_out_.n_cs_precedes [1] =
CHAR_MAX;
576 mon_out_.n_sep_by_space [1] =
CHAR_MAX;
577 mon_out_.p_sign_posn [1] =
CHAR_MAX;
578 mon_out_.n_sign_posn [1] =
CHAR_MAX;
582 collate_out_.largest_ce = 1;
583 collate_out_.longest_weight = 1;
584 collate_out_.num_wchars = 0;
585 std::memset (collate_out_.weight_type, 0,
586 sizeof (collate_out_.weight_type));
589 ctype_out_.ctype_ext_off = 0;
590 num_out_.numeric_ext_off = 0;
591 collate_out_.collate_ext_off = 0;
592 mon_out_.monetary_ext_off = 0;
593 time_out_.time_ext_off = 0;
596 scanner_.
open (filename);
604 coll_map_iter coll_map_pos;
605 for (coll_map_pos = coll_map_.begin();
606 coll_map_pos != coll_map_.end(); coll_map_pos ++) {
607 delete[] (coll_map_pos->second.weights);
#define _RWSTD_STATIC_CAST(T, x)
std::vector< std::string > StringVector
const std::map< wchar_t, std::string > & get_rmb_cmap() const
const std::map< std::string, wchar_t > & get_w_cmap() const
Def(const char *filename, const char *out_name, Charmap &charmap, bool no_position)
void open(std::string, char='#', char='\\')
bool issue_diag(int type, bool, const Scanner::token_t *token, const char *fmt,...)
int makedir(const char *name)