source: trunk/src/symtab.h @ 174

Last change on this file since 174 was 174, checked in by lindanl, 11 years ago

Nmtokens.

File size: 2.1 KB
Line 
1/*  symtab.h - XML Symbol Table Module
2    Copyright (c) 2008 Robert D. Cameron
3    Licensed to the public under the Open Software License 3.0.
4    Licensed to International Characters, Inc., under the Academic
5    Free License 3.0.
6*/
7
8#ifndef SYMTAB_H
9#define SYMTAB_H
10
11#include "namechars.h"
12
13struct eqstr
14{
15  bool operator()(const char* s1, const char* s2) const
16  {
17    return strcmp(s1, s2) == 0;
18  }
19};
20
21struct Name_Data
22{
23        char * name_string;
24        int        lgth;
25};
26       
27char * predefined[] = {"lt", "gt", "amp", "quot", "apos"};
28
29/*  A StringPool object provides managed storage for strings.
30   It can grow to accommodate as many strings as desired, subject
31   to space availability.  It is implemented as a vector of
32   pool buffers.  Initially a single buffer of size initial_capacity
33   is allocated.  Strings are inserted into this area until insufficient
34   space remains, at which point a new buffer is allocated for
35   subsequent insertions.  */
36
37class StringPool {
38public:
39       StringPool();
40       ~StringPool();
41       char * Insert(char * s, int lgth);
42private:
43       int buffer_capacity;
44       int buffer_space_used;
45       vector<char *> pool_buffers;
46};
47
48class Symbol_Table {
49public:
50        Symbol_Table();
51
52
53        int Insert_Name(char * name, int lgth);
54        int ASCII_Lookup_or_Insert_Name(char * name, int lgth); 
55        int UTF8_Lookup_or_Insert_Name(char * name, int lgth);
56        int ASCII_Lookup_or_Insert_Nmtoken(char * name, int lgth);     
57        int UTF8_Lookup_or_Insert_Nmtoken(char * name, int lgth);
58
59        char * Get_UTF8_name(int nameID);
60        int Get_UTF8_lgth(int nameID);
61
62        char * Get_UTF8_nmtoken(int nmtokenID);
63        int Get_UTF8_nmtoken_lgth(int nmtokenID);
64       
65        char * ReserveSymbolSpace(int u8_lgth);
66        int LookupOrInsertReserved();
67        int LookupOrInsertReserved_nmtoken();
68       
69        XML_version version;
70        vector<Name_Data> UTF8NameTable;
71        vector<Name_Data> UTF8NmtokenTable;
72private:
73        hash_map<const char *, int, hash<const char *>, eqstr > UTF8NameMap;
74        hash_map<const char *, int, hash<const char *>, eqstr > UTF8NmtokenMap;
75        int globalNameCount;
76        int globalNmtokenCount;
77//      vector<char *> UTF8NameTable;
78
79        char * reserved;
80        int reserved_lgth;
81        StringPool * pool;
82};
83
84
85
86#endif
Note: See TracBrowser for help on using the repository browser.