Annotation of parser3/src/main/pa_dictionary.C, revision 1.2
1.1 parser 1: /** @file
2: Parser: dictionary class impl.
3:
4: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
5:
6: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
7: */
1.2 ! parser 8: static const char *RCSId="$Id: pa_dictionary.C,v 1.1 2001/08/01 12:08:40 parser Exp $";
1.1 parser 9:
10: #include "pa_dictionary.h"
11:
12:
13: static void add_first(Array::Item *value, void *info) {
14: Dictionary& self=*static_cast<Dictionary *>(info);
15: self.first[(unsigned char)static_cast<Array *>(value)->get_string(0)->first_char()]=true;
16: }
17:
18: Dictionary::Dictionary(Table& atable) : Pooled(atable.pool()), table(atable) {
19: // clear firsts
1.2 ! parser 20: memset(first, 0, sizeof(first));
1.1 parser 21: // grab first letters of first column of a table
22: table.for_each(add_first, this);
23: }
24:
25: static bool starts(Array::Item *value, const void *info) {
26: Array *row=static_cast<Array *>(value);
27: const char *src=static_cast<const char *>(info);
28:
29: int partial;
30: row->get_string(0)->cmp(partial, src);
31: return
32: partial==0 || // full match
33: partial==1; // typo left column starts 'src'
34: }
35:
36: void* Dictionary::first_that_starts(const char *src) const {
37: if(first[(unsigned char)*src])
38: return table.first_that(starts, src);
39: else
40: return 0;
41: }
E-mail: