]> git.ipfire.org Git - thirdparty/squid.git/blob - src/SquidString.h
Removed CVS $ markers
[thirdparty/squid.git] / src / SquidString.h
1 /*
2 * DEBUG: section 67 String
3 * AUTHOR: Duane Wessels
4 *
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
7 *
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
30 *
31 */
32
33 #ifndef SQUID_STRING_H
34 #define SQUID_STRING_H
35
36 #if HAVE_OSTREAM
37 #include <ostream>
38 #endif
39
40 /* squid string placeholder (for printf) */
41 #ifndef SQUIDSTRINGPH
42 #define SQUIDSTRINGPH "%.*s"
43 #define SQUIDSTRINGPRINT(s) (s).psize(),(s).rawBuf()
44 #endif /* SQUIDSTRINGPH */
45
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
59 (String const *);
60
61 StringRegistry();
62
63 void remove
64 (String const *);
65
66 private:
67 static OBJH Stat;
68
69 static StringRegistry Instance_;
70
71 static SplayNode<String const *>::SPLAYWALKEE Stater;
72
73 Splay<String const *> entries;
74
75 bool registered;
76
77 };
78
79 class StoreEntry;
80 #endif
81
82 class String
83 {
84
85 public:
86 _SQUID_INLINE_ String();
87 String (char const *);
88 String (String const &);
89 ~String();
90
91 typedef size_t size_type; //storage size intentionally unspecified
92 const static size_type npos = std::string::npos;
93
94 String &operator =(char const *);
95 String &operator =(String const &);
96 bool operator ==(String const &) const;
97 bool operator !=(String const &) const;
98
99 /**
100 * Retrieve a single character in the string.
101 \param pos Position of character to retrieve.
102 */
103 _SQUID_INLINE_ char operator [](unsigned int pos) const;
104
105 _SQUID_INLINE_ size_type size() const;
106 /// variant of size() suited to be used for printf-alikes.
107 /// throws when size() > MAXINT
108 int psize() 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;
128 void limitInit(const char *str, int len); // TODO: rename to assign()
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 const char * pos(char const *aString) const;
137 const char * pos(char const ch) const;
138 ///offset from string start of the first occurrence of ch
139 /// returns String::npos if ch is not found
140 size_type find(char const ch) const;
141 size_type find(char const *aString) const;
142 const char * rpos(char const ch) const;
143 size_type rfind(char const ch) const;
144 _SQUID_INLINE_ int cmp (char const *) const;
145 _SQUID_INLINE_ int cmp (char const *, size_type count) const;
146 _SQUID_INLINE_ int cmp (String const &) const;
147 _SQUID_INLINE_ int caseCmp (char const *) const;
148 _SQUID_INLINE_ int caseCmp (char const *, size_type count) const;
149 _SQUID_INLINE_ int caseCmp (String const &) const;
150
151 String substr(size_type from, size_type to) const;
152
153 _SQUID_INLINE_ void cut(size_type newLength);
154
155 #if DEBUGSTRINGS
156 void stat (StoreEntry *) const;
157 #endif
158
159 private:
160 void allocAndFill(const char *str, int len);
161 void allocBuffer(size_type sz);
162 void setBuffer(char *buf, size_type sz);
163
164 _SQUID_INLINE_ bool nilCmp(bool, bool, int &) const;
165
166 /* never reference these directly! */
167 size_type size_; /* buffer size; 64K limit */
168
169 size_type len_; /* current length */
170
171 char *buf_;
172
173 _SQUID_INLINE_ void set(char const *loc, char const ch);
174 _SQUID_INLINE_ void cutPointer(char const *loc);
175
176 };
177
178 _SQUID_INLINE_ std::ostream & operator<<(std::ostream& os, String const &aString);
179
180 _SQUID_INLINE_ bool operator<(const String &a, const String &b);
181
182 #if _USE_INLINE_
183 #include "String.cci"
184 #endif
185
186 extern const char *checkNullString(const char *p);
187 extern int stringHasWhitespace(const char *);
188 extern int stringHasCntl(const char *);
189 extern char *strwordtok(char *buf, char **t);
190
191 #endif /* SQUID_STRING_H */