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.
39 #else /* HAVE_STDINT_H */
41 #define INT_MAX 1<<31 //hack but a safe bet
43 #endif /* HAVE_STDINT_H */
46 String::String() : size_(0), len_(0), buf_ (NULL)
49 StringRegistry::Instance().add(this);
59 bool String::defined() const
64 bool String::undefined() const
70 String::rawBuf() const
76 String::termedBuf() const
82 String::operator [](unsigned int aPos) const
90 /// compare NULL and empty strings because str*cmp() may fail on NULL strings
91 /// and because we need to return consistent results for strncmp(count == 0).
93 String::nilCmp(const bool thisIsNilOrEmpty, const bool otherIsNilOrEmpty, int &result) const
95 if (!thisIsNilOrEmpty && !otherIsNilOrEmpty)
96 return false; // result does not matter
98 if (thisIsNilOrEmpty && otherIsNilOrEmpty)
100 else if (thisIsNilOrEmpty)
102 else // otherIsNilOrEmpty
110 String::cmp (char const *aString) const
113 if (nilCmp(!size(), (!aString || !*aString), result))
116 return strcmp(termedBuf(), aString);
120 String::cmp (char const *aString, String::size_type count) const
123 if (nilCmp((!size() || !count), (!aString || !*aString || !count), result))
126 return strncmp(termedBuf(), aString, count);
130 String::cmp (String const &aString) const
133 if (nilCmp(!size(), !aString.size(), result))
136 return strcmp(termedBuf(), aString.termedBuf());
140 String::caseCmp(char const *aString) const
143 if (nilCmp(!size(), (!aString || !*aString), result))
146 return strcasecmp(termedBuf(), aString);
150 String::caseCmp(char const *aString, String::size_type count) const
153 if (nilCmp((!size() || !count), (!aString || !*aString || !count), result))
156 return strncasecmp(termedBuf(), aString, count);
160 String::caseCmp(const String &str) const
162 return caseCmp(str.rawBuf(),str.size());
167 String::set(char const *loc, char const ch)
169 if (loc < buf_ || loc > (buf_ + size_) ) return;
175 String::cut(String::size_type newLength)
177 // size_type is size_t, unsigned. No need to check for newLength <0
178 if (newLength > len_) return;
182 // buf_ may be NULL on zero-length strings.
183 if (len_ == 0 && buf_ == NULL) return;
185 buf_[newLength] = '\0';
189 String::cutPointer(char const *loc)
191 if (loc < buf_ || loc > (buf_ + size_) ) return;
198 operator<<(std::ostream& os, String const &aString)
200 os.write(aString.rawBuf(),aString.size());
205 operator<(const String &a, const String &b)