]> git.ipfire.org Git - thirdparty/squid.git/blame - src/SquidString.h
Cleanup: un-wrap C++ header includes
[thirdparty/squid.git] / src / SquidString.h
CommitLineData
0f15e632 1/*
0f15e632 2 * DEBUG: section 67 String
30abd221 3 * AUTHOR: Duane Wessels
0f15e632 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.
26ac0430 21 *
0f15e632 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.
26ac0430 26 *
0f15e632 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
e1f7507e
AJ
36#include <ostream>
37
bb790702
FC
38/* squid string placeholder (for printf) */
39#ifndef SQUIDSTRINGPH
40#define SQUIDSTRINGPH "%.*s"
b716b3d4 41#define SQUIDSTRINGPRINT(s) (s).psize(),(s).rawBuf()
bb790702
FC
42#endif /* SQUIDSTRINGPH */
43
30abd221 44class String
45{
0353e724 46
30abd221 47public:
48 _SQUID_INLINE_ String();
9e9ef416
RP
49 String(char const *);
50 String(String const &);
30abd221 51 ~String();
52
b4197865 53 typedef size_t size_type; //storage size intentionally unspecified
556bfec0 54 const static size_type npos = static_cast<size_type>(-1);
a7a42b14 55
30abd221 56 String &operator =(char const *);
57 String &operator =(String const &);
58 bool operator ==(String const &) const;
59 bool operator !=(String const &) const;
60
3db44fdf 61 /**
62 * Retrieve a single character in the string.
63 \param pos Position of character to retrieve.
64 */
4ce0e99b 65 _SQUID_INLINE_ char operator [](unsigned int pos) const;
3db44fdf 66
a7a42b14 67 _SQUID_INLINE_ size_type size() const;
9b558d8a
FC
68 /// variant of size() suited to be used for printf-alikes.
69 /// throws when size() > MAXINT
696a257c 70 int psize() const;
99524de7 71
99524de7
FC
72 /**
73 * Returns a raw pointer to the underlying backing store. The caller has been
74 * verified not to make any assumptions about null-termination
75 */
76 _SQUID_INLINE_ char const * rawBuf() const;
77 /**
78 * Returns a raw pointer to the underlying backing store.
79 * The caller requires it to be null-terminated.
80 */
81 _SQUID_INLINE_ char const * termedBuf() const;
e7e1bf60 82 void limitInit(const char *str, int len); // TODO: rename to assign()
30abd221 83 void clean();
84 void reset(char const *str);
85 void append(char const *buf, int len);
86 void append(char const *buf);
87 void append(char const);
9e9ef416 88 void append(String const &);
30abd221 89 void absorb(String &old);
826a1fed
FC
90 const char * pos(char const *aString) const;
91 const char * pos(char const ch) const;
b4f2886c 92 ///offset from string start of the first occurrence of ch
2c1fd837 93 /// returns String::npos if ch is not found
826a1fed
FC
94 size_type find(char const ch) const;
95 size_type find(char const *aString) const;
96 const char * rpos(char const ch) const;
97 size_type rfind(char const ch) const;
9e9ef416
RP
98 _SQUID_INLINE_ int cmp(char const *) const;
99 _SQUID_INLINE_ int cmp(char const *, size_type count) const;
100 _SQUID_INLINE_ int cmp(String const &) const;
101 _SQUID_INLINE_ int caseCmp(char const *) const;
102 _SQUID_INLINE_ int caseCmp(char const *, size_type count) const;
103 _SQUID_INLINE_ int caseCmp(String const &) const;
30abd221 104
a7a42b14 105 String substr(size_type from, size_type to) const;
9b558d8a 106
a7a42b14 107 _SQUID_INLINE_ void cut(size_type newLength);
30abd221 108
30abd221 109private:
e7e1bf60 110 void allocAndFill(const char *str, int len);
a7a42b14
FC
111 void allocBuffer(size_type sz);
112 void setBuffer(char *buf, size_type sz);
e7e1bf60 113
b38b26cb
AJ
114 bool defined() const {return buf_!=NULL;}
115 bool undefined() const {return !defined();}
116
15267b22
AR
117 _SQUID_INLINE_ bool nilCmp(bool, bool, int &) const;
118
30abd221 119 /* never reference these directly! */
a7a42b14 120 size_type size_; /* buffer size; 64K limit */
30abd221 121
a7a42b14 122 size_type len_; /* current length */
30abd221 123
124 char *buf_;
9b558d8a
FC
125
126 _SQUID_INLINE_ void set(char const *loc, char const ch);
127 _SQUID_INLINE_ void cutPointer(char const *loc);
128
30abd221 129};
130
131_SQUID_INLINE_ std::ostream & operator<<(std::ostream& os, String const &aString);
132
634592a6
FC
133_SQUID_INLINE_ bool operator<(const String &a, const String &b);
134
32d002cb 135#if _USE_INLINE_
30abd221 136#include "String.cci"
137#endif
0f15e632 138
8a648e8d
FC
139const char *checkNullString(const char *p);
140int stringHasWhitespace(const char *);
141int stringHasCntl(const char *);
142char *strwordtok(char *buf, char **t);
0875c529 143
0f15e632 144#endif /* SQUID_STRING_H */