--- parser3/src/main/pa_dictionary.C 2001/08/28 09:27:42 1.4 +++ parser3/src/main/pa_dictionary.C 2002/08/01 11:41:18 1.16 @@ -1,25 +1,25 @@ /** @file Parser: dictionary class impl. - Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) - - Author: Alexander Petrosyan (http://design.ru/paf) + Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) + Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char *RCSId="$Id: pa_dictionary.C,v 1.4 2001/08/28 09:27:42 parser Exp $"; + +static const char* IDENT_DICTIONARY_C="$Date: 2002/08/01 11:41:18 $"; #include "pa_dictionary.h" #include "pa_exception.h" -static void add_first(Array::Item *value, void *info) { +void Dictionary::add_first(Array::Item *value, void *info) { Dictionary& self=*static_cast(info); Array *row=static_cast(value); // get a=>b values const String& a=*row->get_string(0); const String& b=*row->get_string(1); // empty 'a' check - if(a.size()==0) { + if(a.is_empty()) { Pool& pool=self.pool(); - PTHROW(0, 0, + throw Exception("parser.runtime", &a, "dictionary table 'from' column elements must not be empty"); } @@ -27,13 +27,12 @@ static void add_first(Array::Item *value if(!self.starting_line_of[c]) self.starting_line_of[c]=self.constructor_line; - double ratio=b.size()/a.size(); + double ratio=((double)b.size())/a.size(); if(ratio>self.fmax_ratio) self.fmax_ratio=ratio; self.constructor_line++; } - Dictionary::Dictionary(Table& atable, double amin_ratio) : Pooled(atable.pool()), table(atable), fmax_ratio(amin_ratio) { @@ -47,7 +46,7 @@ Dictionary::Dictionary(Table& atable, do #ifndef DOXYGEN struct First_that_starts_info { int line; - const char *src; + const char *src; size_t src_size; }; #endif static void *starts(Array::Item *value, void *info) { @@ -60,17 +59,18 @@ static void *starts(Array::Item *value, Array *row=static_cast(value); int partial; - row->get_string(0)->cmp(partial, i.src); + row->get_string(0)->cmp(partial, i.src, i.src_size); return ( partial==0 || // full match partial==1) // typo left column starts 'src' ?value:0; } -void* Dictionary::first_that_starts(const char *src) const { +void* Dictionary::first_that_starts(const char *src, size_t src_size) const { First_that_starts_info info; if(info.line=starting_line_of[(unsigned char)*src]) { info.src=src; + info.src_size=src_size; return table.first_that(starts, &info); } else return 0;