4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 2000 by Sun Microsystems, Inc.
24 * All rights reserved.
33 : str_(strcpy(new char[strlen("")+1], "")),
37 Str::Str(const char *str
)
38 : str_(strcpy(new char[strlen(str
)+1], str
)),
42 Str::Str(const char *str
, int len
)
43 : str_(new char[len
+1]),
46 strlcpy(str_
, str
, len
+1);
49 Str::Str(const Str
& rhs
)
50 : str_(strcpy(new char[strlen(rhs
.str_
)+1], rhs
.str_
)),
60 Str::operator = (const Str
& rhs
)
63 str_
= strcpy(new char[strlen(rhs
.str_
)+1], rhs
.str_
);
64 // pointer arithmetic very BAD I know...
65 nextTok_
= str_
+ (rhs
.nextTok_
- rhs
.str_
);
69 Str::operator = (const char *str
)
72 str_
= strcpy(new char[strlen(str
)+1], str
);
77 Str::operator == (const Str
& rhs
) const
79 return (strcmp(str_
, rhs
.str_
) == 0);
83 Str::operator != (const Str
& rhs
) const
85 return (strcmp(str_
, rhs
.str_
) != 0);
89 Str::operator[](int index
) const
95 Str::operator<<(Str rhs
)
97 char *tmp
= new char[strlen(str_
)+strlen(rhs
.peak())+1];
101 strcat(str_
, rhs
.peak());
106 Str::operator<<(long long i
)
109 sprintf(msg
, "%lld", i
);
110 return (*this << msg
);
114 Str::operator<<(long i
)
117 sprintf(msg
, "%ld", i
);
118 return (*this << msg
);
122 Str::operator<<(int i
)
125 sprintf(msg
, "%d", i
);
126 return (*this << msg
);
130 Str::operator<<(char c
)
133 sprintf(msg
, "%c", c
);
134 return (*this << msg
);
139 Str::compare(const Str
& rhs
) const
141 return (strcmp(str_
, rhs
.str_
));
145 Str::length(void) const
147 return (strlen(str_
));
151 Str::tokenize(Str
& token
, const Str
& separators
, Str
& remainder
)
155 for (i
= 0; nextTok_
[i
] != '\0'; i
++) {
156 for (j
= 0; j
< separators
.length(); j
++) {
157 if (nextTok_
[i
] == separators
[j
]) {
160 nextTok_
= &(nextTok_
[i
+1]);
161 // Str remain(nextTok_);
162 remainder
= nextTok_
;
163 return (separators
[j
]);
169 remainder
= nextTok_
;
170 // remainder = *this;
176 Str::resetToken(void)
182 Str::peak(void) const
188 Str::replaceAll(char c
, char newc
)
190 for (int i
= 0; i
< strlen(str_
); i
++) {
196 // oh look an extra line!!!