--- parser3/src/include/pa_dictionary.h 2003/07/24 11:31:21 1.14 +++ parser3/src/include/pa_dictionary.h 2017/02/07 22:00:33 1.22 @@ -1,14 +1,14 @@ /** @file Parser: dictionary class decl. - Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001-2017 Art. Lebedev Studio (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ #ifndef PA_DICTIONARY_H #define PA_DICTIONARY_H -static const char* IDENT_DICTIONARY_H="$Date: 2003/07/24 11:31:21 $"; +#define IDENT_PA_DICTIONARY_H "$Id: pa_dictionary.h,v 1.22 2017/02/07 22:00:33 moko Exp $" #include "pa_table.h" @@ -16,20 +16,39 @@ static const char* IDENT_DICTIONARY_H="$ class Dictionary: public PA_Object { public: + struct Subst { + const char *from; size_t from_length; + const String* to; + + Subst(int): from(0) {} + Subst(const char* afrom, const String* ato): from(afrom), to(ato) { + from_length=strlen(afrom); + } + operator bool() { return from!=0; } + }; + /// construct wrapper, grabbing first letters of first column into @b first Dictionary(Table& atable); + /// construct simple dictionary within a single pair only + Dictionary(const String& from, const String& to); + /// find first row that contains string in first column which starts @b src - Table::element_type first_that_begins(const char* str) const; + Subst first_that_begins(const char* str) const; private: - - Table& table; + Array substs; private: - friend void pa_dictionary_add_first(Table::element_type row, Dictionary* self); + void append_subst(const String* from, const String* to, const char* exception=0); int starting_line_of[0x100]; int constructor_line; + +public: + size_t count() const { return substs.count(); } + + Subst get(size_t index) const { return substs.get(index); } + }; #endif