1 karl 1.9 //%2006////////////////////////////////////////////////////////////////////////
|
2 mike 1.2 //
3 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
7 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
9 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 karl 1.9 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 mike 1.2 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
|
20 karl 1.9 //
|
21 mike 1.2 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //==============================================================================
31 //
32 //%/////////////////////////////////////////////////////////////////////////////
33
34 #ifndef _Pegasus_StringInline_h
35 #define _Pegasus_StringInline_h
36
37 #include <Pegasus/Common/StringRep.h>
|
38 mike 1.5 #include <cstring>
|
39 mike 1.2
40 #ifdef PEGASUS_INTERNALONLY
41 # define PEGASUS_STRING_INLINE inline
42 #else
43 # define PEGASUS_STRING_INLINE /* empty */
44 #endif
45
46 PEGASUS_NAMESPACE_BEGIN
47
48 PEGASUS_STRING_INLINE CString::CString() : _rep(0)
49 {
50 }
51
52 PEGASUS_STRING_INLINE CString::CString(char* cstr) : _rep(cstr)
53 {
54 }
55
56 PEGASUS_STRING_INLINE CString::~CString()
57 {
58 operator delete(_rep);
59 }
60 mike 1.2
61 PEGASUS_STRING_INLINE CString::operator const char*() const
62 {
63 return _rep;
64 }
65
66 PEGASUS_STRING_INLINE String::String()
67 {
68 // Note: ref() and unref() never touch the reference count of _emptyRep.
69 // This allows use to optimize the copy constructor by not incrementing
70 // _emptyRep.refs here. Performance is critical in this function. Please
71 // do not add any code to this function.
72 _rep = &StringRep::_emptyRep;
73 }
74
75 PEGASUS_STRING_INLINE String::String(const String& str)
76 {
|
77 gs.keenan 1.8 #ifdef PEGASUS_HAVE_BROKEN_GLOBAL_CONSTRUCTION
78 //
79 // Some compilers don't do a good job of initializing global
80 // constructors in the proper sequence. This is one such case.
81 // String::EMPTY is not initialized by the time this is first
82 // called during initialization of the executable.
83 //
84 if (!str._rep)
85 {
86 _rep = &StringRep::_emptyRep;
87 return;
88 }
89 #endif
|
90 mike 1.2 StringRep::ref(_rep = str._rep);
91 }
92
93 PEGASUS_STRING_INLINE String::~String()
94 {
95 StringRep::unref(_rep);
96 }
97
98 PEGASUS_STRING_INLINE Uint32 String::size() const
99 {
100 return _rep->size;
101 }
102
103 PEGASUS_STRING_INLINE const Char16* String::getChar16Data() const
104 {
|
105 w.otsuka 1.10 return (Char16*)&(_rep->data[0]);
|
106 mike 1.2 }
107
108 PEGASUS_STRING_INLINE Char16& String::operator[](Uint32 i)
109 {
110 _checkBounds(i, _rep->size);
111
|
112 mike 1.7 if (_rep->refs.get() != 1)
|
113 mike 1.2 _rep = StringRep::copyOnWrite(_rep);
114
115 return (Char16&)_rep->data[i];
116 }
117
118 PEGASUS_STRING_INLINE const Char16 String::operator[](Uint32 i) const
119 {
120 _checkBounds(i, _rep->size);
121 return (Char16&)_rep->data[i];
122 }
123
124 PEGASUS_STRING_INLINE String& String::operator=(const String& str)
125 {
126 return assign(str);
127 }
128
129 #ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES
130 PEGASUS_STRING_INLINE String& String::operator=(const char* str)
131 {
132 return assign(str);
133 }
134 mike 1.2 #endif /* PEGASUS_USE_EXPERIMENTAL_INTERFACES */
135
136 PEGASUS_STRING_INLINE String& String::assign(const Char16* str)
137 {
138 return assign(str, StringRep::length((Uint16*)str));
139 }
140
141 PEGASUS_STRING_INLINE String& String::assign(const char* str)
142 {
143 return assign(str, strlen(str));
144 }
145
146 PEGASUS_STRING_INLINE Uint32 String::find(const String& s) const
147 {
|
148 w.otsuka 1.10 return StringFindAux(_rep, (Char16*)&(s._rep->data[0]), s._rep->size);
|
149 mike 1.2 }
150
151 PEGASUS_STRING_INLINE String& String::append(const Char16& c)
152 {
|
153 mike 1.7 if (_rep->size == _rep->cap || _rep->refs.get() != 1)
|
154 mike 1.2 StringAppendCharAux(_rep);
155
156 _rep->data[_rep->size++] = c;
157 _rep->data[_rep->size] = 0;
158 return *this;
159 }
160
161 PEGASUS_STRING_INLINE Boolean String::equalNoCase(
162 const String& s1, const String& s2)
163 {
|
164 mike 1.6 #ifdef PEGASUS_HAS_ICU
165 return StringEqualNoCase(s1, s2);
166 #else
|
167 mike 1.3 return s1._rep->size == s2._rep->size && StringEqualNoCase(s1, s2);
|
168 mike 1.6 #endif
|
169 mike 1.2 }
170
171 #ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES
172 PEGASUS_STRING_INLINE String& String::append(const char* str)
173 {
174 append(str, strlen(str));
175 return *this;
176 }
177 #endif /* PEGASUS_USE_EXPERIMENTAL_INTERFACES */
178
179 PEGASUS_STRING_INLINE Boolean operator==(const String& s1, const String& s2)
180 {
181 return String::equal(s1, s2);
182 }
183
184 PEGASUS_STRING_INLINE Boolean operator==(const String& s1, const char* s2)
185 {
186 return String::equal(s1, s2);
187 }
188
189 PEGASUS_STRING_INLINE Boolean operator==(const char* s1, const String& s2)
190 mike 1.2 {
191 return String::equal(s2, s1);
192 }
193
194 PEGASUS_STRING_INLINE Boolean operator!=(const String& s1, const String& s2)
195 {
196 return !String::equal(s1, s2);
197 }
198
199 PEGASUS_STRING_INLINE Boolean operator!=(const String& s1, const char* s2)
200 {
201 return !String::equal(s1, s2);
202 }
203
204 PEGASUS_STRING_INLINE Boolean operator!=(const char* s1, const String& s2)
205 {
206 return !String::equal(s2, s1);
207 }
208
209 PEGASUS_STRING_INLINE Boolean operator<(const String& s1, const String& s2)
210 {
211 mike 1.2 return String::compare(s1, s2) < 0;
212 }
213
214 PEGASUS_STRING_INLINE Boolean operator<(const String& s1, const char* s2)
215 {
216 return String::compare(s1, s2) < 0;
217 }
218
219 PEGASUS_STRING_INLINE Boolean operator<(const char* s1, const String& s2)
220 {
221 return String::compare(s2, s1) > 0;
222 }
223
224 PEGASUS_STRING_INLINE Boolean operator>(const String& s1, const String& s2)
225 {
226 return String::compare(s1, s2) > 0;
227 }
228
229 PEGASUS_STRING_INLINE Boolean operator>(const String& s1, const char* s2)
230 {
231 return String::compare(s1, s2) > 0;
232 mike 1.2 }
233
234 PEGASUS_STRING_INLINE Boolean operator>(const char* s1, const String& s2)
235 {
236 return String::compare(s2, s1) < 0;
237 }
238
239 PEGASUS_STRING_INLINE Boolean operator<=(const String& s1, const String& s2)
240 {
241 return String::compare(s1, s2) <= 0;
242 }
243
244 PEGASUS_STRING_INLINE Boolean operator<=(const String& s1, const char* s2)
245 {
246 return String::compare(s1, s2) <= 0;
247 }
248
249 PEGASUS_STRING_INLINE Boolean operator<=(const char* s1, const String& s2)
250 {
251 return String::compare(s2, s1) >= 0;
252 }
253 mike 1.2
254 PEGASUS_STRING_INLINE Boolean operator>=(const String& s1, const String& s2)
255 {
256 return String::compare(s1, s2) >= 0;
257 }
258
259 PEGASUS_STRING_INLINE Boolean operator>=(const String& s1, const char* s2)
260 {
261 return String::compare(s1, s2) >= 0;
262 }
263
264 PEGASUS_STRING_INLINE Boolean operator>=(const char* s1, const String& s2)
265 {
266 return String::compare(s2, s1) <= 0;
267 }
268
269 PEGASUS_STRING_INLINE String operator+(const String& s1, const String& s2)
270 {
271 #ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES
272 return String(s1, s2);
273 #else
274 mike 1.2 String tmp;
275 tmp.reserveCapacity(s1.size() + s2.size());
276 tmp.append(s1);
277 tmp.append(s2);
278 return tmp;
279 #endif
280 }
281
282 #ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES
283 PEGASUS_STRING_INLINE String operator+(const String& s1, const char* s2)
284 {
285 return String(s1, s2);
286 }
287 #endif /* PEGASUS_USE_EXPERIMENTAL_INTERFACES */
288
289 #ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES
290 PEGASUS_STRING_INLINE String operator+(const char* s1, const String& s2)
291 {
292 return String(s1, s2);
293 }
294 #endif /* PEGASUS_USE_EXPERIMENTAL_INTERFACES */
295 mike 1.2
296 PEGASUS_NAMESPACE_END
297
298 #endif /* _Pegasus_StringInline_h */
|