Annotation of parser3/src/include/pa_string.h, revision 1.36
1.1 paf 1: /*
1.29 paf 2: Parser
3: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.30 paf 4: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
1.29 paf 5:
1.36 ! paf 6: $Id: pa_string.h,v 1.35 2001/03/14 08:50:01 paf Exp $
1.1 paf 7: */
8:
9: /*
10:
11: String Chunk0
12: ====== ========
1.16 paf 13: head--------------->[ptr, size, ...]
14: append_here-------->[ptr, size, ...]
15: .
16: .
17: [ptr, size, ...]
18: link_row----------->[link to the next chunk]
1.1 paf 19:
20: */
21:
22: #ifndef PA_STRING_H
23: #define PA_STRING_H
24:
1.9 paf 25: #ifdef HAVE_CONFIG_H
1.35 paf 26: # include "pa_config.h"
1.9 paf 27: #endif
28:
1.1 paf 29: #include <stddef.h>
30:
1.15 paf 31: #include "pa_pool.h"
1.4 paf 32: #include "pa_types.h"
33:
1.31 paf 34: #define UNTAINT_TIMES_BIGGER 10
35:
1.9 paf 36: #ifndef NO_STRING_ORIGIN
1.33 paf 37: # define STRING_APPEND_PARAMS \
38: const char *src, size_t size, \
39: bool tainted, \
40: const char *file, uint line
1.27 paf 41: # define APPEND(src, size, file, line) real_append(src, size, false, file, line)
42: # define APPEND_TAINTED(src, size, file, line) real_append(src, size, true, file, line)
1.9 paf 43: #else
1.33 paf 44: # define STRING_APPEND_PARAMS \
45: const char *src, \
46: size_t size, \
47: bool tainted
1.27 paf 48: # define APPEND(src, size, file, line) real_append(src, size, false)
49: # define APPEND_TAINTED(src, size, file, line) real_append(src, size, true)
1.9 paf 50: #endif
1.23 paf 51: #define APPEND_CONST(src) APPEND(src, 0, 0, 0)
1.9 paf 52:
1.15 paf 53: class String : public Pooled {
1.1 paf 54: public:
55: enum {
56: CR_PREALLOCATED_COUNT=5,
57: CR_GROW_PERCENT=60
58: };
59:
1.27 paf 60: enum Untaint_lang {
1.31 paf 61: UNKNOWN=0, // when get by name fails
1.27 paf 62: NO, // clean
63: YES, // tainted, untaint language as assigned later
64: // untaint languages. assigned by ^untaint[lang]{...}
1.36 ! paf 65: PASS_APPEND,
1.28 paf 66: // leave language built into string being appended
67: // just a flag, that value not stored
1.27 paf 68: AS_IS,
1.33 paf 69: TABLE,
1.27 paf 70: SQL,
71: JS,
72: HTML,
73: HTML_TYPO
74: };
75:
1.8 paf 76: public:
77:
1.11 paf 78: String(Pool& apool);
1.14 paf 79: String(const String& src);
80: size_t size() const { return fsize; }
81: int used_rows() const { return fused_rows; }
82: char *cstr() const;
1.9 paf 83: String& real_append(STRING_APPEND_PARAMS);
1.26 paf 84: int cmp (const String& src) const;
85: bool operator < (const String& src) const { return cmp(src)<0; }
86: bool operator > (const String& src) const { return cmp(src)>0; }
87: bool operator <= (const String& src) const { return cmp(src)<=0; }
88: bool operator >= (const String& src) const { return cmp(src)>=0; }
89: bool operator == (const String& src) const {
90: if(size()!=src.size()) // can speed up in trivial case
91: return false;
92: return cmp(src)==0;
93: }
94: bool operator != (const String& src) const { return cmp(src)!=0; }
95:
1.34 paf 96: bool operator == (const char* b_ptr) const;
1.27 paf 97: String& append(const String& src, Untaint_lang lang);
1.8 paf 98:
1.14 paf 99: uint hash_code() const;
1.13 paf 100:
101: const Origin& origin() const { return head.rows[0].item.origin; }
1.36 ! paf 102:
! 103: void change_lang(Untaint_lang lang);
1.8 paf 104:
1.10 paf 105: private:
106:
1.1 paf 107: struct Chunk {
1.6 paf 108: // the number of rows in chunk
1.1 paf 109: int count;
110: union Row {
1.27 paf 111: // fragment
112: struct {
113: const char *ptr; // pointer to the start
114: size_t size; // length
115: Untaint_lang lang; // untaint flag, later untaint language
116: #ifndef NO_STRING_ORIGIN
117: Origin origin; // origin
118: #endif
1.1 paf 119: } item;
120: Chunk *link; // link to the next chunk in chain
1.2 paf 121: } rows[CR_PREALLOCATED_COUNT];
1.1 paf 122: // next rows are here
123: Chunk *preallocated_link;
124: }
125: head; // the head chunk of the chunk chain
126:
127: // next append would write to this record
128: Chunk::Row *append_here;
129:
130: // the address of place where lies address
131: // of the link to the next chunk to allocate
132: Chunk::Row *link_row;
133:
1.5 paf 134: private:
1.25 paf 135: // last chunk
136: Chunk *last_chunk;
1.5 paf 137:
138: // string size
139: size_t fsize;
140:
141: // used rows in all chunks
142: int fused_rows;
143:
144: private:
1.1 paf 145:
146: bool chunk_is_full() {
147: return append_here == link_row;
148: }
149: void expand();
1.27 paf 150: void set_lang(Chunk::Row *row, Untaint_lang lang, size_t size);
1.7 paf 151:
152: private: //disabled
153:
1.12 paf 154: String& operator = (const String&) { return *this; }
1.7 paf 155:
1.1 paf 156: };
157:
158: #endif
E-mail: