|
|
| version 1.17.2.6.2.2, 2003/03/20 09:41:46 | version 1.17.2.6.2.3, 2003/03/20 11:11:55 |
|---|---|
| Line 13 static const char* IDENT_DICTIONARY_C="$ | Line 13 static const char* IDENT_DICTIONARY_C="$ |
| // could not make this static: gcc complains "prev decl was extern" | // could not make this static: gcc complains "prev decl was extern" |
| void pa_dictionary_add_first(Table::element_type row, Dictionary* self) { | void pa_dictionary_add_first(Table::element_type row, Dictionary* self) { |
| // get a=>b values | // get a=>b values |
| const String& a=row->get(0); | const String* a=row->get(0); |
| const String& b=row->get(1); | |
| // empty 'a' check | // empty 'a' check |
| if(a->is_empty()) { | if(!*a) { |
| throw Exception("parser.runtime", | throw Exception("parser.runtime", |
| a, | a, |
| "dictionary table 'from' column elements must not be empty"); | "dictionary table 'from' column elements must not be empty"); |
| Line 25 void pa_dictionary_add_first(Table::elem | Line 24 void pa_dictionary_add_first(Table::elem |
| if(!self->starting_line_of[c]) | if(!self->starting_line_of[c]) |
| self->starting_line_of[c]=self->constructor_line; | self->starting_line_of[c]=self->constructor_line; |
| double ratio=((double)b->size())/a->size(); | |
| if(ratio>self->fmax_ratio) | |
| self->fmax_ratio=ratio; | |
| self->constructor_line++; | self->constructor_line++; |
| } | } |
| Dictionary::Dictionary(Table* atable, double amin_ratio): | Dictionary::Dictionary(Table& atable): table(atable) { |
| table(atable), | |
| fmax_ratio(amin_ratio) { | |
| // clear starting_lines | |
| memset(starting_line_of, 0, sizeof(starting_line_of)); | |
| // grab first letters of first column of a table | // grab first letters of first column of a table |
| constructor_line=1; table->for_each(pa_dictionary_add_first, this); | constructor_line=1; table.for_each(pa_dictionary_add_first, this); |
| } | } |
| #ifndef DOXYGEN | #ifndef DOXYGEN |
| struct First_that_starts_info { | struct First_that_starts_info { |
| int line; | int line; |
| const char* src; size_t src_size; | const char* str; |
| }; | }; |
| #endif | #endif |
| static bool starts(Table::element_type row, First_that_starts_info* info) { | static bool starts(Table::element_type row, First_that_starts_info* info) { |
| Line 54 static bool starts(Table::element_type r | Line 44 static bool starts(Table::element_type r |
| return 0; | return 0; |
| } | } |
| int partial; | return row->get(0)->this_starts(info->str); |
| row->get(0)->cmp(partial, info->src, info->src_size); | |
| return ( | |
| partial==0 || // full match | |
| partial==1); // typo left column starts 'src' | |
| } | } |
| Table::element_type Dictionary::first_that_starts(const char* str) const { | |
| Table::element_type Dictionary::first_that_starts(const char* src) const { | |
| First_that_starts_info info; | First_that_starts_info info; |
| if(info.line=starting_line_of[(unsigned char)*src]) { | if(info.line=starting_line_of[(unsigned char)*str]) { |
| info.src=src; | info.str=str; |
| info.src_size=src_size; | return table.first_that(starts, &info); |
| return table->first_that(starts, &info); | |
| } else | } else |
| return Table::element_type(0); | return Table::element_type(0); |
| } | } |