--- parser3/src/include/pa_dictionary.h 2001/08/01 12:08:39 1.1 +++ parser3/src/include/pa_dictionary.h 2026/04/25 13:38:46 1.26 @@ -1,39 +1,53 @@ /** @file Parser: dictionary class decl. - Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) - - Author: Alexander Petrosyan (http://design.ru/paf) - - $Id: pa_dictionary.h,v 1.1 2001/08/01 12:08:39 parser Exp $ + Copyright (c) 2001-2026 Art. Lebedev Studio (https://www.artlebedev.com) + Authors: Konstantin Morshnev , Alexandr Petrosian */ #ifndef PA_DICTIONARY_H #define PA_DICTIONARY_H -#include "pa_config_includes.h" +#define IDENT_PA_DICTIONARY_H "$Id: pa_dictionary.h,v 1.26 2026/04/25 13:38:46 moko Exp $" + #include "pa_table.h" /// simple dictionary, speding up lookups on contained two columned table -class Dictionary : public Pooled { +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 - void* first_that_starts(const char *src) const; + Subst first_that_begins(const char* str) const; - /// where this table came from, may be NULL. proxy to Table - const String *origin_string() { return table.origin_string(); } +private: + Array substs; -public: +private: + void append_subst(const String* from, const String* to, const char* exception=0); - bool first[0x100]; + int starting_line_of[0x100]; int constructor_line; -private: +public: + size_t count() const { return substs.count(); } - Table& table; + Subst get(size_t index) const { return substs.get(index); } };