xref: /AOO41X/main/sal/inc/rtl/string.hxx (revision b3f482f268a8cff565adb4deae69807ab3bbf1f8)
1565d668cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3565d668cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4565d668cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5565d668cSAndrew Rist  * distributed with this work for additional information
6565d668cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7565d668cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8565d668cSAndrew Rist  * "License"); you may not use this file except in compliance
9565d668cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11565d668cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13565d668cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14565d668cSAndrew Rist  * software distributed under the License is distributed on an
15565d668cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16565d668cSAndrew Rist  * KIND, either express or implied.  See the License for the
17565d668cSAndrew Rist  * specific language governing permissions and limitations
18565d668cSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20565d668cSAndrew Rist  *************************************************************/
21565d668cSAndrew Rist 
22565d668cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _RTL_STRING_HXX_
25cdf0e10cSrcweir #define _RTL_STRING_HXX_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #ifdef __cplusplus
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #ifndef _RTL_DIAGNOSE_H_
30cdf0e10cSrcweir #include <osl/diagnose.h>
31cdf0e10cSrcweir #endif
32cdf0e10cSrcweir #include <rtl/memory.h>
33cdf0e10cSrcweir #include <rtl/textenc.h>
34cdf0e10cSrcweir #include <rtl/string.h>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #if !defined EXCEPTIONS_OFF
37cdf0e10cSrcweir #include <new>
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir 
40cdf0e10cSrcweir namespace rtl
41cdf0e10cSrcweir {
42cdf0e10cSrcweir 
43cdf0e10cSrcweir /* ======================================================================= */
44cdf0e10cSrcweir 
45cdf0e10cSrcweir /**
46cdf0e10cSrcweir   This String class provide base functionality for C++ like 8-Bit
47cdf0e10cSrcweir   character array handling. The advantage of this class is, that it
48cdf0e10cSrcweir   handle all the memory managament for you - and it do it
49cdf0e10cSrcweir   more efficient. If you assign a string to another string, the
50cdf0e10cSrcweir   data of both strings are shared (without any copy operation or
51cdf0e10cSrcweir   memory allocation) as long as you do not change the string. This class
52cdf0e10cSrcweir   stores also the length of the string, so that many operations are
53cdf0e10cSrcweir   faster as the C-str-functions.
54cdf0e10cSrcweir 
55cdf0e10cSrcweir   This class provide only readonly string handling. So you could create
56cdf0e10cSrcweir   a string and you could only query the content from this string.
57cdf0e10cSrcweir   It provide also functionality to change the string, but this results
58cdf0e10cSrcweir   in every case in a new string instance (in the most cases with an
59cdf0e10cSrcweir   memory allocation). You don't have functionality to change the
60cdf0e10cSrcweir   content of the string. If you want change the string content, than
61cdf0e10cSrcweir   you should us the OStringBuffer class, which provide these
62cdf0e10cSrcweir   functionality and avoid to much memory allocation.
63cdf0e10cSrcweir 
64cdf0e10cSrcweir   The design of this class is similar to the string classes in Java
65cdf0e10cSrcweir   and so more people should have fewer understanding problems when they
66cdf0e10cSrcweir   use this class.
67cdf0e10cSrcweir */
68cdf0e10cSrcweir 
69cdf0e10cSrcweir class OString
70cdf0e10cSrcweir {
71cdf0e10cSrcweir public:
72cdf0e10cSrcweir     /** @internal */
73cdf0e10cSrcweir     rtl_String * pData;
74cdf0e10cSrcweir 
75cdf0e10cSrcweir private:
76cdf0e10cSrcweir     /** @internal */
77cdf0e10cSrcweir     class DO_NOT_ACQUIRE;
78cdf0e10cSrcweir 
79cdf0e10cSrcweir     /** @internal */
80cdf0e10cSrcweir     OString( rtl_String * value, DO_NOT_ACQUIRE * )
81cdf0e10cSrcweir     {
82cdf0e10cSrcweir         pData = value;
83cdf0e10cSrcweir     }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir public:
86cdf0e10cSrcweir     /**
87cdf0e10cSrcweir       New string containing no characters.
88cdf0e10cSrcweir     */
89cdf0e10cSrcweir     OString() SAL_THROW(())
90cdf0e10cSrcweir     {
91cdf0e10cSrcweir         pData = 0;
92cdf0e10cSrcweir         rtl_string_new( &pData );
93cdf0e10cSrcweir     }
94cdf0e10cSrcweir 
95cdf0e10cSrcweir     /**
96cdf0e10cSrcweir       New string from OString.
97cdf0e10cSrcweir 
98cdf0e10cSrcweir       @param    str         a OString.
99cdf0e10cSrcweir     */
100cdf0e10cSrcweir     OString( const OString & str ) SAL_THROW(())
101cdf0e10cSrcweir     {
102cdf0e10cSrcweir         pData = str.pData;
103cdf0e10cSrcweir         rtl_string_acquire( pData );
104cdf0e10cSrcweir     }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir     /**
107cdf0e10cSrcweir       New string from OString data.
108cdf0e10cSrcweir 
109cdf0e10cSrcweir       @param    str         a OString data.
110cdf0e10cSrcweir     */
111cdf0e10cSrcweir     OString( rtl_String * str ) SAL_THROW(())
112cdf0e10cSrcweir     {
113cdf0e10cSrcweir         pData = str;
114cdf0e10cSrcweir         rtl_string_acquire( pData );
115cdf0e10cSrcweir     }
116cdf0e10cSrcweir 
117cdf0e10cSrcweir     /**
118cdf0e10cSrcweir       New string from a single character.
119cdf0e10cSrcweir 
120cdf0e10cSrcweir       @param    value       a character.
121cdf0e10cSrcweir     */
122cdf0e10cSrcweir     explicit OString( sal_Char value ) SAL_THROW(())
123cdf0e10cSrcweir         : pData (0)
124cdf0e10cSrcweir     {
125cdf0e10cSrcweir         rtl_string_newFromStr_WithLength( &pData, &value, 1 );
126cdf0e10cSrcweir     }
127cdf0e10cSrcweir 
128cdf0e10cSrcweir     /**
129cdf0e10cSrcweir       New string from a character buffer array.
130cdf0e10cSrcweir 
131cdf0e10cSrcweir       @param    value       a NULL-terminated character array.
132cdf0e10cSrcweir     */
133cdf0e10cSrcweir     OString( const sal_Char * value ) SAL_THROW(())
134cdf0e10cSrcweir     {
135cdf0e10cSrcweir         pData = 0;
136cdf0e10cSrcweir         rtl_string_newFromStr( &pData, value );
137cdf0e10cSrcweir     }
138cdf0e10cSrcweir 
139cdf0e10cSrcweir     /**
140cdf0e10cSrcweir       New string from a character buffer array.
141cdf0e10cSrcweir 
142cdf0e10cSrcweir       @param    value       a character array.
143cdf0e10cSrcweir       @param    length      the number of character which should be copied.
144cdf0e10cSrcweir                             The character array length must be greater or
145cdf0e10cSrcweir                             equal than this value.
146cdf0e10cSrcweir     */
147cdf0e10cSrcweir     OString( const sal_Char * value, sal_Int32 length ) SAL_THROW(())
148cdf0e10cSrcweir     {
149cdf0e10cSrcweir         pData = 0;
150cdf0e10cSrcweir         rtl_string_newFromStr_WithLength( &pData, value, length );
151cdf0e10cSrcweir     }
152cdf0e10cSrcweir 
153cdf0e10cSrcweir     /**
154cdf0e10cSrcweir       New string from a Unicode character buffer array.
155cdf0e10cSrcweir 
156cdf0e10cSrcweir       @param    value           a Unicode character array.
157cdf0e10cSrcweir       @param    length          the number of character which should be converted.
158cdf0e10cSrcweir                                 The Unicode character array length must be
159cdf0e10cSrcweir                                 greater or equal than this value.
160cdf0e10cSrcweir       @param    encoding        the text encoding in which the Unicode character
161cdf0e10cSrcweir                                 sequence should be converted.
162cdf0e10cSrcweir       @param    convertFlags    flags which controls the conversion.
163cdf0e10cSrcweir                                 see RTL_UNICODETOTEXT_FLAGS_...
164cdf0e10cSrcweir 
165cdf0e10cSrcweir       @exception std::bad_alloc is thrown if an out-of-memory condition occurs
166cdf0e10cSrcweir     */
167cdf0e10cSrcweir     OString( const sal_Unicode * value, sal_Int32 length,
168cdf0e10cSrcweir              rtl_TextEncoding encoding,
169cdf0e10cSrcweir              sal_uInt32 convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS )
170cdf0e10cSrcweir     {
171cdf0e10cSrcweir         pData = 0;
172cdf0e10cSrcweir         rtl_uString2String( &pData, value, length, encoding, convertFlags );
173cdf0e10cSrcweir #if defined EXCEPTIONS_OFF
174cdf0e10cSrcweir         OSL_ASSERT(pData != NULL);
175cdf0e10cSrcweir #else
176cdf0e10cSrcweir         if (pData == 0) {
177cdf0e10cSrcweir             throw std::bad_alloc();
178cdf0e10cSrcweir         }
179cdf0e10cSrcweir #endif
180cdf0e10cSrcweir     }
181cdf0e10cSrcweir 
182cdf0e10cSrcweir     /**
183cdf0e10cSrcweir       Release the string data.
184cdf0e10cSrcweir     */
185cdf0e10cSrcweir     ~OString() SAL_THROW(())
186cdf0e10cSrcweir     {
187cdf0e10cSrcweir         rtl_string_release( pData );
188cdf0e10cSrcweir     }
189cdf0e10cSrcweir 
190cdf0e10cSrcweir     /**
191cdf0e10cSrcweir       Assign a new string.
192cdf0e10cSrcweir 
193cdf0e10cSrcweir       @param    str         a OString.
194cdf0e10cSrcweir     */
195cdf0e10cSrcweir     OString & operator=( const OString & str ) SAL_THROW(())
196cdf0e10cSrcweir     {
197cdf0e10cSrcweir         rtl_string_assign( &pData, str.pData );
198cdf0e10cSrcweir         return *this;
199cdf0e10cSrcweir     }
200cdf0e10cSrcweir 
201cdf0e10cSrcweir     /**
202cdf0e10cSrcweir       Append a string to this string.
203cdf0e10cSrcweir 
204cdf0e10cSrcweir       @param    str         a OString.
205cdf0e10cSrcweir     */
206cdf0e10cSrcweir     OString & operator+=( const OString & str ) SAL_THROW(())
207cdf0e10cSrcweir     {
208cdf0e10cSrcweir         rtl_string_newConcat( &pData, pData, str.pData );
209cdf0e10cSrcweir         return *this;
210cdf0e10cSrcweir     }
211cdf0e10cSrcweir 
212cdf0e10cSrcweir     /**
213cdf0e10cSrcweir       Returns the length of this string.
214cdf0e10cSrcweir 
215cdf0e10cSrcweir       The length is equal to the number of characters in this string.
216cdf0e10cSrcweir 
217cdf0e10cSrcweir       @return   the length of the sequence of characters represented by this
218cdf0e10cSrcweir                 object.
219cdf0e10cSrcweir     */
220cdf0e10cSrcweir     sal_Int32 getLength() const SAL_THROW(()) { return pData->length; }
221cdf0e10cSrcweir 
222cdf0e10cSrcweir     /**
223cdf0e10cSrcweir       Returns a pointer to the characters of this string.
224cdf0e10cSrcweir 
225cdf0e10cSrcweir       <p>The returned pointer is not guaranteed to point to a null-terminated
226cdf0e10cSrcweir       byte string.  Note that this string object may contain embedded null
227cdf0e10cSrcweir       characters, which will thus also be embedded in the returned byte
228cdf0e10cSrcweir       string.</p>
229cdf0e10cSrcweir 
230cdf0e10cSrcweir       @return a pointer to a (not necessarily null-terminated) byte string
231cdf0e10cSrcweir       representing the characters of this string object.
232cdf0e10cSrcweir     */
233cdf0e10cSrcweir     operator const sal_Char *() const SAL_THROW(()) { return pData->buffer; }
234cdf0e10cSrcweir 
235cdf0e10cSrcweir     /**
236cdf0e10cSrcweir       Returns a pointer to the characters of this string.
237cdf0e10cSrcweir 
238cdf0e10cSrcweir       <p>The returned pointer is guaranteed to point to a null-terminated byte
239cdf0e10cSrcweir       string.  But note that this string object may contain embedded null
240cdf0e10cSrcweir       characters, which will thus also be embedded in the returned
241cdf0e10cSrcweir       null-terminated byte string.</p>
242cdf0e10cSrcweir 
243cdf0e10cSrcweir       @return a pointer to a null-terminated byte string representing the
244cdf0e10cSrcweir       characters of this string object.
245cdf0e10cSrcweir     */
246cdf0e10cSrcweir     const sal_Char * getStr() const SAL_THROW(()) { return pData->buffer; }
247cdf0e10cSrcweir 
248cdf0e10cSrcweir     /**
249cdf0e10cSrcweir       Compares two strings.
250cdf0e10cSrcweir 
251cdf0e10cSrcweir       The comparison is based on the numeric value of each character in
252cdf0e10cSrcweir       the strings and return a value indicating their relationship.
253cdf0e10cSrcweir       This function can't be used for language specific sorting.
254cdf0e10cSrcweir 
255cdf0e10cSrcweir       @param    str         the object to be compared.
256cdf0e10cSrcweir       @return   0 - if both strings are equal
257cdf0e10cSrcweir                 < 0 - if this string is less than the string argument
258cdf0e10cSrcweir                 > 0 - if this string is greater than the string argument
259cdf0e10cSrcweir     */
260cdf0e10cSrcweir     sal_Int32 compareTo( const OString & str ) const SAL_THROW(())
261cdf0e10cSrcweir     {
262cdf0e10cSrcweir         return rtl_str_compare_WithLength( pData->buffer, pData->length,
263cdf0e10cSrcweir                                            str.pData->buffer, str.pData->length );
264cdf0e10cSrcweir     }
265cdf0e10cSrcweir 
266cdf0e10cSrcweir     /**
267cdf0e10cSrcweir       Compares two strings with an maximum count of characters.
268cdf0e10cSrcweir 
269cdf0e10cSrcweir       The comparison is based on the numeric value of each character in
270cdf0e10cSrcweir       the strings and return a value indicating their relationship.
271cdf0e10cSrcweir       This function can't be used for language specific sorting.
272cdf0e10cSrcweir 
273cdf0e10cSrcweir       @param    str         the object to be compared.
274cdf0e10cSrcweir       @param    maxLength   the maximum count of characters to be compared.
275cdf0e10cSrcweir       @return   0 - if both strings are equal
276cdf0e10cSrcweir                 < 0 - if this string is less than the string argument
277cdf0e10cSrcweir                 > 0 - if this string is greater than the string argument
278cdf0e10cSrcweir     */
279cdf0e10cSrcweir     sal_Int32 compareTo( const OString & rObj, sal_Int32 maxLength ) const SAL_THROW(())
280cdf0e10cSrcweir     {
281cdf0e10cSrcweir         return rtl_str_shortenedCompare_WithLength( pData->buffer, pData->length,
282cdf0e10cSrcweir                                                     rObj.pData->buffer, rObj.pData->length, maxLength );
283cdf0e10cSrcweir     }
284cdf0e10cSrcweir 
285cdf0e10cSrcweir     /**
286cdf0e10cSrcweir       Compares two strings in reverse order.
287cdf0e10cSrcweir 
288cdf0e10cSrcweir       The comparison is based on the numeric value of each character in
289cdf0e10cSrcweir       the strings and return a value indicating their relationship.
290cdf0e10cSrcweir       This function can't be used for language specific sorting.
291cdf0e10cSrcweir 
292cdf0e10cSrcweir       @param    str         the object to be compared.
293cdf0e10cSrcweir       @return   0 - if both strings are equal
294cdf0e10cSrcweir                 < 0 - if this string is less than the string argument
295cdf0e10cSrcweir                 > 0 - if this string is greater than the string argument
296cdf0e10cSrcweir     */
297cdf0e10cSrcweir     sal_Int32 reverseCompareTo( const OString & str ) const SAL_THROW(())
298cdf0e10cSrcweir     {
299cdf0e10cSrcweir         return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
300cdf0e10cSrcweir                                                   str.pData->buffer, str.pData->length );
301cdf0e10cSrcweir     }
302cdf0e10cSrcweir 
303cdf0e10cSrcweir     /**
304cdf0e10cSrcweir       Perform a comparison of two strings.
305cdf0e10cSrcweir 
306cdf0e10cSrcweir       The result is true if and only if second string
307cdf0e10cSrcweir       represents the same sequence of characters as the first string.
308cdf0e10cSrcweir       This function can't be used for language specific comparison.
309cdf0e10cSrcweir 
310cdf0e10cSrcweir       @param    str         the object to be compared.
311cdf0e10cSrcweir       @return   sal_True if the strings are equal;
312cdf0e10cSrcweir                 sal_False, otherwise.
313cdf0e10cSrcweir     */
314cdf0e10cSrcweir     sal_Bool equals( const OString & str ) const SAL_THROW(())
315cdf0e10cSrcweir     {
316cdf0e10cSrcweir         if ( pData->length != str.pData->length )
317cdf0e10cSrcweir             return sal_False;
318cdf0e10cSrcweir         if ( pData == str.pData )
319cdf0e10cSrcweir             return sal_True;
320cdf0e10cSrcweir         return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
321cdf0e10cSrcweir                                                   str.pData->buffer, str.pData->length ) == 0;
322cdf0e10cSrcweir     }
323cdf0e10cSrcweir 
324cdf0e10cSrcweir     /**
325cdf0e10cSrcweir       Perform a ASCII lowercase comparison of two strings.
326cdf0e10cSrcweir 
327cdf0e10cSrcweir       The result is true if and only if second string
328cdf0e10cSrcweir       represents the same sequence of characters as the first string,
329cdf0e10cSrcweir       ignoring the case.
330cdf0e10cSrcweir       Character values between 65 and 90 (ASCII A-Z) are interpreted as
331cdf0e10cSrcweir       values between 97 and 122 (ASCII a-z).
332cdf0e10cSrcweir       This function can't be used for language specific comparison.
333cdf0e10cSrcweir 
334cdf0e10cSrcweir       @param    str         the object to be compared.
335cdf0e10cSrcweir       @return   sal_True if the strings are equal;
336cdf0e10cSrcweir                 sal_False, otherwise.
337cdf0e10cSrcweir     */
338cdf0e10cSrcweir     sal_Bool equalsIgnoreAsciiCase( const OString & str ) const SAL_THROW(())
339cdf0e10cSrcweir     {
340cdf0e10cSrcweir         if ( pData->length != str.pData->length )
341cdf0e10cSrcweir             return sal_False;
342cdf0e10cSrcweir         if ( pData == str.pData )
343cdf0e10cSrcweir             return sal_True;
344cdf0e10cSrcweir         return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
345cdf0e10cSrcweir                                                           str.pData->buffer, str.pData->length ) == 0;
346cdf0e10cSrcweir     }
347cdf0e10cSrcweir 
348cdf0e10cSrcweir     /**
349cdf0e10cSrcweir       Match against a substring appearing in this string.
350cdf0e10cSrcweir 
351cdf0e10cSrcweir       The result is true if and only if the second string appears as a substring
352cdf0e10cSrcweir       of this string, at the given position.
353cdf0e10cSrcweir       This function can't be used for language specific comparison.
354cdf0e10cSrcweir 
355cdf0e10cSrcweir       @param    str         the object (substring) to be compared.
356cdf0e10cSrcweir       @param    fromIndex   the index to start the comparion from.
357cdf0e10cSrcweir                             The index must be greater or equal than 0
358cdf0e10cSrcweir                             and less or equal as the string length.
359cdf0e10cSrcweir       @return   sal_True if str match with the characters in the string
360cdf0e10cSrcweir                 at the given position;
361cdf0e10cSrcweir                 sal_False, otherwise.
362cdf0e10cSrcweir     */
363cdf0e10cSrcweir     sal_Bool match( const OString & str, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
364cdf0e10cSrcweir     {
365cdf0e10cSrcweir         return rtl_str_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
366cdf0e10cSrcweir                                                     str.pData->buffer, str.pData->length, str.pData->length ) == 0;
367cdf0e10cSrcweir     }
368cdf0e10cSrcweir 
369cdf0e10cSrcweir     /**
370cdf0e10cSrcweir       Match against a substring appearing in this string, ignoring the case of
371cdf0e10cSrcweir       ASCII letters.
372cdf0e10cSrcweir 
373cdf0e10cSrcweir       The result is true if and only if the second string appears as a substring
374cdf0e10cSrcweir       of this string, at the given position.
375cdf0e10cSrcweir       Character values between 65 and 90 (ASCII A-Z) are interpreted as
376cdf0e10cSrcweir       values between 97 and 122 (ASCII a-z).
377cdf0e10cSrcweir       This function can't be used for language specific comparison.
378cdf0e10cSrcweir 
379cdf0e10cSrcweir       @param    str         the object (substring) to be compared.
380cdf0e10cSrcweir       @param    fromIndex   the index to start the comparion from.
381cdf0e10cSrcweir                             The index must be greater or equal than 0
382cdf0e10cSrcweir                             and less or equal as the string length.
383cdf0e10cSrcweir       @return   sal_True if str match with the characters in the string
384cdf0e10cSrcweir                 at the given position;
385cdf0e10cSrcweir                 sal_False, otherwise.
386cdf0e10cSrcweir     */
387cdf0e10cSrcweir     sal_Bool matchIgnoreAsciiCase( const OString & str, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
388cdf0e10cSrcweir     {
389cdf0e10cSrcweir         return rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
390cdf0e10cSrcweir                                                                    str.pData->buffer, str.pData->length,
391cdf0e10cSrcweir                                                                    str.pData->length ) == 0;
392cdf0e10cSrcweir     }
393cdf0e10cSrcweir 
394cdf0e10cSrcweir     friend sal_Bool     operator == ( const OString& rStr1, const OString& rStr2 ) SAL_THROW(())
395cdf0e10cSrcweir                         { return rStr1.getLength() == rStr2.getLength() && rStr1.compareTo( rStr2 ) == 0; }
396cdf0e10cSrcweir     friend sal_Bool     operator == ( const OString& rStr1, const sal_Char * pStr2 ) SAL_THROW(())
397cdf0e10cSrcweir                         { return rStr1.compareTo( pStr2 ) == 0; }
398cdf0e10cSrcweir     friend sal_Bool     operator == ( const sal_Char * pStr1,   const OString& rStr2 ) SAL_THROW(())
399cdf0e10cSrcweir                         { return OString( pStr1 ).compareTo( rStr2 ) == 0; }
400cdf0e10cSrcweir 
401cdf0e10cSrcweir     friend sal_Bool     operator != ( const OString& rStr1,     const OString& rStr2 ) SAL_THROW(())
402cdf0e10cSrcweir                         { return !(operator == ( rStr1, rStr2 )); }
403cdf0e10cSrcweir     friend sal_Bool     operator != ( const OString& rStr1, const sal_Char * pStr2 ) SAL_THROW(())
404cdf0e10cSrcweir                         { return !(operator == ( rStr1, pStr2 )); }
405cdf0e10cSrcweir     friend sal_Bool     operator != ( const sal_Char * pStr1,   const OString& rStr2 ) SAL_THROW(())
406cdf0e10cSrcweir                         { return !(operator == ( pStr1, rStr2 )); }
407cdf0e10cSrcweir 
408cdf0e10cSrcweir     friend sal_Bool     operator <  ( const OString& rStr1,    const OString& rStr2 ) SAL_THROW(())
409cdf0e10cSrcweir                         { return rStr1.compareTo( rStr2 ) < 0; }
410cdf0e10cSrcweir     friend sal_Bool     operator >  ( const OString& rStr1,    const OString& rStr2 ) SAL_THROW(())
411cdf0e10cSrcweir                         { return rStr1.compareTo( rStr2 ) > 0; }
412cdf0e10cSrcweir     friend sal_Bool     operator <= ( const OString& rStr1,    const OString& rStr2 ) SAL_THROW(())
413cdf0e10cSrcweir                         { return rStr1.compareTo( rStr2 ) <= 0; }
414cdf0e10cSrcweir     friend sal_Bool     operator >= ( const OString& rStr1,    const OString& rStr2 ) SAL_THROW(())
415cdf0e10cSrcweir                         { return rStr1.compareTo( rStr2 ) >= 0; }
416cdf0e10cSrcweir 
417cdf0e10cSrcweir     /**
418cdf0e10cSrcweir       Returns a hashcode for this string.
419cdf0e10cSrcweir 
420cdf0e10cSrcweir       @return   a hash code value for this object.
421cdf0e10cSrcweir 
422cdf0e10cSrcweir       @see rtl::OStringHash for convenient use of STLPort's hash_map
423cdf0e10cSrcweir     */
424cdf0e10cSrcweir     sal_Int32 hashCode() const SAL_THROW(())
425cdf0e10cSrcweir     {
426cdf0e10cSrcweir         return rtl_str_hashCode_WithLength( pData->buffer, pData->length );
427cdf0e10cSrcweir     }
428cdf0e10cSrcweir 
429cdf0e10cSrcweir     /**
430cdf0e10cSrcweir       Returns the index within this string of the first occurrence of the
431cdf0e10cSrcweir       specified character, starting the search at the specified index.
432cdf0e10cSrcweir 
433cdf0e10cSrcweir       @param    ch          character to be located.
434cdf0e10cSrcweir       @param    fromIndex   the index to start the search from.
435cdf0e10cSrcweir                             The index must be greater or equal than 0
436cdf0e10cSrcweir                             and less or equal as the string length.
437cdf0e10cSrcweir       @return   the index of the first occurrence of the character in the
438cdf0e10cSrcweir                 character sequence represented by this string that is
439cdf0e10cSrcweir                 greater than or equal to fromIndex, or
440cdf0e10cSrcweir                 -1 if the character does not occur.
441cdf0e10cSrcweir     */
442cdf0e10cSrcweir     sal_Int32 indexOf( sal_Char ch, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
443cdf0e10cSrcweir     {
444cdf0e10cSrcweir         sal_Int32 ret = rtl_str_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
445cdf0e10cSrcweir         return (ret < 0 ? ret : ret+fromIndex);
446cdf0e10cSrcweir     }
447cdf0e10cSrcweir 
448cdf0e10cSrcweir     /**
449cdf0e10cSrcweir       Returns the index within this string of the last occurrence of the
450cdf0e10cSrcweir       specified character, searching backward starting at the end.
451cdf0e10cSrcweir 
452cdf0e10cSrcweir       @param    ch          character to be located.
453cdf0e10cSrcweir       @return   the index of the last occurrence of the character in the
454cdf0e10cSrcweir                 character sequence represented by this string, or
455cdf0e10cSrcweir                 -1 if the character does not occur.
456cdf0e10cSrcweir     */
457cdf0e10cSrcweir     sal_Int32 lastIndexOf( sal_Char ch ) const SAL_THROW(())
458cdf0e10cSrcweir     {
459cdf0e10cSrcweir         return rtl_str_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
460cdf0e10cSrcweir     }
461cdf0e10cSrcweir 
462cdf0e10cSrcweir     /**
463cdf0e10cSrcweir       Returns the index within this string of the last occurrence of the
464cdf0e10cSrcweir       specified character, searching backward starting before the specified
465cdf0e10cSrcweir       index.
466cdf0e10cSrcweir 
467cdf0e10cSrcweir       @param    ch          character to be located.
468cdf0e10cSrcweir       @param    fromIndex   the index before which to start the search.
469cdf0e10cSrcweir       @return   the index of the last occurrence of the character in the
470cdf0e10cSrcweir                 character sequence represented by this string that
471cdf0e10cSrcweir                 is less than fromIndex, or -1
472cdf0e10cSrcweir                 if the character does not occur before that point.
473cdf0e10cSrcweir     */
474cdf0e10cSrcweir     sal_Int32 lastIndexOf( sal_Char ch, sal_Int32 fromIndex ) const SAL_THROW(())
475cdf0e10cSrcweir     {
476cdf0e10cSrcweir         return rtl_str_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
477cdf0e10cSrcweir     }
478cdf0e10cSrcweir 
479cdf0e10cSrcweir     /**
480cdf0e10cSrcweir       Returns the index within this string of the first occurrence of the
481cdf0e10cSrcweir       specified substring, starting at the specified index.
482cdf0e10cSrcweir 
483cdf0e10cSrcweir       If str doesn't include any character, always -1 is
484cdf0e10cSrcweir       returned. This is also the case, if both strings are empty.
485cdf0e10cSrcweir 
486cdf0e10cSrcweir       @param    str         the substring to search for.
487cdf0e10cSrcweir       @param    fromIndex   the index to start the search from.
488cdf0e10cSrcweir       @return   If the string argument occurs one or more times as a substring
489cdf0e10cSrcweir                 within this string at the starting index, then the index
490cdf0e10cSrcweir                 of the first character of the first such substring is
491cdf0e10cSrcweir                 returned. If it does not occur as a substring starting
492cdf0e10cSrcweir                 at fromIndex or beyond, -1 is returned.
493cdf0e10cSrcweir     */
494cdf0e10cSrcweir     sal_Int32 indexOf( const OString & str, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
495cdf0e10cSrcweir     {
496cdf0e10cSrcweir         sal_Int32 ret = rtl_str_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
497cdf0e10cSrcweir                                                        str.pData->buffer, str.pData->length );
498cdf0e10cSrcweir         return (ret < 0 ? ret : ret+fromIndex);
499cdf0e10cSrcweir     }
500cdf0e10cSrcweir 
501cdf0e10cSrcweir     /**
502cdf0e10cSrcweir       Returns the index within this string of the last occurrence of
503cdf0e10cSrcweir       the specified substring, searching backward starting at the end.
504cdf0e10cSrcweir 
505cdf0e10cSrcweir       The returned index indicates the starting index of the substring
506cdf0e10cSrcweir       in this string.
507cdf0e10cSrcweir       If str doesn't include any character, always -1 is
508cdf0e10cSrcweir       returned. This is also the case, if both strings are empty.
509cdf0e10cSrcweir 
510cdf0e10cSrcweir       @param    str         the substring to search for.
511cdf0e10cSrcweir       @return   If the string argument occurs one or more times as a substring
512cdf0e10cSrcweir                 within this string, then the index of the first character of
513cdf0e10cSrcweir                 the last such substring is returned. If it does not occur as
514cdf0e10cSrcweir                 a substring, -1 is returned.
515cdf0e10cSrcweir     */
516cdf0e10cSrcweir     sal_Int32 lastIndexOf( const OString & str ) const SAL_THROW(())
517cdf0e10cSrcweir     {
518cdf0e10cSrcweir         return rtl_str_lastIndexOfStr_WithLength( pData->buffer, pData->length,
519cdf0e10cSrcweir                                                   str.pData->buffer, str.pData->length );
520cdf0e10cSrcweir     }
521cdf0e10cSrcweir 
522cdf0e10cSrcweir     /**
523cdf0e10cSrcweir       Returns the index within this string of the last occurrence of
524cdf0e10cSrcweir       the specified substring, searching backward starting before the specified
525cdf0e10cSrcweir       index.
526cdf0e10cSrcweir 
527cdf0e10cSrcweir       The returned index indicates the starting index of the substring
528cdf0e10cSrcweir       in this string.
529cdf0e10cSrcweir       If str doesn't include any character, always -1 is
530cdf0e10cSrcweir       returned. This is also the case, if both strings are empty.
531cdf0e10cSrcweir 
532cdf0e10cSrcweir       @param    str         the substring to search for.
533cdf0e10cSrcweir       @param    fromIndex   the index before which to start the search.
534cdf0e10cSrcweir       @return   If the string argument occurs one or more times as a substring
535cdf0e10cSrcweir                 within this string before the starting index, then the index
536cdf0e10cSrcweir                 of the first character of the last such substring is
537cdf0e10cSrcweir                 returned. Otherwise, -1 is returned.
538cdf0e10cSrcweir     */
539cdf0e10cSrcweir     sal_Int32 lastIndexOf( const OString & str, sal_Int32 fromIndex ) const SAL_THROW(())
540cdf0e10cSrcweir     {
541cdf0e10cSrcweir         return rtl_str_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
542cdf0e10cSrcweir                                                   str.pData->buffer, str.pData->length );
543cdf0e10cSrcweir     }
544cdf0e10cSrcweir 
545cdf0e10cSrcweir     /**
546cdf0e10cSrcweir       Returns a new string that is a substring of this string.
547cdf0e10cSrcweir 
548cdf0e10cSrcweir       The substring begins at the specified beginIndex.  It is an error for
549cdf0e10cSrcweir       beginIndex to be negative or to be greater than the length of this string.
550cdf0e10cSrcweir 
551cdf0e10cSrcweir       @param     beginIndex   the beginning index, inclusive.
552cdf0e10cSrcweir       @return    the specified substring.
553cdf0e10cSrcweir     */
554cdf0e10cSrcweir     OString copy( sal_Int32 beginIndex ) const SAL_THROW(())
555cdf0e10cSrcweir     {
556cdf0e10cSrcweir         OSL_ASSERT(beginIndex >= 0 && beginIndex <= getLength());
557cdf0e10cSrcweir         if ( beginIndex == 0 )
558cdf0e10cSrcweir             return *this;
559cdf0e10cSrcweir         else
560cdf0e10cSrcweir         {
561cdf0e10cSrcweir             rtl_String* pNew = 0;
562cdf0e10cSrcweir             rtl_string_newFromStr_WithLength( &pNew, pData->buffer+beginIndex, getLength()-beginIndex );
563cdf0e10cSrcweir             return OString( pNew, (DO_NOT_ACQUIRE*)0 );
564cdf0e10cSrcweir         }
565cdf0e10cSrcweir     }
566cdf0e10cSrcweir 
567cdf0e10cSrcweir     /**
568cdf0e10cSrcweir       Returns a new string that is a substring of this string.
569cdf0e10cSrcweir 
570cdf0e10cSrcweir       The substring begins at the specified beginIndex and contains count
571cdf0e10cSrcweir       characters.  It is an error for either beginIndex or count to be negative,
572cdf0e10cSrcweir       or for beginIndex + count to be greater than the length of this string.
573cdf0e10cSrcweir 
574cdf0e10cSrcweir       @param     beginIndex   the beginning index, inclusive.
575cdf0e10cSrcweir       @param     count        the number of characters.
576cdf0e10cSrcweir       @return    the specified substring.
577cdf0e10cSrcweir     */
578cdf0e10cSrcweir     OString copy( sal_Int32 beginIndex, sal_Int32 count ) const SAL_THROW(())
579cdf0e10cSrcweir     {
580cdf0e10cSrcweir         OSL_ASSERT(beginIndex >= 0 && beginIndex <= getLength()
581cdf0e10cSrcweir                    && count >= 0 && count <= getLength() - beginIndex);
582cdf0e10cSrcweir         if ( (beginIndex == 0) && (count == getLength()) )
583cdf0e10cSrcweir             return *this;
584cdf0e10cSrcweir         else
585cdf0e10cSrcweir         {
586cdf0e10cSrcweir             rtl_String* pNew = 0;
587cdf0e10cSrcweir             rtl_string_newFromStr_WithLength( &pNew, pData->buffer+beginIndex, count );
588cdf0e10cSrcweir             return OString( pNew, (DO_NOT_ACQUIRE*)0 );
589cdf0e10cSrcweir         }
590cdf0e10cSrcweir     }
591cdf0e10cSrcweir 
592cdf0e10cSrcweir     /**
593cdf0e10cSrcweir       Concatenates the specified string to the end of this string.
594cdf0e10cSrcweir 
595cdf0e10cSrcweir       @param    str   the string that is concatenated to the end
596cdf0e10cSrcweir                       of this string.
597cdf0e10cSrcweir       @return   a string that represents the concatenation of this string
598cdf0e10cSrcweir                 followed by the string argument.
599cdf0e10cSrcweir     */
600cdf0e10cSrcweir     OString concat( const OString & str ) const SAL_THROW(())
601cdf0e10cSrcweir     {
602cdf0e10cSrcweir         rtl_String* pNew = 0;
603cdf0e10cSrcweir         rtl_string_newConcat( &pNew, pData, str.pData );
604cdf0e10cSrcweir         return OString( pNew, (DO_NOT_ACQUIRE*)0 );
605cdf0e10cSrcweir     }
606cdf0e10cSrcweir 
607cdf0e10cSrcweir     friend OString operator+( const OString & str1, const OString & str2  ) SAL_THROW(())
608cdf0e10cSrcweir     {
609cdf0e10cSrcweir         return str1.concat( str2 );
610cdf0e10cSrcweir     }
611cdf0e10cSrcweir 
612cdf0e10cSrcweir     /**
613cdf0e10cSrcweir       Returns a new string resulting from replacing n = count characters
614cdf0e10cSrcweir       from position index in this string with newStr.
615cdf0e10cSrcweir 
616cdf0e10cSrcweir       @param  index   the replacing index in str.
617cdf0e10cSrcweir                       The index must be greater or equal as 0 and
618cdf0e10cSrcweir                       less or equal as the length of the string.
619cdf0e10cSrcweir       @param  count   the count of charcters that will replaced
620cdf0e10cSrcweir                       The count must be greater or equal as 0 and
621cdf0e10cSrcweir                       less or equal as the length of the string minus index.
622cdf0e10cSrcweir       @param  newStr  the new substring.
623cdf0e10cSrcweir       @return the new string.
624cdf0e10cSrcweir     */
625cdf0e10cSrcweir     OString replaceAt( sal_Int32 index, sal_Int32 count, const OString& newStr ) const SAL_THROW(())
626cdf0e10cSrcweir     {
627cdf0e10cSrcweir         rtl_String* pNew = 0;
628cdf0e10cSrcweir         rtl_string_newReplaceStrAt( &pNew, pData, index, count, newStr.pData );
629cdf0e10cSrcweir         return OString( pNew, (DO_NOT_ACQUIRE*)0 );
630cdf0e10cSrcweir     }
631cdf0e10cSrcweir 
632cdf0e10cSrcweir     /**
633cdf0e10cSrcweir       Returns a new string resulting from replacing all occurrences of
634cdf0e10cSrcweir       oldChar in this string with newChar.
635cdf0e10cSrcweir 
636cdf0e10cSrcweir       If the character oldChar does not occur in the character sequence
637cdf0e10cSrcweir       represented by this object, then the string is assigned with
638cdf0e10cSrcweir       str.
639cdf0e10cSrcweir 
640cdf0e10cSrcweir       @param    oldChar     the old character.
641cdf0e10cSrcweir       @param    newChar     the new character.
642cdf0e10cSrcweir       @return   a string derived from this string by replacing every
643cdf0e10cSrcweir                 occurrence of oldChar with newChar.
644cdf0e10cSrcweir     */
645cdf0e10cSrcweir     OString replace( sal_Char oldChar, sal_Char newChar ) const SAL_THROW(())
646cdf0e10cSrcweir     {
647cdf0e10cSrcweir         rtl_String* pNew = 0;
648cdf0e10cSrcweir         rtl_string_newReplace( &pNew, pData, oldChar, newChar );
649cdf0e10cSrcweir         return OString( pNew, (DO_NOT_ACQUIRE*)0 );
650cdf0e10cSrcweir     }
651cdf0e10cSrcweir 
652cdf0e10cSrcweir     /**
653cdf0e10cSrcweir       Converts from this string all ASCII uppercase characters (65-90)
654cdf0e10cSrcweir       to ASCII lowercase characters (97-122).
655cdf0e10cSrcweir 
656cdf0e10cSrcweir       This function can't be used for language specific conversion.
657cdf0e10cSrcweir       If the string doesn't contain characters which must be converted,
658cdf0e10cSrcweir       then the new string is assigned with str.
659cdf0e10cSrcweir 
660cdf0e10cSrcweir       @return   the string, converted to ASCII lowercase.
661cdf0e10cSrcweir     */
662cdf0e10cSrcweir     OString toAsciiLowerCase() const SAL_THROW(())
663cdf0e10cSrcweir     {
664cdf0e10cSrcweir         rtl_String* pNew = 0;
665cdf0e10cSrcweir         rtl_string_newToAsciiLowerCase( &pNew, pData );
666cdf0e10cSrcweir         return OString( pNew, (DO_NOT_ACQUIRE*)0 );
667cdf0e10cSrcweir     }
668cdf0e10cSrcweir 
669cdf0e10cSrcweir     /**
670cdf0e10cSrcweir       Converts from this string all ASCII lowercase characters (97-122)
671cdf0e10cSrcweir       to ASCII uppercase characters (65-90).
672cdf0e10cSrcweir 
673cdf0e10cSrcweir       This function can't be used for language specific conversion.
674cdf0e10cSrcweir       If the string doesn't contain characters which must be converted,
675cdf0e10cSrcweir       then the new string is assigned with str.
676cdf0e10cSrcweir 
677cdf0e10cSrcweir       @return   the string, converted to ASCII uppercase.
678cdf0e10cSrcweir     */
679cdf0e10cSrcweir     OString toAsciiUpperCase() const SAL_THROW(())
680cdf0e10cSrcweir     {
681cdf0e10cSrcweir         rtl_String* pNew = 0;
682cdf0e10cSrcweir         rtl_string_newToAsciiUpperCase( &pNew, pData );
683cdf0e10cSrcweir         return OString( pNew, (DO_NOT_ACQUIRE*)0 );
684cdf0e10cSrcweir     }
685cdf0e10cSrcweir 
686cdf0e10cSrcweir     /**
687cdf0e10cSrcweir       Returns a new string resulting from removing white space from both ends
688cdf0e10cSrcweir       of the string.
689cdf0e10cSrcweir 
690cdf0e10cSrcweir       All characters that have codes less than or equal to
691cdf0e10cSrcweir       32 (the space character) are considered to be white space.
692cdf0e10cSrcweir       If the string doesn't contain white spaces at both ends,
693cdf0e10cSrcweir       then the new string is assigned with str.
694cdf0e10cSrcweir 
695cdf0e10cSrcweir       @return   the string, with white space removed from the front and end.
696cdf0e10cSrcweir     */
697cdf0e10cSrcweir     OString trim() const SAL_THROW(())
698cdf0e10cSrcweir     {
699cdf0e10cSrcweir         rtl_String* pNew = 0;
700cdf0e10cSrcweir         rtl_string_newTrim( &pNew, pData );
701cdf0e10cSrcweir         return OString( pNew, (DO_NOT_ACQUIRE*)0 );
702cdf0e10cSrcweir     }
703cdf0e10cSrcweir 
704cdf0e10cSrcweir     /**
705cdf0e10cSrcweir       Returns a token in the string.
706cdf0e10cSrcweir 
707cdf0e10cSrcweir       Example:
708cdf0e10cSrcweir         sal_Int32 nIndex = 0;
709cdf0e10cSrcweir         do
710cdf0e10cSrcweir         {
711cdf0e10cSrcweir             ...
712cdf0e10cSrcweir             OString aToken = aStr.getToken( 0, ';', nIndex );
713cdf0e10cSrcweir             ...
714cdf0e10cSrcweir         }
715cdf0e10cSrcweir         while ( nIndex >= 0 );
716cdf0e10cSrcweir 
717cdf0e10cSrcweir       @param    token       the number of the token to return.
718cdf0e10cSrcweir       @param    cTok        the character which seperate the tokens.
719cdf0e10cSrcweir       @param    index       the position at which the token is searched in the
720cdf0e10cSrcweir                             string.
721cdf0e10cSrcweir                             The index must not be greater thanthe length of the
722cdf0e10cSrcweir                             string.
723cdf0e10cSrcweir                             This param is set to the position of the
724cdf0e10cSrcweir                             next token or to -1, if it is the last token.
725cdf0e10cSrcweir       @return   the token; if either token or index is negative, an empty token
726cdf0e10cSrcweir                 is returned (and index is set to -1)
727cdf0e10cSrcweir     */
728cdf0e10cSrcweir     OString getToken( sal_Int32 token, sal_Char cTok, sal_Int32& index ) const SAL_THROW(())
729cdf0e10cSrcweir     {
730cdf0e10cSrcweir         rtl_String * pNew = 0;
731cdf0e10cSrcweir         index = rtl_string_getToken( &pNew, pData, token, cTok, index );
732cdf0e10cSrcweir         return OString( pNew, (DO_NOT_ACQUIRE *)0 );
733cdf0e10cSrcweir     }
734cdf0e10cSrcweir 
735cdf0e10cSrcweir     /**
736cdf0e10cSrcweir       Returns the Boolean value from this string.
737cdf0e10cSrcweir 
738cdf0e10cSrcweir       This function can't be used for language specific conversion.
739cdf0e10cSrcweir 
740cdf0e10cSrcweir       @return   sal_True, if the string is 1 or "True" in any ASCII case.
741cdf0e10cSrcweir                 sal_False in any other case.
742cdf0e10cSrcweir     */
743cdf0e10cSrcweir     sal_Bool toBoolean() const SAL_THROW(())
744cdf0e10cSrcweir     {
745cdf0e10cSrcweir         return rtl_str_toBoolean( pData->buffer );
746cdf0e10cSrcweir     }
747cdf0e10cSrcweir 
748cdf0e10cSrcweir     /**
749cdf0e10cSrcweir       Returns the first character from this string.
750cdf0e10cSrcweir 
751cdf0e10cSrcweir       @return   the first character from this string or 0, if this string
752cdf0e10cSrcweir                 is emptry.
753cdf0e10cSrcweir     */
754cdf0e10cSrcweir     sal_Char toChar() const SAL_THROW(())
755cdf0e10cSrcweir     {
756cdf0e10cSrcweir         return pData->buffer[0];
757cdf0e10cSrcweir     }
758cdf0e10cSrcweir 
759cdf0e10cSrcweir     /**
760cdf0e10cSrcweir       Returns the int32 value from this string.
761cdf0e10cSrcweir 
762cdf0e10cSrcweir       This function can't be used for language specific conversion.
763cdf0e10cSrcweir 
764cdf0e10cSrcweir       @param    radix       the radix (between 2 and 36)
765cdf0e10cSrcweir       @return   the int32 represented from this string.
766cdf0e10cSrcweir                 0 if this string represents no number.
767cdf0e10cSrcweir     */
768cdf0e10cSrcweir     sal_Int32 toInt32( sal_Int16 radix = 10 ) const SAL_THROW(())
769cdf0e10cSrcweir     {
770cdf0e10cSrcweir         return rtl_str_toInt32( pData->buffer, radix );
771cdf0e10cSrcweir     }
772cdf0e10cSrcweir 
773cdf0e10cSrcweir     /**
774cdf0e10cSrcweir       Returns the int64 value from this string.
775cdf0e10cSrcweir 
776cdf0e10cSrcweir       This function can't be used for language specific conversion.
777cdf0e10cSrcweir 
778cdf0e10cSrcweir       @param    radix       the radix (between 2 and 36)
779cdf0e10cSrcweir       @return   the int64 represented from this string.
780cdf0e10cSrcweir                 0 if this string represents no number.
781cdf0e10cSrcweir     */
782cdf0e10cSrcweir     sal_Int64 toInt64( sal_Int16 radix = 10 ) const SAL_THROW(())
783cdf0e10cSrcweir     {
784cdf0e10cSrcweir         return rtl_str_toInt64( pData->buffer, radix );
785cdf0e10cSrcweir     }
786cdf0e10cSrcweir 
787cdf0e10cSrcweir     /**
788cdf0e10cSrcweir       Returns the float value from this string.
789cdf0e10cSrcweir 
790cdf0e10cSrcweir       This function can't be used for language specific conversion.
791cdf0e10cSrcweir 
792cdf0e10cSrcweir       @return   the float represented from this string.
793cdf0e10cSrcweir                 0.0 if this string represents no number.
794cdf0e10cSrcweir     */
795cdf0e10cSrcweir     float toFloat() const SAL_THROW(())
796cdf0e10cSrcweir     {
797cdf0e10cSrcweir         return rtl_str_toFloat( pData->buffer );
798cdf0e10cSrcweir     }
799cdf0e10cSrcweir 
800cdf0e10cSrcweir     /**
801cdf0e10cSrcweir       Returns the double value from this string.
802cdf0e10cSrcweir 
803cdf0e10cSrcweir       This function can't be used for language specific conversion.
804cdf0e10cSrcweir 
805cdf0e10cSrcweir       @return   the double represented from this string.
806cdf0e10cSrcweir                 0.0 if this string represents no number.
807cdf0e10cSrcweir     */
808cdf0e10cSrcweir     double toDouble() const SAL_THROW(())
809cdf0e10cSrcweir     {
810cdf0e10cSrcweir         return rtl_str_toDouble( pData->buffer );
811cdf0e10cSrcweir     }
812cdf0e10cSrcweir 
813cdf0e10cSrcweir     /**
814cdf0e10cSrcweir       Returns the string representation of the sal_Bool argument.
815cdf0e10cSrcweir 
816cdf0e10cSrcweir       If the sal_Bool is true, the string "true" is returned.
817cdf0e10cSrcweir       If the sal_Bool is false, the string "false" is returned.
818cdf0e10cSrcweir       This function can't be used for language specific conversion.
819cdf0e10cSrcweir 
820cdf0e10cSrcweir       @param    b   a sal_Bool.
821cdf0e10cSrcweir       @return   a string with the string representation of the argument.
822cdf0e10cSrcweir     */
823cdf0e10cSrcweir     static OString valueOf( sal_Bool b ) SAL_THROW(())
824cdf0e10cSrcweir     {
825cdf0e10cSrcweir         sal_Char aBuf[RTL_STR_MAX_VALUEOFBOOLEAN];
826cdf0e10cSrcweir         rtl_String* pNewData = 0;
827cdf0e10cSrcweir         rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfBoolean( aBuf, b ) );
828cdf0e10cSrcweir         return OString( pNewData, (DO_NOT_ACQUIRE*)0 );
829cdf0e10cSrcweir     }
830cdf0e10cSrcweir 
831cdf0e10cSrcweir     /**
832cdf0e10cSrcweir       Returns the string representation of the char argument.
833cdf0e10cSrcweir 
834cdf0e10cSrcweir       @param    c   a character.
835cdf0e10cSrcweir       @return   a string with the string representation of the argument.
836cdf0e10cSrcweir     */
837cdf0e10cSrcweir     static OString valueOf( sal_Char c ) SAL_THROW(())
838cdf0e10cSrcweir     {
839cdf0e10cSrcweir         return OString( &c, 1 );
840cdf0e10cSrcweir     }
841cdf0e10cSrcweir 
842cdf0e10cSrcweir     /**
843cdf0e10cSrcweir       Returns the string representation of the int argument.
844cdf0e10cSrcweir 
845cdf0e10cSrcweir       This function can't be used for language specific conversion.
846cdf0e10cSrcweir 
847cdf0e10cSrcweir       @param    i           a int32.
848cdf0e10cSrcweir       @param    radix       the radix (between 2 and 36)
849cdf0e10cSrcweir       @return   a string with the string representation of the argument.
850cdf0e10cSrcweir     */
851cdf0e10cSrcweir     static OString valueOf( sal_Int32 i, sal_Int16 radix = 10 ) SAL_THROW(())
852cdf0e10cSrcweir     {
853cdf0e10cSrcweir         sal_Char aBuf[RTL_STR_MAX_VALUEOFINT32];
854cdf0e10cSrcweir         rtl_String* pNewData = 0;
855cdf0e10cSrcweir         rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfInt32( aBuf, i, radix ) );
856cdf0e10cSrcweir         return OString( pNewData, (DO_NOT_ACQUIRE*)0 );
857cdf0e10cSrcweir     }
858cdf0e10cSrcweir 
859cdf0e10cSrcweir     /**
860cdf0e10cSrcweir       Returns the string representation of the long argument.
861cdf0e10cSrcweir 
862cdf0e10cSrcweir       This function can't be used for language specific conversion.
863cdf0e10cSrcweir 
864cdf0e10cSrcweir       @param    ll          a int64.
865cdf0e10cSrcweir       @param    radix       the radix (between 2 and 36)
866cdf0e10cSrcweir       @return   a string with the string representation of the argument.
867cdf0e10cSrcweir     */
868cdf0e10cSrcweir     static OString valueOf( sal_Int64 ll, sal_Int16 radix = 10 ) SAL_THROW(())
869cdf0e10cSrcweir     {
870cdf0e10cSrcweir         sal_Char aBuf[RTL_STR_MAX_VALUEOFINT64];
871cdf0e10cSrcweir         rtl_String* pNewData = 0;
872cdf0e10cSrcweir         rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfInt64( aBuf, ll, radix ) );
873cdf0e10cSrcweir         return OString( pNewData, (DO_NOT_ACQUIRE*)0 );
874cdf0e10cSrcweir     }
875cdf0e10cSrcweir 
876cdf0e10cSrcweir     /**
877cdf0e10cSrcweir       Returns the string representation of the float argument.
878cdf0e10cSrcweir 
879cdf0e10cSrcweir       This function can't be used for language specific conversion.
880cdf0e10cSrcweir 
881cdf0e10cSrcweir       @param    f           a float.
882cdf0e10cSrcweir       @return   a string with the string representation of the argument.
883cdf0e10cSrcweir     */
884cdf0e10cSrcweir     static OString valueOf( float f ) SAL_THROW(())
885cdf0e10cSrcweir     {
886cdf0e10cSrcweir         sal_Char aBuf[RTL_STR_MAX_VALUEOFFLOAT];
887cdf0e10cSrcweir         rtl_String* pNewData = 0;
888cdf0e10cSrcweir         rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfFloat( aBuf, f ) );
889cdf0e10cSrcweir         return OString( pNewData, (DO_NOT_ACQUIRE*)0 );
890cdf0e10cSrcweir     }
891cdf0e10cSrcweir 
892cdf0e10cSrcweir     /**
893cdf0e10cSrcweir       Returns the string representation of the double argument.
894cdf0e10cSrcweir 
895cdf0e10cSrcweir       This function can't be used for language specific conversion.
896cdf0e10cSrcweir 
897cdf0e10cSrcweir       @param    d           a double.
898cdf0e10cSrcweir       @return   a string with the string representation of the argument.
899cdf0e10cSrcweir     */
900cdf0e10cSrcweir     static OString valueOf( double d ) SAL_THROW(())
901cdf0e10cSrcweir     {
902cdf0e10cSrcweir         sal_Char aBuf[RTL_STR_MAX_VALUEOFDOUBLE];
903cdf0e10cSrcweir         rtl_String* pNewData = 0;
904cdf0e10cSrcweir         rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfDouble( aBuf, d ) );
905cdf0e10cSrcweir         return OString( pNewData, (DO_NOT_ACQUIRE*)0 );
906cdf0e10cSrcweir     }
907cdf0e10cSrcweir };
908cdf0e10cSrcweir 
909cdf0e10cSrcweir /* ======================================================================= */
910cdf0e10cSrcweir 
911cdf0e10cSrcweir /** A helper to use OStrings with hash maps.
912cdf0e10cSrcweir 
913cdf0e10cSrcweir     Instances of this class are unary function objects that can be used as
914cdf0e10cSrcweir     hash function arguments to STLPort's hash_map and similar constructs.
915cdf0e10cSrcweir  */
916cdf0e10cSrcweir struct OStringHash
917cdf0e10cSrcweir {
918cdf0e10cSrcweir     /** Compute a hash code for a string.
919cdf0e10cSrcweir 
920cdf0e10cSrcweir         @param rString
921cdf0e10cSrcweir         a string.
922cdf0e10cSrcweir 
923cdf0e10cSrcweir         @return
924cdf0e10cSrcweir         a hash code for the string.  This hash code should not be stored
925cdf0e10cSrcweir         persistently, as its computation may change in later revisions.
926cdf0e10cSrcweir      */
927cdf0e10cSrcweir     size_t operator()( const rtl::OString& rString ) const
928cdf0e10cSrcweir         { return (size_t)rString.hashCode(); }
929cdf0e10cSrcweir };
930cdf0e10cSrcweir 
931cdf0e10cSrcweir /* ======================================================================= */
932cdf0e10cSrcweir 
933fda69661SHerbert Dürr /** Equality functor for classic c-strings (i.e. null-terminated char* strings) */
934fda69661SHerbert Dürr struct CStringEqual
935fda69661SHerbert Dürr {
936fda69661SHerbert Dürr 	bool operator()( const char* p1, const char* p2) const {
937fda69661SHerbert Dürr 		while( *p1)
938fda69661SHerbert Dürr 			if( *(p1++) != *(p2++))
939fda69661SHerbert Dürr 				return false;
940fda69661SHerbert Dürr 		return true;
941fda69661SHerbert Dürr 	}
942fda69661SHerbert Dürr };
943fda69661SHerbert Dürr 
944fda69661SHerbert Dürr /** Hashing functor for classic c-strings (i.e. null-terminated char* strings) */
945fda69661SHerbert Dürr struct CStringHash
946fda69661SHerbert Dürr {
947fda69661SHerbert Dürr 	size_t operator()( const char* p) const {
948fda69661SHerbert Dürr 		size_t n = 0;
949fda69661SHerbert Dürr 		while( *p)
950*b3f482f2SHerbert Dürr 			n += 4*n + *reinterpret_cast<const unsigned char*>(p++);
951fda69661SHerbert Dürr 		return n;
952fda69661SHerbert Dürr 	}
953fda69661SHerbert Dürr };
954fda69661SHerbert Dürr 
955cdf0e10cSrcweir } /* Namespace */
956cdf0e10cSrcweir 
957cdf0e10cSrcweir #endif /* __cplusplus */
958cdf0e10cSrcweir 
959cdf0e10cSrcweir #endif /* _RTL_STRING_HXX_ */
960fda69661SHerbert Dürr 
961