2 * $Id: String.cci,v 1.12 2008/02/11 23:01:23 amosjeffries Exp $
4 * DEBUG: section 67 String
5 * AUTHOR: Duane Wessels
7 * SQUID Web Proxy Cache http://www.squid-cache.org/
8 * ----------------------------------------------------------
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.
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.
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.
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.
37 String::String() : size_(0), len_(0), buf_ (NULL)
40 StringRegistry::Instance().add(this);
57 String::operator [](unsigned int pos)
65 String::pos(char const *aString) const
67 return strstr(buf(), aString);
71 String::pos(char const ch) const
73 return strchr(buf(), ch);
77 String::rpos(char const ch) const
79 return strrchr(buf(), (ch));
83 String::cmp (char const *aString) const
85 /* strcmp fails on NULLS */
87 if (size() == 0 && (aString == NULL || aString[0] == '\0'))
93 if (aString == NULL || aString[0] == '\0')
96 return strcmp(buf(), aString);
100 String::cmp (char const *aString, size_t count) const
102 /* always the same at length 0 */
107 if (size() == 0 && (aString == NULL || aString[0] == '\0'))
113 if (aString == NULL || aString[0] == '\0')
116 return strncmp(buf(), aString, count);
120 String::cmp (String const &aString) const
122 /* strcmp fails on NULLS */
124 if (size() == 0 && aString.size() == 0)
130 if (aString.size() == 0)
133 return strcmp(buf(), aString.buf());
137 String::caseCmp(char const *aString) const
139 return strcasecmp(buf(), aString);
143 String::caseCmp(char const *aString, size_t count) const
145 return strncasecmp(buf(), aString, count);
149 String::set(char const *loc, char const ch)
151 if(loc < buf_ || loc > (buf_ + size_) ) return;
157 String::cut(size_t newLength)
159 if(newLength < 0 || newLength > len_) return;
163 // buf_ may be NULL on zero-length strings.
164 if(len_ == 0 && buf_ == NULL) return;
166 buf_[newLength] = '\0';
170 String::cutPointer(char const *loc)
172 if(loc < buf_ || loc > (buf_ + size_) ) return;
179 operator<<(std::ostream& os, String const &aString)