~clint-fewbar/ubuntu/precise/squid3/ignore-sighup-early

« back to all changes in this revision

Viewing changes to src/String.cci

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2010-05-04 11:15:49 UTC
  • mfrom: (1.3.1 upstream)
  • mto: (20.3.1 squeeze) (21.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: james.westby@ubuntu.com-20100504111549-1apjh2g5sndki4te
Tags: upstream-3.1.3
ImportĀ upstreamĀ versionĀ 3.1.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
1
/*
3
 
 * $Id: String.cci,v 1.10.2.1 2008/02/27 10:47:59 amosjeffries Exp $
 
2
 * $Id$
4
3
 *
5
4
 * DEBUG: section 67    String
6
5
 * AUTHOR: Duane Wessels
21
20
 *  it under the terms of the GNU General Public License as published by
22
21
 *  the Free Software Foundation; either version 2 of the License, or
23
22
 *  (at your option) any later version.
24
 
 *  
 
23
 *
25
24
 *  This program is distributed in the hope that it will be useful,
26
25
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
27
26
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28
27
 *  GNU General Public License for more details.
29
 
 *  
 
28
 *
30
29
 *  You should have received a copy of the GNU General Public License
31
30
 *  along with this program; if not, write to the Free Software
32
31
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
33
32
 *
34
33
 */
35
34
 
36
 
#include "assert.h"
 
35
#include "config.h"
37
36
#include <cstring>
38
37
 
 
38
#ifdef HAVE_STDINT_H
 
39
#include <stdint.h> //for INT_MAX
 
40
#else /* HAVE_STDINT_H */
 
41
#ifndef INT_MAX
 
42
#define INT_MAX 1<<31 //hack but a safe bet
 
43
#endif /* INT_MAX */
 
44
#endif /* HAVE_STDINT_H */
 
45
 
 
46
 
39
47
String::String() : size_(0), len_(0), buf_ (NULL)
40
48
{
41
49
#if DEBUGSTRINGS
43
51
#endif
44
52
}
45
53
 
46
 
int
 
54
String::size_type
47
55
String::size() const
48
56
{
49
57
    return len_;
50
58
}
51
59
 
52
 
char const *
53
 
String::buf() const
54
 
{
55
 
    return buf_;
56
 
}
57
 
 
58
 
const char *
59
 
String::pos(char const *aString) const
60
 
{
61
 
    return strstr(buf(), aString);
62
 
}
63
 
 
64
 
const char *
65
 
String::pos(char const ch) const
66
 
{
67
 
    return strchr(buf(), ch);
68
 
}
69
 
 
70
 
const char *
71
 
String::rpos(char const ch) const
72
 
{
73
 
    return strrchr(buf(), (ch));
74
 
}
 
60
bool String::defined() const
 
61
{
 
62
    return buf_!=NULL;
 
63
}
 
64
 
 
65
bool String::undefined() const
 
66
{
 
67
    return buf_==NULL;
 
68
}
 
69
 
 
70
char const *
 
71
String::rawBuf() const
 
72
{
 
73
    return buf_;
 
74
}
 
75
 
 
76
char const *
 
77
String::termedBuf() const
 
78
{
 
79
    return buf_;
 
80
}
 
81
 
 
82
char
 
83
String::operator [](unsigned int aPos) const
 
84
{
 
85
    assert(aPos < size_);
 
86
 
 
87
    return buf_[aPos];
 
88
}
 
89
 
75
90
 
76
91
int
77
92
String::cmp (char const *aString) const
87
102
    if (aString == NULL || aString[0] == '\0')
88
103
        return 1;
89
104
 
90
 
    return strcmp(buf(), aString);
 
105
    return strcmp(termedBuf(), aString);
91
106
}
92
107
 
93
108
int
94
 
String::cmp (char const *aString, size_t count) const
 
109
String::cmp (char const *aString, String::size_type count) const
95
110
{
96
111
    /* always the same at length 0 */
97
112
 
107
122
    if (aString == NULL || aString[0] == '\0')
108
123
        return 1;
109
124
 
110
 
    return strncmp(buf(), aString, count);
 
125
    return strncmp(termedBuf(), aString, count);
111
126
}
112
127
 
113
128
int
124
139
    if (aString.size() == 0)
125
140
        return 1;
126
141
 
127
 
    return strcmp(buf(), aString.buf());
 
142
    return strcmp(termedBuf(), aString.termedBuf());
128
143
}
129
144
 
130
145
int
131
146
String::caseCmp(char const *aString) const
132
147
{
133
 
    return strcasecmp(buf(), aString);
134
 
}
135
 
 
136
 
int
137
 
String::caseCmp(char const *aString, size_t count) const
138
 
{
139
 
    return strncasecmp(buf(), aString, count);
140
 
}
 
148
    return strcasecmp(termedBuf(), aString);
 
149
}
 
150
 
 
151
int
 
152
String::caseCmp(char const *aString, String::size_type count) const
 
153
{
 
154
    return strncasecmp(termedBuf(), aString, count);
 
155
}
 
156
 
 
157
int
 
158
String::caseCmp(const String &str) const
 
159
{
 
160
    return caseCmp(str.rawBuf(),str.size());
 
161
}
 
162
 
141
163
 
142
164
void
143
165
String::set(char const *loc, char const ch)
144
166
{
145
 
    if(loc < buf_ || loc > (buf_ + size_) ) return;
 
167
    if (loc < buf_ || loc > (buf_ + size_) ) return;
146
168
 
147
169
    buf_[loc-buf_] = ch;
148
170
}
149
171
 
150
172
void
151
 
String::cut(size_t newLength)
 
173
String::cut(String::size_type newLength)
152
174
{
153
 
    if(newLength < 0 || newLength > len_) return;
 
175
    if (newLength < 0 || newLength > len_) return;
154
176
 
155
177
    len_ = newLength;
156
178
 
157
 
    if(len_ == 0 && buf_ == NULL) return; // buf_ may be NULL on zero-length strings.
 
179
    // buf_ may be NULL on zero-length strings.
 
180
    if (len_ == 0 && buf_ == NULL) return;
 
181
 
158
182
    buf_[newLength] = '\0';
159
183
}
160
184
 
161
185
void
162
186
String::cutPointer(char const *loc)
163
187
{
164
 
    if(loc < buf_ || loc > (buf_ + size_) ) return;
 
188
    if (loc < buf_ || loc > (buf_ + size_) ) return;
165
189
 
166
190
    len_ = loc-buf_;
167
191
    buf_[len_] = '\0';
170
194
std::ostream &
171
195
operator<<(std::ostream& os, String const &aString)
172
196
{
173
 
    os << aString.buf();
 
197
    os.write(aString.rawBuf(),aString.size());
174
198
    return os;
175
199
}