47create_wchar_utf8_table ()
49 if (!wchar_utf8_to_ext_.empty())
52 typedef std::map<std::string, wchar_t>::const_iterator
n_cmap_citer2;
57 n_cmap_it != n_cmap_end; ++n_cmap_it) {
59 const std::string wchar_utf8 = utf8_encode (n_cmap_it->second);
61 wchar_utf8_to_ext_.insert (std::make_pair (wchar_utf8,
67void Def::process_weights (collate_entry_t& entry)
70 token_list_t::iterator w_it = entry.second.begin ();
73 ce_map_iter ce_map_it;
74 coll_map_iter coll_map_it;
76 Weights_t* weights =
new Weights_t[collate_out_.num_weights];
79 for (
i = 0;
i < collate_out_.num_weights && w_it != entry.second.end ();
81 get_weight (*w_it, weights,
i);
84 const std::map<std::string, wchar_t>& w_cmap = charmap_.
get_w_cmap ();
88 while (
i < collate_out_.num_weights) {
90 wcmap_it = w_cmap.find (entry.first.name);
91 if (wcmap_it != w_cmap.end()) {
92 coll_map_it = coll_map_.find (wcmap_it->second);
93 weights[
i].weight[0] = coll_map_it->second.coll_val;
95 else if ((ce_map_it = ce_map_.find (entry.first.name)) !=
97 weights[
i].weight[0] = ce_map_it->second.coll_val;
102 "symbolic name %s not defined as character or "
103 "collating-element, ignoring\n",
109 wcmap_it = w_cmap.find (entry.first.name);
110 if (wcmap_it != w_cmap.end()) {
111 coll_map_it = coll_map_.find (wcmap_it->second);
112 coll_map_it->second.weights = weights;
113 }
else if ((ce_map_it = ce_map_.find (entry.first.name)) != ce_map_.end()) {
114 ce_map_it->second.weights = weights;
118 "symbolic name %s not defined as character or "
119 "collating-element, ignoring\n",
125unsigned int Def::process_order_stmt (collate_section_t& section)
128 collate_out_.num_weights = unsigned (section.order.size ());
129 if (collate_out_.num_weights == 0) {
130 collate_out_.num_weights = 1;
131 collate_out_.weight_type[0] = 0;
133 collate_out_.num_weights = 0;
134 token_list_t::iterator ord_it = section.order.begin ();
135 for (; ord_it != section.order.end ();
136 ++ord_it, ++collate_out_.num_weights) {
138 collate_out_.weight_type[collate_out_.num_weights] = 0;
140 collate_out_.weight_type[collate_out_.num_weights] = 1;
144 collate_out_.weight_type[collate_out_.num_weights] = 0;
146 collate_out_.weight_type[collate_out_.num_weights] = 2;
148 std::string::size_type comma_pos = ord_it->name.find (
',');
149 if (comma_pos != std::string::npos) {
150 std::string first = ord_it->name.substr (0, comma_pos);
151 std::string second = ord_it->name.substr (comma_pos + 1);
154 if ( (first ==
"forward" && second !=
"position")
155 || (first ==
"backward" && second !=
"position")) {
157 &*ord_it,
"unrecognized collating order\n");
159 }
else if (first ==
"forward") {
161 collate_out_.weight_type
162 [collate_out_.num_weights] = 0;
164 collate_out_.weight_type
165 [collate_out_.num_weights] = 2;
168 collate_out_.weight_type[collate_out_.num_weights] = 3;
172 &*ord_it,
"unrecognized collating order\n");
179 unsigned int order = 0;
180 for (
int i = 0;
i < collate_out_.num_weights; ++
i) {
182 order |= collate_out_.weight_type[
i];
192dec_increment (
const std::string &sym)
194 const char *pdig = sym.c_str ();
196 for (; !(std::isdigit (*pdig)); ++pdig);
200 const unsigned long sym_val = std::strtoul (pdig, &end, 10);
203 std::sprintf (numstr,
"%lu", sym_val + 1);
205 std::string next_sym = sym.substr (0, pdig - sym.c_str ());
206 next_sym.append (numstr);
207 next_sym.append (end);
215hex_increment (
const std::string& sym)
217 const char *pdig = sym.c_str ();
219 for (; !(std::isxdigit (*pdig)); ++pdig);
223 const unsigned long sym_val = std::strtoul (pdig, &end, 16);
226 std::sprintf (numstr,
"%lx", sym_val + 1);
228 std::string next_sym = sym.substr (0, pdig - sym.c_str ());
229 next_sym.append (numstr);
230 next_sym.append (end);
237void Def::preprocess_collation_definitions()
240 unsigned int coll_value = 2;
243 std::string prev_elm;
244 std::string next_elm;
246 token_list_t::iterator cs_it = sym_list_.begin ();
247 for (; cs_it != sym_list_.end (); ++cs_it) {
248 cs_map_iter csm_it = cs_map_.find (cs_it->name);
249 if (csm_it != cs_map_.end ())
250 csm_it->second = coll_value++;
253 static token_list_t::size_type max_orders = 0;
255 std::list<collate_section_t>::iterator s_it = section_list_.begin ();
257 if (s_it != section_list_.end()) {
259 max_orders = s_it->order.size ();
262 for (; s_it != section_list_.end (); ++s_it) {
263 if (max_orders != s_it->order.size ())
265 "number of collation orders "
266 "different for this section\n");
269 const std::map<std::string, wchar_t>& w_cmap = charmap_.
get_w_cmap ();
272 for (s_it = section_list_.begin ();
273 s_it != section_list_.end (); ++s_it) {
276 unsigned int order = process_order_stmt (*s_it);
278 std::list<collate_entry_t>::iterator e_it =
279 s_it->entries.begin ();
281 for (; e_it != s_it->entries.end (); ++e_it) {
282 switch (e_it->first.token) {
285 prev_elm = e_it->first.name;
288 process_collation_definition (
false, *e_it,
289 coll_value++, order);
298 if (++e_it != s_it->entries.end ())
299 next_elm = e_it->first.name;
302 "unexpected end of collation section while"
303 " processing ellipsis during scan_ahead\n");
307 wchar_t w_cmap_cur_val
308 = w_cmap.find(prev_elm)->second;
309 wchar_t w_cmap_end_val
310 = w_cmap.find(next_elm)->second;
315 while (w_cmap_cur_val != w_cmap_end_val) {
318 ci.coll_val = coll_value++;
321 coll_map_.insert (std::make_pair (w_cmap_cur_val, ci));
328 ci.coll_val = coll_value++;
330 coll_map_.insert (std::make_pair (w_cmap_cur_val, ci));
335 std::string next_name = prev_elm;
338 next_name = hex_increment (next_name);
340 next_name = dec_increment (next_name);
342 w_cmap_iter it = w_cmap.find (next_name);
343 if (it != w_cmap.end()) {
346 ci.coll_val = coll_value++;
349 std::make_pair (it->second, ci));
351 }
while (next_name != next_elm);
360 "ellipsis not supported"
361 " processing ellipsis during scan_ahead\n");
370void Def::process_collation_definition (
bool do_weights,
371 collate_entry_t& entry,
372 unsigned int coll_value,
375 const std::map<std::string, wchar_t>& w_cmap = charmap_.
get_w_cmap ();
378 w_cmap_iter w_cmap_pos =
379 w_cmap.find(entry.first.name);
380 ce_map_iter ce_map_pos =
381 ce_map_.find(entry.first.name);
384 if (w_cmap_pos != w_cmap.end()) {
386 wchar_t wval = w_cmap_pos->second;
387 coll_map_iter coll_map_pos = coll_map_.find (wval);
389 coll_map_pos->second.coll_val = coll_value;
390 coll_map_pos->second.order = order;
394 unsigned int offset = next_offset_++;
395 coll_map_pos->second.offset =
offset;
396 off_mapr_.insert(std::make_pair(
offset, entry.first.name));
398 process_weights (entry);
402 else if (ce_map_pos != ce_map_.end()) {
404 ce_map_pos->second.coll_val = coll_value;
405 ce_map_pos->second.order = order;
409 unsigned int offset = next_offset_++;
410 ce_map_pos->second.offset =
offset;
411 off_mapr_.insert(std::make_pair(
offset, entry.first.name));
413 process_weights (entry);
417 else if (cs_map_.find(entry.first.name) != cs_map_.end()) {
419 cs_map_.find(entry.first.name)->second = coll_value;
425 cs_map_.insert (std::make_pair(entry.first.name, coll_value));
429 "unknown symbol name %s found in "
430 "LC_COLLATE definition\n",
435void Def::process_order(collate_section_t& section,
436 unsigned int& coll_value)
441 unsigned int section_order = process_order_stmt (section);
444 std::string curr_elm;
447 std::string prev_elm;
448 std::string next_elm;
450 const std::map<std::string, wchar_t>& w_cmap = charmap_.
get_w_cmap ();
453 std::list<collate_entry_t>::iterator e_it = section.entries.begin ();
454 for (; e_it != section.entries.end (); ++e_it) {
456 prev_elm = e_it->first.name;
457 process_collation_definition (
true, *e_it,
458 coll_value++, section_order);
466 Weights_t* weights_template =
467 new Weights_t[collate_out_.num_weights];
468 std::vector<bool> ordinal_weights;
470 token_list_t::iterator w_it = e_it->second.begin ();
471 for (
int i = 0;
i < collate_out_.num_weights
472 && w_it != e_it->second.end (); ++
i, ++w_it) {
473 ordinal_weights.push_back (
474 get_weight (*w_it,weights_template,
i));
476 while (ordinal_weights.size() < collate_out_.num_weights)
477 ordinal_weights.push_back (
true);
480 if (++e_it != section.entries.end ())
481 next_elm = e_it->first.name;
484 "unexpected end of collation section while"
485 " processing ellipsis\n");
489 wchar_t w_cmap_cur_val
490 = w_cmap.find(prev_elm)->second;
491 wchar_t w_cmap_end_val
492 = w_cmap.find(next_elm)->second;
497 while (w_cmap_cur_val != w_cmap_end_val) {
499 add_to_coll (w_cmap_cur_val, weights_template,
500 coll_value++, ordinal_weights,
false);
506 add_to_coll (w_cmap_end_val, weights_template, coll_value++,
507 ordinal_weights,
false);
512 std::string next_name = prev_elm;
515 next_name = hex_increment (next_name);
517 next_name = dec_increment (next_name);
519 w_cmap_iter it = w_cmap.find (next_name);
520 if (it != w_cmap.end()) {
521 add_to_coll (it->second, weights_template,
522 coll_value++, ordinal_weights,
false);
524 }
while (next_name != next_elm);
530 delete[] weights_template;
536 undefined_keyword_found_ =
true;
537 collate_out_.undefined_optimization =
true;
538 undef_char_info_.order = section_order;
539 Weights_t* weights_template
540 =
new Weights_t[collate_out_.num_weights];
541 std::vector<bool> ordinal_weights;
543 token_list_t::iterator w_it = e_it->second.begin ();
544 for (
int i = 0;
i < collate_out_.num_weights
545 && w_it != e_it->second.end(); ++
i, ++w_it) {
548 collate_out_.undefined_optimization =
false;
550 ordinal_weights.push_back (
551 !get_weight (*w_it, weights_template,
i));
554 while (ordinal_weights.size() < collate_out_.num_weights)
555 ordinal_weights.push_back (
false);
557 add_missing_values (ordinal_weights, weights_template,
560 delete[] weights_template;
565void Def::add_missing_values (
const std::vector<bool> &ordinal_weights,
566 const Weights_t* weights_template,
567 unsigned int &coll_value,
bool give_warning)
569 const std::map<std::string, wchar_t>& w_cmap = charmap_.
get_w_cmap ();
573 bool warning_issued =
false;
575 symnames_list_iter symnames_it;
580 std::map<std::string, wchar_t>::const_iterator w_cmap_it;
581 if ((w_cmap_it = w_cmap.find(*symnames_it)) != w_cmap.end()) {
582 wchar_t wchar_val = (*w_cmap_it).second;
584 coll_map_iter coll_map_it;
585 if ((coll_map_it = coll_map_.find(wchar_val)) != coll_map_.end()) {
586 if (coll_map_it->second.offset ==
UINT_MAX) {
587 if (give_warning && !warning_issued) {
588 warning_issued =
true;
591 0,
"some characters in the codeset "
592 "were not explicitly given a "
596 if (!collate_out_.undefined_optimization) {
597 add_to_coll (wchar_val, weights_template,
598 coll_value++, ordinal_weights,
true);
604 if (collate_out_.undefined_optimization){
605 collate_out_.undefined_weight_idx = next_offset_++;
606 undef_char_info_.offset = collate_out_.undefined_weight_idx;
607 undef_char_info_.coll_val = coll_value++;
609 Weights_t* weights =
new Weights_t[collate_out_.num_weights];
611 if (0 != weights_template) {
612 for (
int k = 0;
k < collate_out_.num_weights; ++
k) {
613 weights[
k].size = weights_template[
k].size;
614 for (
int j = 0;
j < 256; ++
j)
615 weights[
k].weight[
j] = weights_template[
k].weight[
j];
620 std::vector<bool>::const_iterator it;
627 for (it = ordinal_weights.begin();
628 it != ordinal_weights.end(); ++it, ++
i)
633 weights[
i].weight[0] = undef_char_info_.coll_val;
636 undef_char_info_.weights = weights;
642void Def::add_to_coll (
const wchar_t w_cmap_cur_val,
643 const Weights_t* weights_template,
644 const unsigned int coll_value,
645 const std::vector<bool>& ordinal_weights,
646 bool undefined_value)
648 Weights_t* weights =
new Weights_t[collate_out_.num_weights];
650 if (0 != weights_template) {
651 for (
int k = 0;
k < collate_out_.num_weights; ++
k) {
652 weights[
k].size = weights_template[
k].size;
653 for (
int j = 0;
j < 256; ++
j)
654 weights[
k].weight[
j] = weights_template[
k].weight[
j];
660 = charmap_.
get_rw_cmap().find (w_cmap_cur_val)->second;
661 coll_map_.find (w_cmap_cur_val)->second.coll_val = coll_value;
664 if (undefined_value && collate_out_.undefined_optimization)
669 const std::map<std::string, wchar_t>& w_cmap = charmap_.
get_w_cmap ();
671 w_cmap_iter w_cmap_pos = w_cmap.find(
name);
672 coll_map_iter coll_it = coll_map_.find (w_cmap_pos->second);
673 coll_it->second.offset =
offset;
675 off_mapr_.insert(std::make_pair(
offset,
name));
677 std::vector<bool>::const_iterator it;
684 for (it = ordinal_weights.begin();
685 it != ordinal_weights.end(); ++it, ++
i)
689 weights[
i].weight[0] = coll_value;
692 coll_it->second.weights = weights;
698void Def::gen_valid_coll_mb_set ()
700 if (!valid_coll_mb_set_.empty())
703 for (coll_map_iter coll_it = coll_map_.begin();
704 coll_it != coll_map_.end(); ++coll_it) {
705 if (coll_it->second.offset !=
UINT_MAX
706 || !collate_out_.undefined_optimization){
707 rmb_cmap_iter rn_cmap_it
709 std::string valid = rn_cmap_it->second.substr
710 (0, rn_cmap_it->second.size() - 1);
712 while (valid.size() > 0){
713 valid_coll_mb_set_.insert (valid);
714 valid = valid.substr(0, valid.size() - 1);
728void Def::process_collate()
733 collate_def_found_ =
true;
738 preprocess_collate ();
740 const std::map<std::string, wchar_t>& w_cmap = charmap_.
get_w_cmap ();
743 token_list_t::iterator cs_it = cs_list_.begin ();
744 for (;cs_it != cs_list_.end (); ++cs_it) {
745 if (w_cmap.find (cs_it->name) !=
748 "collating-symbol %s found in character map\n",
749 cs_it->name.c_str ());
750 else if (ce_map_.find (cs_it->name) != ce_map_.end())
752 "collating-symbol %s has already been defined as "
753 "a collating-element\n", cs_it->name.c_str ());
755 cs_map_.insert (std::make_pair (cs_it->name, 0));
759 std::list<collate_elem_t>::iterator ce_it =
761 for (; ce_it != ce_list_.end (); ++ce_it) {
762 if (w_cmap.find (ce_it->first.name) !=
765 "collating element %s found in charmap\n",
766 ce_it->first.name.c_str());
777 std::vector<std::string> ce_sym_array;
781 token_list_t::iterator ce_def_it = ce_def_list.begin ();
782 bool invalid =
false;
785 if ((ce_tmp.ce_wstr = convert_wstring (*ce_def_it)).empty())
788 for (; ce_def_it != ce_def_list.end (); ++ce_def_it)
789 ce_sym_array.push_back (ce_def_it->name);
790 if ((ce_tmp.ce_wstr = convert_wstring (ce_sym_array)).empty())
794 "illegal collating-element expression: %s\n",
795 ce_def_it->name.c_str ());
799 "character in collating element definition "
800 "not found in character map\n");
803 ce_map_.insert (std::make_pair(ce_it->first.name, ce_tmp));
806 std::string ce_utf8_wstr;
807 for (
unsigned int i = 0;
i < ce_tmp.ce_wstr.size(); ++
i){
808 ce_str += convert_to_ext(ce_tmp.ce_wstr[
i]);
809 ce_utf8_wstr += utf8_encode (ce_tmp.ce_wstr[
i]);
811 ce_sym_map_.insert (std::make_pair(ce_str, ce_it->first.name));
812 ce_wsym_map_.insert (std::make_pair (ce_utf8_wstr,
819 preprocess_collation_definitions();
822 unsigned int coll_value = 2;
825 cs_it = sym_list_.begin ();
826 for (; cs_it != sym_list_.end (); ++cs_it) {
827 cs_map_iter csm_it = cs_map_.find (cs_it->name);
828 if (csm_it != cs_map_.end ())
829 csm_it->second = coll_value++;
833 std::list<collate_section_t>::iterator sect_it =
834 section_list_.begin ();
835 for (; sect_it != section_list_.end (); ++sect_it)
836 process_order (*sect_it, coll_value);
839 if (!undefined_keyword_found_) {
840 std::vector<bool> ordinal_weights;
841 for (
int i = 0;
i < collate_out_.num_weights; ++
i)
842 ordinal_weights.push_back (
false);
843 collate_out_.undefined_optimization =
true;
844 add_missing_values (ordinal_weights, 0, coll_value,
true);
850void Def::gen_n_to_w_coll_tables (
const std::string &charp,
851 unsigned int tab_num)
853 gen_valid_coll_mb_set();
859 tab.first_offset = -1;
860 mb_cmap_iter n_cmap_it;
863 unsigned char cur_char = (
unsigned char)
i;
864 std::string mb_char = charp;
865 mb_char += (char)cur_char;
866 if ((n_cmap_it = charmap_.
get_mb_cmap().find (mb_char))
868 coll_map_iter coll_map_it = coll_map_.find (n_cmap_it->second);
869 if (coll_map_it->second.offset !=
UINT_MAX
870 || !collate_out_.undefined_optimization) {
871 tab.off[cur_char] = coll_map_it->second.offset;
872 if (tab.first_offset == -1)
873 tab.first_offset = cur_char;
877 if (valid_coll_mb_set_.find (mb_char) != valid_coll_mb_set_.end()){
879 tab.off[cur_char] = next_tab_num_ | 0x80000000;
880 gen_n_to_w_coll_tables (mb_char, next_tab_num_);
881 if (tab.first_offset == -1)
882 tab.first_offset = cur_char;
890 char_offs_.insert (std::make_pair (tab_num, tab));
894void Def::gen_w_to_n_coll_tables (
const std::string &charp,
895 unsigned int tab_num)
898 create_wchar_utf8_table();
899 gen_valid_coll_wchar_set();
905 tab.first_offset = -1;
906 wchar_utf8_iter wu_it;
907 mb_cmap_iter n_cmap_it;
910 unsigned char cur_char = (
unsigned char)
i;
911 std::string mb_char = (charp);
913 mb_char += (char)cur_char;
915 wu_it = wchar_utf8_to_ext_.find (mb_char);
916 if (wu_it != wchar_utf8_to_ext_.end()) {
917 n_cmap_it = charmap_.
get_mb_cmap().find (wu_it->second);
920 coll_map_iter coll_map_it = coll_map_.find (n_cmap_it->second);
921 if (coll_map_it->second.offset !=
UINT_MAX ||
922 !collate_out_.undefined_optimization) {
923 tab.off[cur_char] = coll_map_it->second.offset;
924 if (tab.first_offset == -1)
925 tab.first_offset = cur_char;
930 if (valid_coll_wchar_set_.find (mb_char) !=
931 valid_coll_wchar_set_.end()) {
933 ++next_wchar_coll_tab_num_;
934 tab.off[cur_char] = next_wchar_coll_tab_num_ | 0x80000000;
935 gen_w_to_n_coll_tables (mb_char,
936 next_wchar_coll_tab_num_);
937 if (tab.first_offset == -1)
938 tab.first_offset = cur_char;
944 w_to_n_coll_.insert (std::make_pair (tab_num, tab));
948void Def::gen_n_ce_tables (
const std::set<std::string>ce_elms,
949 unsigned int idx,
unsigned int tab_num)
951 if (ce_elms.size() > 0) {
956 tab.first_offset = -1;
958 ce_sym_map_iter ce_sym_map_it;
959 ce_map_iter ce_map_it;
961 std::set<std::string>::const_iterator ce_elms_it;
962 std::set<std::string> next_elms;
966 for (ce_elms_it = ce_elms.begin(); ce_elms_it != ce_elms.end();
969 if ((
unsigned char)
i == (
unsigned char)((*ce_elms_it)[idx])) {
970 if ((*ce_elms_it).size() == idx + 1) {
971 if ((ce_sym_map_it = ce_sym_map_.find (*ce_elms_it))
972 != ce_sym_map_.end()) {
973 ce_map_it = ce_map_.find(ce_sym_map_it->second);
974 tab.off[
i] = ce_map_it->second.offset;
975 if (tab.first_offset == -1)
976 tab.first_offset =
i;
977 if ((
unsigned int)tab.last_offset <
i)
983 next_elms.insert (*ce_elms_it);
985 ++ next_n_ce_tab_num_;
986 tab.off[
i] = next_n_ce_tab_num_ | 0x80000000;
988 if (tab.first_offset == -1)
989 tab.first_offset =
i;
990 if ((
unsigned int)tab.last_offset <
i)
997 if (next_elms.size() != 0)
998 gen_n_ce_tables (next_elms, idx + 1, next_n_ce_tab_num_);
1000 n_ce_offs_.insert(std::make_pair(tab_num, tab));
1006void Def::gen_w_ce_tables (
const std::set<std::string>ce_elms,
1007 unsigned int idx,
unsigned int tab_num)
1009 if (ce_elms.size() > 0) {
1010 ce_offset_tab_t tab;
1014 tab.first_offset = -1;
1015 tab.last_offset = 0;
1016 ce_sym_map_iter ce_sym_map_it;
1017 ce_map_iter ce_map_it;
1019 std::set<std::string>::const_iterator ce_elms_it;
1020 std::set<std::string> next_elms;
1024 for (ce_elms_it = ce_elms.begin(); ce_elms_it != ce_elms.end();
1027 if ((
unsigned char)
i == (
unsigned char)(*ce_elms_it)[idx]) {
1028 if ((*ce_elms_it).size() == idx + 1) {
1029 if ((ce_sym_map_it = ce_wsym_map_.find (*ce_elms_it))
1030 != ce_wsym_map_.end()) {
1031 ce_map_it = ce_map_.find(ce_sym_map_it->second);
1032 tab.off[
i] = ce_map_it->second.offset;
1033 if (tab.first_offset == -1)
1034 tab.first_offset =
i;
1035 if ((
unsigned int)tab.last_offset <
i)
1036 tab.last_offset =
i;
1040 next_elms.insert (*ce_elms_it);
1042 ++ next_w_ce_tab_num_;
1043 tab.off[
i] = next_w_ce_tab_num_ | 0x80000000;
1045 if (tab.first_offset == -1)
1046 tab.first_offset =
i;
1047 if ((
unsigned int)tab.last_offset <
i)
1048 tab.last_offset =
i;
1054 if (next_elms.size() != 0)
1055 gen_w_ce_tables (next_elms, idx + 1, next_w_ce_tab_num_);
1057 w_ce_offs_.insert(std::make_pair(tab_num, tab));
1064 std::cout <<
"LC_COLLATE\n";
1066 const std::map<std::string, wchar_t>& w_cmap = charmap_.
get_w_cmap ();
1068 token_list_t::iterator sl_it = sym_list_.begin ();
1069 for (; sl_it != sym_list_.end (); ++sl_it) {
1070 std::cout << sl_it->name <<
" % ";
1071 cs_map_iter cs_it = cs_map_.find (sl_it->name);
1072 if (cs_it != cs_map_.end ()) {
1073 std::cout << cs_it->second <<
'\n';
1077 ce_map_iter ce_it = ce_map_.find (sl_it->name);
1078 if (ce_it != ce_map_.end ()) {
1079 std::cout << ce_it->second.coll_val <<
'\n';
1083 std::map<std::string, wchar_t >::const_iterator cw_it =
1084 w_cmap.find (sl_it->name);
1085 if (cw_it != w_cmap.end ()) {
1086 coll_map_iter cm_it =
1087 coll_map_.find (cw_it->second);
1088 if (cm_it != coll_map_.end ()) {
1089 std::cout << cm_it->second.coll_val <<
'\n';
1096 std::cout <<
"\n\n";
1098 std::list<collate_section_t>::iterator sect_it =
1099 section_list_.begin ();
1100 while (sect_it != section_list_.end ()) {
1103 std::cout <<
"order_start " << sect_it->name;
1104 token_list_t::iterator o_it = sect_it->order.begin ();
1105 for (; o_it != sect_it->order.end (); ++o_it)
1106 std::cout <<
";" << o_it->name;
1110 collate_entry_list_t::iterator e_it = sect_it->entries.begin ();
1111 for (; e_it != sect_it->entries.end (); ++e_it) {
1114 std::cout << e_it->first.name <<
" ";
1115 if (!e_it->second.empty ()) {
1116 token_list_t::iterator w_it = e_it->second.begin ();
1117 std::cout << (w_it++)->
name;
1118 for (; w_it != e_it->second.end (); ++w_it)
1119 std::cout <<
";" << w_it->name;
1123 cs_map_iter cs_it = cs_map_.find (e_it->first.name);
1124 if (cs_it != cs_map_.end ()) {
1125 std::cout <<
" % " << cs_it->second <<
'\n';
1129 ce_map_iter ce_it = ce_map_.find (e_it->first.name);
1130 if (ce_it != ce_map_.end ()) {
1131 std::cout <<
" % " << ce_it->second.coll_val <<
'\n';
1135 std::map<std::string, wchar_t >::const_iterator cw_it =
1136 w_cmap.find (e_it->first.name);
1137 if (cw_it != w_cmap.end ()) {
1138 coll_map_iter cm_it =
1139 coll_map_.find (cw_it->second);
1140 if (cm_it != coll_map_.end ()) {
1141 std::cout <<
" % " << cm_it->second.coll_val <<
'\n';
1149 std::cout <<
"order_end\n";
1152 std::cout <<
"END LC_COLLATE\n";
1158 assert (!dir_name.empty());
1160 static const char lc_name[] =
"LC_COLLATE";
1162 if (collate_written_)
1165 if (!collate_def_found_) {
1167 "%s section not found, skipping\n", lc_name);
1172 next_wchar_coll_tab_num_ = 0;
1173 std::set<std::string> ce_strs;
1176 for (it = ce_sym_map_.begin (); it != ce_sym_map_.end (); ++it) {
1177 if ((ce_mit = ce_map_.find (it->second))->second.coll_val
1180 if (ce_mit->second.ce_wstr.size() + 1
1181 > collate_out_.largest_ce)
1182 collate_out_.largest_ce =
1183 unsigned (ce_mit->second.ce_wstr.size());
1185 ce_strs.insert (it->first);
1188 next_n_ce_tab_num_ = 0;
1189 gen_n_ce_tables(ce_strs, 0, 0);
1191 for (it = ce_wsym_map_.begin (); it != ce_wsym_map_.end (); ++it) {
1192 if (ce_map_.find (it->second)->second.coll_val !=
UINT_MAX)
1193 ce_strs.insert (it->first);
1195 next_w_ce_tab_num_ = 0;
1196 gen_w_ce_tables (ce_strs, 0, 0);
1198 gen_n_to_w_coll_tables (
"", next_tab_num_);
1199 gen_w_to_n_coll_tables (
"", next_wchar_coll_tab_num_);
1205 std::ofstream
out (dir_name.c_str(), std::ios::binary);
1206 out.exceptions (std::ios::failbit | std::ios::badbit);
1209 collate_out_.elm_size = collate_out_.num_weights
1210 * collate_out_.longest_weight * unsigned (
sizeof (
unsigned int)) +
1211 unsigned (
sizeof (
unsigned int));
1215 collate_out_.n_ce_tab_off = 0;
1216 collate_out_.w_ce_tab_off = collate_out_.n_ce_tab_off;
1217 n_ce_offs_iter n_ce_offs_it;
1218 for (n_ce_offs_it = n_ce_offs_.begin();
1219 n_ce_offs_it != n_ce_offs_.end (); ++n_ce_offs_it) {
1220 collate_out_.w_ce_tab_off += (n_ce_offs_it->second.last_offset
1221 - n_ce_offs_it->second.first_offset + 1)
1222 *
unsigned (
sizeof (
int));
1226 collate_out_.weight_tab_off = collate_out_.w_ce_tab_off;
1227 w_ce_offs_iter w_ce_offs_it;
1228 for (w_ce_offs_it = w_ce_offs_.begin();
1229 w_ce_offs_it != w_ce_offs_.end(); ++w_ce_offs_it) {
1230 collate_out_.weight_tab_off += (w_ce_offs_it->second.last_offset
1231 - w_ce_offs_it->second.first_offset + 1)
1232 *
unsigned (
sizeof (
int));
1235 coll_map_iter coll_map_pos;
1237 collate_out_.num_elms = unsigned (off_mapr_.size());
1238 if (collate_out_.undefined_optimization)
1239 ++collate_out_.num_elms;
1242 collate_out_.n_char_tab_off = collate_out_.weight_tab_off
1243 + collate_out_.num_elms * collate_out_.elm_size;
1247 char_offs_iter char_offs_it;
1248 unsigned int char_offs_size = 0;
1249 for (char_offs_it = char_offs_.begin();
1250 char_offs_it != char_offs_.end(); ++char_offs_it) {
1252 - char_offs_it->second.first_offset)
1253 *
unsigned (
sizeof (
unsigned int));
1256 collate_out_.w_char_tab_off = collate_out_.n_char_tab_off
1261 w_to_n_coll_iter w_to_n_coll_it;
1262 unsigned int w_to_n_size = 0;
1263 for (w_to_n_coll_it = w_to_n_coll_.begin();
1264 w_to_n_coll_it != w_to_n_coll_.end(); ++w_to_n_coll_it) {
1266 - w_to_n_coll_it->second.first_offset)
1267 *
unsigned (
sizeof (
unsigned int));
1270 collate_out_.n_char_off_tab_off = collate_out_.w_char_tab_off
1274 collate_out_.w_char_off_tab_off = collate_out_.n_char_off_tab_off
1275 + unsigned (char_offs_.size() * sizeof (
unsigned int));
1278 collate_out_.n_ce_off_tab_off = collate_out_.w_char_off_tab_off
1279 + unsigned (w_to_n_coll_.size() * sizeof (
unsigned int));
1282 collate_out_.w_ce_off_tab_off = collate_out_.n_ce_off_tab_off
1283 + unsigned (n_ce_offs_.size() * sizeof (
unsigned int));
1286 collate_out_.n_char_first_char_off = collate_out_.w_ce_off_tab_off
1287 + unsigned (w_ce_offs_.size() * sizeof (
unsigned int));
1290 collate_out_.w_char_first_char_off = collate_out_.n_char_first_char_off
1291 + unsigned (char_offs_.size() * sizeof (
unsigned char));
1294 collate_out_.n_ce_first_char_off = collate_out_.w_char_first_char_off
1295 + unsigned (w_to_n_coll_.size() * sizeof (
unsigned char));
1298 collate_out_.w_ce_first_char_off = collate_out_.n_ce_first_char_off
1299 + unsigned (n_ce_offs_.size() * sizeof (
unsigned char));
1302 collate_out_.n_ce_last_char_off = collate_out_.w_ce_first_char_off
1303 + unsigned (w_ce_offs_.size() * sizeof (
unsigned char));
1306 collate_out_.w_ce_last_char_off = collate_out_.n_ce_last_char_off
1307 + unsigned (n_ce_offs_.size() * sizeof (
unsigned char));
1310 collate_out_.codeset_off = collate_out_.w_ce_last_char_off
1311 + unsigned (w_ce_offs_.size() * sizeof (
unsigned char));
1314 collate_out_.charmap_off = collate_out_.codeset_off
1320 out.write ((
char*)&collate_out_,
sizeof(collate_out_));
1323 for (n_ce_offs_it = n_ce_offs_.begin();
1324 n_ce_offs_it != n_ce_offs_.end(); ++n_ce_offs_it) {
1325 for (
i = (
unsigned int)n_ce_offs_it->second.first_offset;
1326 i <= (
unsigned int)n_ce_offs_it->second.last_offset; ++
i)
1327 out.write ((
char*)&n_ce_offs_it->second.off[
i],
1328 sizeof (n_ce_offs_it->second.off[
i]));
1331 for (w_ce_offs_it = w_ce_offs_.begin();
1332 w_ce_offs_it != w_ce_offs_.end(); ++w_ce_offs_it) {
1333 for (
i = (
unsigned int)w_ce_offs_it->second.first_offset;
1334 i <= (
unsigned int)w_ce_offs_it->second.last_offset; ++
i)
1335 out.write ((
char*)&w_ce_offs_it->second.off[
i],
1336 sizeof (w_ce_offs_it->second.off[
i]));
1343 bool undefined_written =
false;
1345 const std::map<std::string, wchar_t>& w_cmap = charmap_.
get_w_cmap ();
1347 std::size_t off_idx = 0;
1348 off_mapr_iter current_off = off_mapr_.begin();
1349 for (; current_off != off_mapr_.end(); ++off_idx) {
1352 if (current_off->first != off_idx
1353 && off_idx != undef_char_info_.offset)
1355 "current_off : %d, index : %d, giving up\n",
1356 current_off->first, off_idx);
1358 if (collate_out_.undefined_optimization
1359 && off_idx == undef_char_info_.offset) {
1360 undefined_written =
true;
1361 weights = undef_char_info_.weights;
1362 out.write ((
char*)&undef_char_info_.order,
1363 sizeof (undef_char_info_.order));
1364 for (
int j = 0;
j < collate_out_.num_weights; ++
j) {
1365 for (
int k = 0;
k < weights[
j].size; ++
k) {
1366 out.write ((
char*)&weights[
j].weight[
k],
1367 sizeof (weights[
j].weight[
k]));
1369 for (
int c = weights[
j].
size;
1370 c < collate_out_.longest_weight; ++
c)
1371 out.write ((
char*)&maxw, sizeof (maxw));
1376 w_cmap_iter w_cmap_pos = w_cmap.find
1377 (current_off->second);
1378 if (w_cmap_pos != w_cmap.end()) {
1379 coll_map_pos = coll_map_.find (w_cmap_pos->second);
1380 out.write ((
char*)&coll_map_pos->second.order,
1381 sizeof (coll_map_pos->second.order));
1382 weights = coll_map_pos->second.weights;
1383 for (
int j = 0;
j < collate_out_.num_weights; ++
j) {
1384 for (
int k = 0;
k < weights[
j].size; ++
k) {
1385 out.write ((
char*)&weights[
j].weight[
k],
1386 sizeof (weights[
j].weight[
k]));
1388 for (
int c = weights[
j].
size;
1389 c < collate_out_.longest_weight; ++
c)
1390 out.write ((
char*)&maxw, sizeof (maxw));
1396 ce_map_iter ce_map_it = ce_map_.find (current_off->second);
1397 if (ce_map_it != ce_map_.end()
1398 && ce_map_it->second.coll_val !=
UINT_MAX) {
1399 out.write ((
char*)&ce_map_it->second.order,
1400 sizeof (ce_map_it->second.order));
1401 weights = ce_map_it->second.weights;
1402 for (
int j = 0;
j < collate_out_.num_weights; ++
j) {
1403 for (
int k = 0;
k < weights[
j].size; ++
k) {
1404 out.write ((
char*)&weights[
j].weight[
k],
1405 sizeof (weights[
j].weight[
k]));
1407 for (
int c = weights[
j].
size;
1408 c < collate_out_.longest_weight; ++
c)
1409 out.write ((
char*)&maxw, sizeof (maxw));
1418 if (!undefined_written && collate_out_.undefined_optimization) {
1419 if (off_idx != undef_char_info_.offset)
1421 "current_off : %d, index : %d, giving up\n",
1422 undef_char_info_.offset, off_idx);
1424 weights = undef_char_info_.weights;
1425 out.write ((
char*)&undef_char_info_.order,
1426 sizeof (undef_char_info_.order));
1427 for (
int j = 0;
j < collate_out_.num_weights; ++
j) {
1428 for (
int k = 0;
k < weights[
j].size; ++
k) {
1429 out.write ((
char*)&weights[
j].weight[
k],
1430 sizeof (weights[
j].weight[
k]));
1432 for (
int c = weights[
j].
size;
1433 c < collate_out_.longest_weight; ++
c)
1434 out.write ((
char*)&maxw, sizeof (maxw));
1439 for (char_offs_it = char_offs_.begin();
1440 char_offs_it != char_offs_.end(); ++char_offs_it) {
1441 for (
unsigned int c = char_offs_it->second.first_offset;
1443 out.write ((
const char*)&char_offs_it->second.off[
c],
1444 sizeof (char_offs_it->second.off[
c]));
1449 for (w_to_n_coll_it = w_to_n_coll_.begin();
1450 w_to_n_coll_it != w_to_n_coll_.end(); ++w_to_n_coll_it) {
1451 for (
unsigned int c = w_to_n_coll_it->second.first_offset;
1453 out.write ((
const char*)&w_to_n_coll_it->second.off[
c],
1454 sizeof (w_to_n_coll_it->second.off[
c]));
1459 unsigned int current_offset = 0;
1460 for (char_offs_it = char_offs_.begin();
1461 char_offs_it != char_offs_.end(); ++char_offs_it) {
1462 out.write ((
const char*)¤t_offset,
sizeof (current_offset));
1464 - char_offs_it->second.first_offset);
1469 for (w_to_n_coll_it = w_to_n_coll_.begin();
1470 w_to_n_coll_it != w_to_n_coll_.end(); ++w_to_n_coll_it) {
1471 out.write ((
const char*)¤t_offset,
sizeof (current_offset));
1473 - w_to_n_coll_it->second.first_offset);
1478 for (n_ce_offs_it = n_ce_offs_.begin();
1479 n_ce_offs_it != n_ce_offs_.end(); ++n_ce_offs_it) {
1480 out.write ((
const char*)¤t_offset,
sizeof (current_offset));
1481 current_offset += (n_ce_offs_it->second.last_offset
1482 - n_ce_offs_it->second.first_offset + 1);
1487 for (w_ce_offs_it = w_ce_offs_.begin();
1488 w_ce_offs_it != w_ce_offs_.end(); ++w_ce_offs_it) {
1489 out.write ((
const char*)¤t_offset,
sizeof (current_offset));
1490 current_offset += (w_ce_offs_it->second.last_offset
1491 - w_ce_offs_it->second.first_offset + 1);
1496 for (char_offs_it = char_offs_.begin();
1497 char_offs_it != char_offs_.end(); ++char_offs_it) {
1498 const char off = char ((char_offs_it->second).first_offset);
1503 for (w_to_n_coll_it = w_to_n_coll_.begin();
1504 w_to_n_coll_it != w_to_n_coll_.end(); ++w_to_n_coll_it) {
1505 const char off = char ((w_to_n_coll_it->second).first_offset);
1510 for (n_ce_offs_it = n_ce_offs_.begin();
1511 n_ce_offs_it != n_ce_offs_.end(); ++n_ce_offs_it) {
1512 const char off = char ((n_ce_offs_it->second).first_offset);
1517 for (w_ce_offs_it = w_ce_offs_.begin();
1518 w_ce_offs_it != w_ce_offs_.end(); ++w_ce_offs_it) {
1519 const char off = char ((w_ce_offs_it->second).first_offset);
1524 for (n_ce_offs_it = n_ce_offs_.begin();
1525 n_ce_offs_it != n_ce_offs_.end(); ++n_ce_offs_it) {
1526 const char off = char ((n_ce_offs_it->second).last_offset);
1531 for (w_ce_offs_it = w_ce_offs_.begin();
1532 w_ce_offs_it != w_ce_offs_.end(); ++w_ce_offs_it) {
1533 const char off = char ((w_ce_offs_it->second).last_offset);
1543void Def::init_coll_map() {
1545 rw_cmap_iter rw_cmap_pos;
1548 for (rw_cmap_pos = charmap_.
get_rw_cmap().begin();
1551 coll_map_.insert (std::make_pair (rw_cmap_pos->first,
tmp));
1561void Def::preprocess_collate ()
1563 int nesting_level = 0;
1569 switch (next.
token) {
1574 if (nesting_level == 0)
1581 "wrong section name in END directive\n");
1588 "expected string following \"copy\" directive\n");
1624 "symbolic name expected following "
1625 "collating-element\n");
1632 "illegal collating-element expression\n");
1637 ce_def_list.push_back (next);
1638 ce_list_.push_back (std::make_pair(sym,ce_def_list));
1641 ce_def_list.push_back (next);
1644 ce_list_.push_back (std::make_pair(sym,ce_def_list));
1647 "illegal collating-element expression\n");
1654 "symbolic name expected following "
1655 "collating-symbol\n");
1656 cs_list_.push_back (next);
1662 "expecting script name, got %s\n",
1663 next.
name.c_str ());
1664 script_list_.push_back(next);
1667 sym_list_.push_back (next);
1674 preprocess_reorder ();
1678 preprocess_reorder_section ();
1691void Def::preprocess_order ()
1696 section_list_.push_back (collate_section_t());
1697 collate_section_t& section = section_list_.back ();
1709 section.order.push_back (next);
1717 if (section.name ==
"")
1718 section.
name =
"unnamed";
1721 "processing %s order\n", section.name.c_str ());
1728 switch (next.
token) {
1731 "unexpected END directive while "
1732 "parsing collate section\n");
1742 section.entries.push_back (
1748 entry.second.push_back (next);
1768void Def::preprocess_reorder ()
1778 "expecting symbolic name, got %s\n",
1779 next.
name.c_str ());
1800 entry.second.push_back (next);
1805 entries_list.push_back (entry);
1808 if (!entries_list.empty ())
1809 insert_entries (sym, entries_list);
1810 entries_list.clear ();
1815 if (!entries_list.empty ())
1816 insert_entries (sym, entries_list);
1820 "unexpected token : %s in a reorder block\n",
1821 next.
name.c_str ());
1828void Def::preprocess_reorder_section ()
1843 switch (next.
token) {
1852 "expecting section name, got %s\n",
1853 next.
name.c_str ());
1856 std::list<collate_section_t>::iterator beg =
1857 section_list_.begin ();
1858 std::list<collate_section_t>::iterator
end =
1859 section_list_.end ();
1860 std::list<collate_section_t>::iterator ref_it, mov_it;
1862 ref_it->name != sym.name && ref_it !=
end;
1865 mov_it->name != next.
name && mov_it !=
end;
1868 if (ref_it == end || mov_it == end)
1870 "missing sections %s %s requested\n",
1871 sym.name.c_str (), next.
name.c_str ());
1874 section_list_.splice (++ref_it, section_list_,
1883 "unexpected token : %s in a "
1884 "reorder section block\n",
1885 next.
name.c_str ());
1894void Def::list_collate ()
1897 token_list_t::iterator script_it = script_list_.begin ();
1898 while (script_it != script_list_.end ()) {
1899 std::cout <<
"script " << (script_it++)->
name <<
'\n';
1904 token_list_t::iterator cs_it = cs_list_.begin ();
1905 while (cs_it != cs_list_.end ()) {
1906 std::cout <<
"collating-symbol " << (cs_it++)->
name <<
'\n';
1911 std::list<collate_elem_t>::iterator ce_it = ce_list_.begin ();
1912 while (ce_it != ce_list_.end ()) {
1913 std::cout <<
"collating-element " << ce_it->first.name
1915 token_list_t::iterator ce_def_it = ce_it->second.begin ();
1916 for (;ce_def_it != ce_it->second.end (); ce_def_it++) {
1917 std::cout << ce_def_it->name <<
";";
1924 token_list_t::iterator sym_it = sym_list_.begin ();
1925 while (sym_it != sym_list_.end ()) {
1926 std::cout << (sym_it++)->
name <<
'\n';
1931 std::list<collate_section_t>::iterator sc_it =
1932 section_list_.begin ();
1933 while (sc_it != section_list_.end ()) {
1935 std::cout <<
"order_start ";
1936 if (sc_it->name !=
"unnamed")
1937 std::cout << sc_it->name <<
";";
1939 token_list_t::iterator it = sc_it->order.begin ();
1940 while (it != sc_it->order.end ())
1941 std::cout << (it++)->name <<
";";
1944 std::list<collate_entry_t>::iterator e_it =
1945 sc_it->entries.begin ();
1946 while (e_it != sc_it->entries.end ()) {
1947 std::cout << e_it->first.name <<
" ";
1948 token_list_t::iterator w_it = e_it->second.begin ();
1949 while (w_it != e_it->second.end ())
1950 std::cout << (w_it++)->name <<
";";
1957 std::cout <<
'\n' <<
"order_end\n";
1965bool Def::insert_entries (token_t&
s, collate_entry_list_t&
e)
1968 collate_entry_list_t::iterator r_it =
e.begin ();
1969 for (; r_it !=
e.end (); ++r_it)
1970 remove_entry (*r_it);
1974 token_list_t::iterator it = sym_list_.begin ();
1975 for (; it != sym_list_.end (); ++it) {
1976 if (it->name !=
s.name)
1982 if (!
e.begin ()->second.empty ()) {
1984 "requested reorder-after: reference "
1985 "symbol %s was found outside section boundaries "
1986 "and the objects to be reordered are collation "
1987 "definitions\n",
s.name.c_str ());
1991 collate_entry_list_t::iterator e_it =
e.begin ();
1992 for (; e_it !=
e.end (); ++e_it)
1993 it = sym_list_.insert (++it, e_it->first);
1999 std::list<collate_section_t>::iterator sect_it = section_list_.begin ();
2000 while (sect_it != section_list_.end ()) {
2001 collate_entry_list_t::iterator e_it = sect_it->entries.begin ();
2002 for (; e_it != sect_it->entries.end (); ++e_it) {
2003 if (e_it->first.name !=
s.name)
2007 sect_it->entries.insert (++e_it,
e.begin (),
e.end ());
2014 "requested reorder-after: reference "
2015 "symbol %s was not found \n",
s.name.c_str ());
2022void Def::remove_entry (collate_entry_t&
e)
2025 if (
e.second.empty ()) {
2026 token_list_t::iterator it = sym_list_.begin ();
2027 for (; it != sym_list_.end (); ++it) {
2028 if (it->name !=
e.first.name)
2031 sym_list_.erase (it);
2037 std::list<collate_section_t>::iterator sect_it = section_list_.begin ();
2038 while (sect_it != section_list_.end ()) {
2039 std::list<collate_entry_t>::iterator e_it = sect_it->entries.begin ();
2040 for (; e_it != sect_it->entries.end (); ++e_it) {
2041 if (e_it->first.name !=
e.first.name)
2044 sect_it->entries.erase (e_it);
2054bool Def::get_weight ( token_t&
w,
2058 const std::map<std::string, wchar_t>& w_cmap = charmap_.
get_w_cmap ();
2061 weights[weight_num].size = 1;
2062 ce_map_iter ce_map_it;
2064 w_cmap_iter w_cmap_pos = w_cmap.find (
w.name);
2065 if (w_cmap_pos != w_cmap.end()){
2066 coll_map_iter coll_map_pos = coll_map_.find(w_cmap_pos->second);
2068 if (coll_map_pos->second.coll_val ==
UINT_MAX)
2070 &
w,
"symbolic name %s "
2071 "used as weight before being assigned a "
2072 "collation value\n",
w.name.c_str());
2075 weights[weight_num].weight[0] = coll_map_pos->second.coll_val;
2077 else if ((ce_map_it = ce_map_.find (
w.name))
2079 weights[weight_num].weight[0] = ce_map_it->second.coll_val;
2081 cs_map_iter cs_it = cs_map_.find (
w.name);
2082 if (cs_it == cs_map_.end ())
2084 &
w,
"symbolic name %s not found\n",
2087 weights[weight_num].weight[0] = cs_it->second;
2092 const char* next_val =
2093 std::strchr (
w.name.c_str (), scanner_.
escape_char ());
2097 const char* next_wt = std::strchr (
w.name.c_str (),
';');
2099 while (weight_num < collate_out_.num_weights) {
2103 for (
c = 0; *next_val && (!next_wt || next_val < next_wt); ++
c) {
2105 const char*
end = 0;
2107 weights [weight_num].weight [
c] =
2115 weights [weight_num++].size =
c;
2118 next_wt = std::strchr (next_val,
';');
2125 weights[weight_num].size = 1;
2126 weights[weight_num].weight[0] = 0;
2132 const std::string
tmp (
w.name.substr (1,
w.name.size() - 2));
2135 unsigned char k = 0;
2138 std::string::const_iterator it =
tmp.begin ();
2142 while (it !=
tmp.end ()) {
2148 while (*it !=
'>') {
2159 w_cmap_iter w_cm_pos = w_cmap.find(wsym);
2160 cs_map_iter cs_it = cs_map_.find (wsym);
2161 ce_map_iter ce_it = ce_map_.find (wsym);
2163 if (w_cm_pos != w_cmap.end()) {
2166 coll_map_iter coll_it = coll_map_.find(w_cm_pos->second);
2167 if (coll_it == coll_map_.end())
2169 "weight %s not defined\n",
2171 if (coll_it->second.coll_val ==
UINT_MAX)
2173 &
w,
"symbolic name %s "
2174 "used as weight before being assigned a "
2175 "collation value\n", wsym.c_str());
2177 weights[weight_num].weight[
k++] = coll_it->second.coll_val;
2179 else if (ce_it != ce_map_.end()) {
2181 weights[weight_num].weight[
k++] = ce_it->second.coll_val;
2183 else if (cs_it != cs_map_.end()) {
2185 weights[weight_num].weight[
k++] = cs_it->second;
2190 "symbolic name %s not found\n",
2194 else if (*it == escape) {
2197 const char*
const beg =
tmp.c_str () + (it -
tmp.begin ());
2198 const char*
end = 0;
2200 weights [weight_num].weight [
k++] =
2211 "illegal string content as a weight");
2214 weights[weight_num].size =
k;
2215 if (
k > collate_out_.longest_weight)
2216 collate_out_.longest_weight =
k;
2225 "illegal token %s found in collation definition\n",
2235void Def::gen_valid_coll_wchar_set () {
2237 if (!valid_coll_wchar_set_.empty())
2240 create_wchar_utf8_table();
2242 for (coll_map_iter coll_it = coll_map_.begin();
2243 coll_it != coll_map_.end(); ++coll_it) {
2244 if (coll_it->second.offset !=
UINT_MAX
2245 || !collate_out_.undefined_optimization){
2247 std::string valid = utf8_encode (coll_it->first);
2248 valid = valid.substr (0, valid.size() - 1);
2250 while (valid.size() > 0){
2251 valid_coll_wchar_set_.insert (valid);
2252 valid = valid.substr(0, valid.size() - 1);
const std::list< std::string > & get_symnames_list() const
const std::map< wchar_t, std::string > & get_rmb_cmap() const
const std::string & get_code_set_name() const
std::string get_charmap_name() const
const std::map< wchar_t, std::string > & get_rw_cmap() const
const std::map< std::string, wchar_t > & get_w_cmap() const
const std::map< std::string, wchar_t > & get_mb_cmap() const
wchar_t increment_wchar(wchar_t) const
std::pair< token_t, token_list_t > collate_entry_t
void write_collate(std::string dir_name)
std::list< collate_entry_t > collate_entry_list_t
friend struct collate_info_t
std::list< token_t > token_list_t
void open(std::string, char='#', char='\\')
unsigned long convert_escape(const char *, const char **=0, bool=false) const
@ tok_reorder_section_end
std::string strip_quotes(const std::string &str)
bool issue_diag(int type, bool, const Scanner::token_t *token, const char *fmt,...)
StringType escape(StringType s)
string escaping as described in RFC 6901 (Sect. 4)
std::string get_pathname(const std::string &fname, const std::string &other)
std::map< std::string, wchar_t >::const_iterator n_cmap_citer2