]>
Commit | Line | Data |
---|---|---|
0f15e632 | 1 | /* |
262a0e14 | 2 | * $Id$ |
0f15e632 | 3 | * |
4 | * DEBUG: section 67 String | |
30abd221 | 5 | * AUTHOR: Duane Wessels |
0f15e632 | 6 | * |
7 | * SQUID Web Proxy Cache http://www.squid-cache.org/ | |
8 | * ---------------------------------------------------------- | |
9 | * | |
10 | * Squid is the result of efforts by numerous individuals from | |
11 | * the Internet community; see the CONTRIBUTORS file for full | |
12 | * details. Many organizations have provided support for Squid's | |
13 | * development; see the SPONSORS file for full details. Squid is | |
14 | * Copyrighted (C) 2001 by the Regents of the University of | |
15 | * California; see the COPYRIGHT file for full details. Squid | |
16 | * incorporates software developed and/or copyrighted by other | |
17 | * sources; see the CREDITS file for full details. | |
18 | * | |
19 | * This program is free software; you can redistribute it and/or modify | |
20 | * it under the terms of the GNU General Public License as published by | |
21 | * the Free Software Foundation; either version 2 of the License, or | |
22 | * (at your option) any later version. | |
26ac0430 | 23 | * |
0f15e632 | 24 | * This program is distributed in the hope that it will be useful, |
25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
27 | * GNU General Public License for more details. | |
26ac0430 | 28 | * |
0f15e632 | 29 | * You should have received a copy of the GNU General Public License |
30 | * along with this program; if not, write to the Free Software | |
31 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. | |
32 | * | |
33 | */ | |
34 | ||
35 | #ifndef SQUID_STRING_H | |
36 | #define SQUID_STRING_H | |
37 | ||
7b270d4c | 38 | #include "config.h" |
9b558d8a FC |
39 | #include "TextException.h" |
40 | ||
60745f24 | 41 | |
e1f7507e AJ |
42 | /** todo checks to wrap this include properly */ |
43 | #include <ostream> | |
44 | ||
45 | ||
30abd221 | 46 | #define DEBUGSTRINGS 0 |
47 | #if DEBUGSTRINGS | |
48 | #include "splay.h" | |
49 | ||
50 | class String; | |
51 | ||
52 | class StringRegistry | |
53 | { | |
54 | ||
55 | public: | |
56 | static StringRegistry &Instance(); | |
57 | ||
58 | void add | |
26ac0430 | 59 | (String const *); |
30abd221 | 60 | |
6852be71 | 61 | StringRegistry(); |
30abd221 | 62 | |
63 | void remove | |
26ac0430 | 64 | (String const *); |
30abd221 | 65 | |
66 | private: | |
67 | static OBJH Stat; | |
0353e724 | 68 | |
30abd221 | 69 | static StringRegistry Instance_; |
0353e724 | 70 | |
30abd221 | 71 | static SplayNode<String const *>::SPLAYWALKEE Stater; |
0353e724 | 72 | |
30abd221 | 73 | Splay<String const *> entries; |
0353e724 | 74 | |
30abd221 | 75 | bool registered; |
0353e724 | 76 | |
30abd221 | 77 | }; |
0353e724 | 78 | |
30abd221 | 79 | class StoreEntry; |
80 | #endif | |
0353e724 | 81 | |
30abd221 | 82 | class String |
83 | { | |
0353e724 | 84 | |
30abd221 | 85 | public: |
86 | _SQUID_INLINE_ String(); | |
87 | String (char const *); | |
88 | String (String const &); | |
89 | ~String(); | |
90 | ||
a7a42b14 FC |
91 | typedef unsigned int size_type; //storage size intentionally unspecified |
92 | ||
30abd221 | 93 | String &operator =(char const *); |
94 | String &operator =(String const &); | |
95 | bool operator ==(String const &) const; | |
96 | bool operator !=(String const &) const; | |
97 | ||
3db44fdf | 98 | /** |
99 | * Retrieve a single character in the string. | |
100 | \param pos Position of character to retrieve. | |
101 | */ | |
4ce0e99b | 102 | _SQUID_INLINE_ char operator [](unsigned int pos) const; |
3db44fdf | 103 | |
a7a42b14 | 104 | _SQUID_INLINE_ size_type size() const; |
9b558d8a FC |
105 | /// variant of size() suited to be used for printf-alikes. |
106 | /// throws when size() > MAXINT | |
107 | _SQUID_INLINE_ int psize() const; | |
99524de7 FC |
108 | _SQUID_INLINE_ char const * unsafeBuf() const; |
109 | ||
110 | /** | |
111 | * \retval true the String has some contents | |
112 | */ | |
113 | _SQUID_INLINE_ bool defined() const; | |
114 | /** | |
115 | * \retval true the String does not hold any contents | |
116 | */ | |
117 | _SQUID_INLINE_ bool undefined() const; | |
118 | /** | |
119 | * Returns a raw pointer to the underlying backing store. The caller has been | |
120 | * verified not to make any assumptions about null-termination | |
121 | */ | |
122 | _SQUID_INLINE_ char const * rawBuf() const; | |
123 | /** | |
124 | * Returns a raw pointer to the underlying backing store. | |
125 | * The caller requires it to be null-terminated. | |
126 | */ | |
127 | _SQUID_INLINE_ char const * termedBuf() const; | |
e7e1bf60 | 128 | void limitInit(const char *str, int len); // TODO: rename to assign() |
30abd221 | 129 | void clean(); |
130 | void reset(char const *str); | |
131 | void append(char const *buf, int len); | |
132 | void append(char const *buf); | |
133 | void append(char const); | |
134 | void append (String const &); | |
135 | void absorb(String &old); | |
136 | _SQUID_INLINE_ const char * pos(char const *) const; | |
137 | _SQUID_INLINE_ const char * pos(char const ch) const; | |
b4f2886c FC |
138 | ///offset from string start of the first occurrence of ch |
139 | /// returns std::string::npos if ch is not found | |
a7a42b14 | 140 | _SQUID_INLINE_ size_type find(char const ch) const; |
30abd221 | 141 | _SQUID_INLINE_ const char * rpos(char const ch) const; |
a7a42b14 | 142 | _SQUID_INLINE_ size_type rfind(char const ch) const; |
30abd221 | 143 | _SQUID_INLINE_ int cmp (char const *) const; |
a7a42b14 | 144 | _SQUID_INLINE_ int cmp (char const *, size_type count) const; |
30abd221 | 145 | _SQUID_INLINE_ int cmp (String const &) const; |
146 | _SQUID_INLINE_ int caseCmp (char const *) const; | |
a7a42b14 | 147 | _SQUID_INLINE_ int caseCmp (char const *, size_type count) const; |
9d7a89a5 | 148 | _SQUID_INLINE_ int caseCmp (String const &) const; |
30abd221 | 149 | |
a7a42b14 | 150 | String substr(size_type from, size_type to) const; |
9b558d8a | 151 | |
3db44fdf | 152 | /** \deprecated Use assignment to [] position instead. |
153 | * ie str[newLength] = '\0'; | |
154 | */ | |
a7a42b14 | 155 | _SQUID_INLINE_ void cut(size_type newLength); |
30abd221 | 156 | |
30abd221 | 157 | |
158 | #if DEBUGSTRINGS | |
159 | ||
160 | void stat (StoreEntry *) const; | |
161 | ||
162 | #endif | |
163 | ||
e7e1bf60 | 164 | |
165 | ||
30abd221 | 166 | private: |
e7e1bf60 | 167 | void allocAndFill(const char *str, int len); |
a7a42b14 FC |
168 | void allocBuffer(size_type sz); |
169 | void setBuffer(char *buf, size_type sz); | |
e7e1bf60 | 170 | |
30abd221 | 171 | /* never reference these directly! */ |
a7a42b14 | 172 | size_type size_; /* buffer size; 64K limit */ |
30abd221 | 173 | |
a7a42b14 | 174 | size_type len_; /* current length */ |
30abd221 | 175 | |
176 | char *buf_; | |
9b558d8a FC |
177 | |
178 | _SQUID_INLINE_ void set(char const *loc, char const ch); | |
179 | _SQUID_INLINE_ void cutPointer(char const *loc); | |
180 | ||
30abd221 | 181 | }; |
182 | ||
183 | _SQUID_INLINE_ std::ostream & operator<<(std::ostream& os, String const &aString); | |
184 | ||
185 | #ifdef _USE_INLINE_ | |
186 | #include "String.cci" | |
187 | #endif | |
0f15e632 | 188 | |
189 | #endif /* SQUID_STRING_H */ |