1 martin 1.15 //%LICENSE////////////////////////////////////////////////////////////////
|
2 martin 1.16 //
|
3 martin 1.15 // Licensed to The Open Group (TOG) under one or more contributor license
4 // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
5 // this work for additional information regarding copyright ownership.
6 // Each contributor licenses this file to you under the OpenPegasus Open
7 // Source License; you may not use this file except in compliance with the
8 // License.
|
9 martin 1.16 //
|
10 martin 1.15 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
|
16 martin 1.16 //
|
17 martin 1.15 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
|
19 martin 1.16 //
|
20 martin 1.15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
21 martin 1.16 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22 martin 1.15 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27 martin 1.16 //
|
28 martin 1.15 //////////////////////////////////////////////////////////////////////////
|
29 mike 1.2 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #ifndef _Pegasus_StringInline_h
33 #define _Pegasus_StringInline_h
34
35 #include <Pegasus/Common/StringRep.h>
|
36 mike 1.5 #include <cstring>
|
37 mike 1.2
|
38 dave.sudlik 1.14 PEGASUS_NAMESPACE_BEGIN
39
40 #if !defined(PEGASUS_DISABLE_INTERNAL_INLINES)
41
|
42 mike 1.2 #ifdef PEGASUS_INTERNALONLY
43 # define PEGASUS_STRING_INLINE inline
44 #else
45 # define PEGASUS_STRING_INLINE /* empty */
46 #endif
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
61 PEGASUS_STRING_INLINE CString::operator const char*() const
62 {
63 mike 1.2 return _rep;
64 }
65
66 PEGASUS_STRING_INLINE String::String()
67 {
|
68 kumpf 1.11 // Note: ref() and unref() never touch the reference count of _emptyRep.
|
69 mike 1.2 // 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 kumpf 1.11 //
|
79 gs.keenan 1.8 // 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 kumpf 1.11 //
|
84 gs.keenan 1.8 if (!str._rep)
85 {
86 _rep = &StringRep::_emptyRep;
87 return;
88 }
89 #endif
|
90 mike 1.2 StringRep::ref(_rep = str._rep);
|
91 kumpf 1.11 }
|
92 mike 1.2
93 PEGASUS_STRING_INLINE String::~String()
94 {
95 StringRep::unref(_rep);
96 }
97
|
98 kumpf 1.11 PEGASUS_STRING_INLINE Uint32 String::size() const
99 {
|
100 a.dunfey 1.12 return (Uint32)_rep->size;
|
101 mike 1.2 }
102
|
103 kumpf 1.11 PEGASUS_STRING_INLINE const Char16* String::getChar16Data() const
104 {
105 return (Char16*)&(_rep->data[0]);
|
106 mike 1.2 }
107
|
108 kumpf 1.11 PEGASUS_STRING_INLINE Char16& String::operator[](Uint32 i)
|
109 mike 1.2 {
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 kumpf 1.11 return (Char16&)_rep->data[i];
|
116 mike 1.2 }
117
|
118 kumpf 1.11 PEGASUS_STRING_INLINE const Char16 String::operator[](Uint32 i) const
|
119 mike 1.2 {
120 _checkBounds(i, _rep->size);
|
121 kumpf 1.11 return (Char16&)_rep->data[i];
|
122 mike 1.2 }
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 #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 a.dunfey 1.12 return assign(str, (Uint32)strlen(str));
|
144 mike 1.2 }
145
146 PEGASUS_STRING_INLINE Uint32 String::find(const String& s) const
147 {
|
148 a.dunfey 1.12 return StringFindAux(_rep, (Char16*)&(s._rep->data[0]),
149 (Uint32)s._rep->size);
|
150 mike 1.2 }
151
152 PEGASUS_STRING_INLINE String& String::append(const Char16& c)
153 {
|
154 mike 1.7 if (_rep->size == _rep->cap || _rep->refs.get() != 1)
|
155 mike 1.2 StringAppendCharAux(_rep);
156
157 _rep->data[_rep->size++] = c;
158 _rep->data[_rep->size] = 0;
159 return *this;
160 }
161
162 PEGASUS_STRING_INLINE Boolean String::equalNoCase(
163 const String& s1, const String& s2)
164 {
|
165 mike 1.6 #ifdef PEGASUS_HAS_ICU
166 return StringEqualNoCase(s1, s2);
167 #else
|
168 mike 1.3 return s1._rep->size == s2._rep->size && StringEqualNoCase(s1, s2);
|
169 mike 1.6 #endif
|
170 mike 1.2 }
171
172 #ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES
173 PEGASUS_STRING_INLINE String& String::append(const char* str)
174 {
|
175 a.dunfey 1.12 append(str, (Uint32)strlen(str));
|
176 mike 1.2 return *this;
177 }
178 #endif /* PEGASUS_USE_EXPERIMENTAL_INTERFACES */
179
180 PEGASUS_STRING_INLINE Boolean operator==(const String& s1, const String& s2)
181 {
182 return String::equal(s1, s2);
183 }
184
185 PEGASUS_STRING_INLINE Boolean operator==(const String& s1, const char* s2)
186 {
187 return String::equal(s1, s2);
188 }
189
190 PEGASUS_STRING_INLINE Boolean operator==(const char* s1, const String& s2)
191 {
192 return String::equal(s2, s1);
193 }
194
195 PEGASUS_STRING_INLINE Boolean operator!=(const String& s1, const String& s2)
196 {
197 mike 1.2 return !String::equal(s1, s2);
198 }
199
200 PEGASUS_STRING_INLINE Boolean operator!=(const String& s1, const char* s2)
201 {
202 return !String::equal(s1, s2);
203 }
204
205 PEGASUS_STRING_INLINE Boolean operator!=(const char* s1, const String& s2)
206 {
207 return !String::equal(s2, s1);
208 }
209
210 PEGASUS_STRING_INLINE Boolean operator<(const String& s1, const String& s2)
211 {
212 return String::compare(s1, s2) < 0;
213 }
214
215 PEGASUS_STRING_INLINE Boolean operator<(const String& s1, const char* s2)
216 {
217 return String::compare(s1, s2) < 0;
218 mike 1.2 }
219
220 PEGASUS_STRING_INLINE Boolean operator<(const char* s1, const String& s2)
221 {
222 return String::compare(s2, s1) > 0;
223 }
224
225 PEGASUS_STRING_INLINE Boolean operator>(const String& s1, const String& s2)
226 {
227 return String::compare(s1, s2) > 0;
228 }
229
230 PEGASUS_STRING_INLINE Boolean operator>(const String& s1, const char* s2)
231 {
232 return String::compare(s1, s2) > 0;
233 }
234
235 PEGASUS_STRING_INLINE Boolean operator>(const char* s1, const String& s2)
236 {
237 return String::compare(s2, s1) < 0;
238 }
239 mike 1.2
240 PEGASUS_STRING_INLINE Boolean operator<=(const String& s1, const String& s2)
241 {
242 return String::compare(s1, s2) <= 0;
243 }
244
245 PEGASUS_STRING_INLINE Boolean operator<=(const String& s1, const char* s2)
246 {
247 return String::compare(s1, s2) <= 0;
248 }
249
250 PEGASUS_STRING_INLINE Boolean operator<=(const char* s1, const String& s2)
251 {
252 return String::compare(s2, s1) >= 0;
253 }
254
255 PEGASUS_STRING_INLINE Boolean operator>=(const String& s1, const String& s2)
256 {
257 return String::compare(s1, s2) >= 0;
258 }
259
260 mike 1.2 PEGASUS_STRING_INLINE Boolean operator>=(const String& s1, const char* s2)
261 {
262 return String::compare(s1, s2) >= 0;
263 }
264
265 PEGASUS_STRING_INLINE Boolean operator>=(const char* s1, const String& s2)
266 {
267 return String::compare(s2, s1) <= 0;
268 }
269
270 PEGASUS_STRING_INLINE String operator+(const String& s1, const String& s2)
271 {
272 #ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES
273 return String(s1, s2);
274 #else
275 String tmp;
276 tmp.reserveCapacity(s1.size() + s2.size());
277 tmp.append(s1);
278 tmp.append(s2);
279 return tmp;
280 #endif
281 mike 1.2 }
282
283 #ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES
284 PEGASUS_STRING_INLINE String operator+(const String& s1, const char* s2)
285 {
286 return String(s1, s2);
287 }
288 #endif /* PEGASUS_USE_EXPERIMENTAL_INTERFACES */
289
290 #ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES
291 PEGASUS_STRING_INLINE String operator+(const char* s1, const String& s2)
292 {
293 return String(s1, s2);
294 }
295 #endif /* PEGASUS_USE_EXPERIMENTAL_INTERFACES */
296
|
297 dave.sudlik 1.14 #endif /* !defined(PEGASUS_DISABLE_INTERNAL_INLINES) */
298
299 /**
300 Fast way to assign a given character string consisting of ASCII only and
301 legal characters for a CIMName (i.e. letter, numbers and underscore)
302 to a String reference.
303
304 @param s reference to the String object which will be changed
305 @param str character string
306 @param n number of characters which shall be assigned from str to s
307 */
|
308 thilo.boehm 1.13 PEGASUS_COMMON_LINKAGE void AssignASCII(String& s, const char* str, Uint32 n);
309
|
310 mike 1.2 PEGASUS_NAMESPACE_END
311
312 #endif /* _Pegasus_StringInline_h */
|