(file) Return to StringInline.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

  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 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                PEGASUS_NAMESPACE_END
298                
299                #endif /* _Pegasus_StringInline_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2