Annotation of parser3/src/include/pa_string.h, revision 1.40
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.40 ! paf 6: $Id: pa_string.h,v 1.39 2001/03/18 17:18:35 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.40 ! paf 65: PASS_APPENDED,
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.40 ! paf 69: HEADER,
1.38 paf 70: URI,
1.33 paf 71: TABLE,
1.27 paf 72: SQL,
73: JS,
74: HTML,
75: HTML_TYPO
76: };
77:
1.8 paf 78: public:
79:
1.37 paf 80: String(Pool& apool, const char *src=0, bool tainted=false);
1.14 paf 81: String(const String& src);
82: size_t size() const { return fsize; }
83: int used_rows() const { return fused_rows; }
84: char *cstr() const;
1.9 paf 85: String& real_append(STRING_APPEND_PARAMS);
1.26 paf 86: int cmp (const String& src) const;
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 { return cmp(src)<=0; }
90: bool operator >= (const String& src) const { return cmp(src)>=0; }
91: bool operator == (const String& src) const {
92: if(size()!=src.size()) // can speed up in trivial case
93: return false;
94: return cmp(src)==0;
95: }
96: bool operator != (const String& src) const { return cmp(src)!=0; }
97:
1.34 paf 98: bool operator == (const char* b_ptr) const;
1.39 paf 99: String& append(const String& src, Untaint_lang lang, bool forced=false);
1.8 paf 100:
1.14 paf 101: uint hash_code() const;
1.13 paf 102:
103: const Origin& origin() const { return head.rows[0].item.origin; }
1.36 paf 104:
1.39 paf 105: // void change_lang(Untaint_lang lang);
1.8 paf 106:
1.10 paf 107: private:
108:
1.1 paf 109: struct Chunk {
1.6 paf 110: // the number of rows in chunk
1.1 paf 111: int count;
112: union Row {
1.27 paf 113: // fragment
114: struct {
115: const char *ptr; // pointer to the start
116: size_t size; // length
117: Untaint_lang lang; // untaint flag, later untaint language
118: #ifndef NO_STRING_ORIGIN
119: Origin origin; // origin
120: #endif
1.1 paf 121: } item;
122: Chunk *link; // link to the next chunk in chain
1.2 paf 123: } rows[CR_PREALLOCATED_COUNT];
1.1 paf 124: // next rows are here
125: Chunk *preallocated_link;
126: }
127: head; // the head chunk of the chunk chain
128:
129: // next append would write to this record
130: Chunk::Row *append_here;
131:
132: // the address of place where lies address
133: // of the link to the next chunk to allocate
134: Chunk::Row *link_row;
135:
1.5 paf 136: private:
1.25 paf 137: // last chunk
138: Chunk *last_chunk;
1.5 paf 139:
140: // string size
141: size_t fsize;
142:
143: // used rows in all chunks
144: int fused_rows;
145:
146: private:
1.1 paf 147:
148: bool chunk_is_full() {
149: return append_here == link_row;
150: }
151: void expand();
1.39 paf 152: void set_lang(Chunk::Row *row, Untaint_lang lang, bool forced, size_t size);
1.7 paf 153:
154: private: //disabled
155:
1.12 paf 156: String& operator = (const String&) { return *this; }
1.7 paf 157:
1.1 paf 158: };
159:
160: #endif
E-mail: