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