]> git.ipfire.org Git - thirdparty/squid.git/blame - src/SqString.cci
Added 'clientside_tos' directive and feature.
[thirdparty/squid.git] / src / SqString.cci
CommitLineData
ad80164a 1
2/*
7c617f30 3 * $Id: SqString.cci,v 1.2 2007/05/19 06:49:12 amosjeffries Exp $
ad80164a 4 *
5 * DEBUG: section 67 String
6 * AUTHOR: Duane Wessels
7 *
8 * SQUID Web Proxy Cache http://www.squid-cache.org/
9 * ----------------------------------------------------------
10 *
11 * Squid is the result of efforts by numerous individuals from
12 * the Internet community; see the CONTRIBUTORS file for full
13 * details. Many organizations have provided support for Squid's
14 * development; see the SPONSORS file for full details. Squid is
15 * Copyrighted (C) 2001 by the Regents of the University of
16 * California; see the COPYRIGHT file for full details. Squid
17 * incorporates software developed and/or copyrighted by other
18 * sources; see the CREDITS file for full details.
19 *
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
33 *
34 */
35
36SqString::SqString() : size_(0), len_(0), buf_ (NULL)
37{
38#if DEBUGSTRINGS
39 SqStringRegistry::Instance().add(this);
40#endif
41}
42
43void
44SqString::absorb(SqString &old)
45{
46 clear();
47 size_ = old.size_;
48 buf_ = old.buf_;
49 len_ = old.len_;
50 old.size_ = 0;
51 old.buf_ = NULL;
52 old.len_ = 0;
53}
54
55int
56SqString::size() const
57{
58 return len_;
59}
60
61char const *
62SqString::c_str() const
63{
64 return buf_;
65}
66
67const char *
68SqString::pos(char const *aString) const
69{
70 return strstr(c_str(), aString);
71}
72
73const char *
74SqString::pos(char const ch) const
75{
76 return strchr(c_str(), ch);
77}
78
79const char *
80SqString::rpos(char const ch) const
81{
82 return strrchr(c_str(), ch);
83}
84
85bool
86SqString::empty() const
87{
88 return (buf_ == NULL || len_ == 0);
89}
90
91int
92SqString::compare(char const *aString) const
93{
94 /* strcmp fails on NULLS */
95
96 if (size() == 0 && (aString == NULL || aString[0] == '\0'))
97 return 0;
98
99 if (size() == 0)
100 return -1;
101
102 if (aString == NULL || aString[0] == '\0')
103 return 1;
104
105 return strcmp(c_str(), aString);
106}
107
108int
109SqString::compare(char const *aString, size_t count) const
110{
111 /* always the same at length 0 */
112
113 if (count == 0)
114 return 0;
115
116 if (size() == 0 && (aString == NULL || aString[0] == '\0'))
117 return 0;
118
119 if (size() == 0)
120 return -1;
121
122 if (aString == NULL || aString[0] == '\0')
123 return 1;
124
125 return strncmp(c_str(), aString, count);
126}
127
128int
129SqString::compare(SqString const &aString) const
130{
131 /* strcmp fails on NULLS */
132
133 if (size() == 0 && aString.size() == 0)
134 return 0;
135
136 if (size() == 0)
137 return -1;
138
139 if (aString.size() == 0)
140 return 1;
141
142 return strcmp(c_str(), aString.c_str());
143}
144
ad80164a 145void
146SqString::set (char const *loc, char const ch)
147{
7c617f30 148 operator[](loc-buf_) = ch;
ad80164a 149}
150
ad80164a 151void
152SqString::cut (size_t newLength)
153{
7c617f30 154 operator[](newLength) = '\0';
ad80164a 155 len_ = newLength;
ad80164a 156}
157
ad80164a 158void
159SqString::cutPointer (char const *loc)
160{
7c617f30 161 operator[](loc-buf_) = '\0';
ad80164a 162 len_ = loc-buf_;
ad80164a 163}