]> git.ipfire.org Git - thirdparty/squid.git/blame - src/SquidString.h
Moved some prototypes to tools.h
[thirdparty/squid.git] / src / SquidString.h
CommitLineData
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
27e059d4 38#if HAVE_OSTREAM
e1f7507e 39#include <ostream>
27e059d4 40#endif
e1f7507e 41
bb790702
FC
42/* squid string placeholder (for printf) */
43#ifndef SQUIDSTRINGPH
44#define SQUIDSTRINGPH "%.*s"
b716b3d4 45#define SQUIDSTRINGPRINT(s) (s).psize(),(s).rawBuf()
bb790702
FC
46#endif /* SQUIDSTRINGPH */
47
30abd221 48#define DEBUGSTRINGS 0
49#if DEBUGSTRINGS
50#include "splay.h"
51
52class String;
53
54class StringRegistry
55{
56
57public:
58 static StringRegistry &Instance();
59
60 void add
26ac0430 61 (String const *);
30abd221 62
6852be71 63 StringRegistry();
30abd221 64
65 void remove
26ac0430 66 (String const *);
30abd221 67
68private:
69 static OBJH Stat;
0353e724 70
30abd221 71 static StringRegistry Instance_;
0353e724 72
30abd221 73 static SplayNode<String const *>::SPLAYWALKEE Stater;
0353e724 74
30abd221 75 Splay<String const *> entries;
0353e724 76
30abd221 77 bool registered;
0353e724 78
30abd221 79};
0353e724 80
30abd221 81class StoreEntry;
82#endif
0353e724 83
30abd221 84class String
85{
0353e724 86
30abd221 87public:
88 _SQUID_INLINE_ String();
89 String (char const *);
90 String (String const &);
91 ~String();
92
b4197865 93 typedef size_t size_type; //storage size intentionally unspecified
2c1fd837 94 const static size_type npos = std::string::npos;
a7a42b14 95
30abd221 96 String &operator =(char const *);
97 String &operator =(String const &);
98 bool operator ==(String const &) const;
99 bool operator !=(String const &) const;
100
3db44fdf 101 /**
102 * Retrieve a single character in the string.
103 \param pos Position of character to retrieve.
104 */
4ce0e99b 105 _SQUID_INLINE_ char operator [](unsigned int pos) const;
3db44fdf 106
a7a42b14 107 _SQUID_INLINE_ size_type size() const;
9b558d8a
FC
108 /// variant of size() suited to be used for printf-alikes.
109 /// throws when size() > MAXINT
696a257c 110 int psize() const;
99524de7
FC
111
112 /**
113 * \retval true the String has some contents
114 */
115 _SQUID_INLINE_ bool defined() const;
116 /**
117 * \retval true the String does not hold any contents
118 */
119 _SQUID_INLINE_ bool undefined() const;
120 /**
121 * Returns a raw pointer to the underlying backing store. The caller has been
122 * verified not to make any assumptions about null-termination
123 */
124 _SQUID_INLINE_ char const * rawBuf() const;
125 /**
126 * Returns a raw pointer to the underlying backing store.
127 * The caller requires it to be null-terminated.
128 */
129 _SQUID_INLINE_ char const * termedBuf() const;
e7e1bf60 130 void limitInit(const char *str, int len); // TODO: rename to assign()
30abd221 131 void clean();
132 void reset(char const *str);
133 void append(char const *buf, int len);
134 void append(char const *buf);
135 void append(char const);
136 void append (String const &);
137 void absorb(String &old);
826a1fed
FC
138 const char * pos(char const *aString) const;
139 const char * pos(char const ch) const;
b4f2886c 140 ///offset from string start of the first occurrence of ch
2c1fd837 141 /// returns String::npos if ch is not found
826a1fed
FC
142 size_type find(char const ch) const;
143 size_type find(char const *aString) const;
144 const char * rpos(char const ch) const;
145 size_type rfind(char const ch) const;
30abd221 146 _SQUID_INLINE_ int cmp (char const *) const;
a7a42b14 147 _SQUID_INLINE_ int cmp (char const *, size_type count) const;
30abd221 148 _SQUID_INLINE_ int cmp (String const &) const;
149 _SQUID_INLINE_ int caseCmp (char const *) const;
a7a42b14 150 _SQUID_INLINE_ int caseCmp (char const *, size_type count) const;
9d7a89a5 151 _SQUID_INLINE_ int caseCmp (String const &) const;
30abd221 152
a7a42b14 153 String substr(size_type from, size_type to) const;
9b558d8a 154
a7a42b14 155 _SQUID_INLINE_ void cut(size_type newLength);
30abd221 156
30abd221 157#if DEBUGSTRINGS
30abd221 158 void stat (StoreEntry *) const;
30abd221 159#endif
160
161private:
e7e1bf60 162 void allocAndFill(const char *str, int len);
a7a42b14
FC
163 void allocBuffer(size_type sz);
164 void setBuffer(char *buf, size_type sz);
e7e1bf60 165
15267b22
AR
166 _SQUID_INLINE_ bool nilCmp(bool, bool, int &) const;
167
30abd221 168 /* never reference these directly! */
a7a42b14 169 size_type size_; /* buffer size; 64K limit */
30abd221 170
a7a42b14 171 size_type len_; /* current length */
30abd221 172
173 char *buf_;
9b558d8a
FC
174
175 _SQUID_INLINE_ void set(char const *loc, char const ch);
176 _SQUID_INLINE_ void cutPointer(char const *loc);
177
30abd221 178};
179
180_SQUID_INLINE_ std::ostream & operator<<(std::ostream& os, String const &aString);
181
634592a6
FC
182_SQUID_INLINE_ bool operator<(const String &a, const String &b);
183
32d002cb 184#if _USE_INLINE_
30abd221 185#include "String.cci"
186#endif
0f15e632 187
188#endif /* SQUID_STRING_H */