xref: /aoo42x/main/sal/inc/rtl/string.hxx (revision 24c56ab9)
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
10565d668cSAndrew Rist  *
11565d668cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12565d668cSAndrew Rist  *
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.
19565d668cSAndrew Rist  *
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 
222*24c56ab9SHerbert Dürr private:
223cdf0e10cSrcweir     /**
224cdf0e10cSrcweir       Returns a pointer to the characters of this string.
225cdf0e10cSrcweir 
226*24c56ab9SHerbert Dürr       NOTE: the implicit cast to a char pointer is obsolete
227*24c56ab9SHerbert Dürr             because it is too dangerous #i123068#
228*24c56ab9SHerbert Dürr 
229cdf0e10cSrcweir       <p>The returned pointer is not guaranteed to point to a null-terminated
230cdf0e10cSrcweir       byte string.  Note that this string object may contain embedded null
231cdf0e10cSrcweir       characters, which will thus also be embedded in the returned byte
232cdf0e10cSrcweir       string.</p>
233cdf0e10cSrcweir 
234cdf0e10cSrcweir       @return a pointer to a (not necessarily null-terminated) byte string
235cdf0e10cSrcweir       representing the characters of this string object.
236cdf0e10cSrcweir     */
237cdf0e10cSrcweir     operator const sal_Char *() const SAL_THROW(()) { return pData->buffer; }
238*24c56ab9SHerbert Dürr public:
239*24c56ab9SHerbert Dürr     /** Returns a reference to a character of this string. */
240*24c56ab9SHerbert Dürr     sal_Char& operator[]( int n ) { return pData->buffer[n]; }
241*24c56ab9SHerbert Dürr     /** Returns a const reference to a character of this string. */
242*24c56ab9SHerbert Dürr     const sal_Char& operator[]( int n ) const { return pData->buffer[n]; }
243*24c56ab9SHerbert Dürr     /** Returns a bool indicating whether this string is empty. */
244*24c56ab9SHerbert Dürr     bool isEmpty() const { return (pData->length == 0); }
245cdf0e10cSrcweir 
246cdf0e10cSrcweir     /**
247cdf0e10cSrcweir       Returns a pointer to the characters of this string.
248cdf0e10cSrcweir 
249cdf0e10cSrcweir       <p>The returned pointer is guaranteed to point to a null-terminated byte
250cdf0e10cSrcweir       string.  But note that this string object may contain embedded null
251cdf0e10cSrcweir       characters, which will thus also be embedded in the returned
252cdf0e10cSrcweir       null-terminated byte string.</p>
253cdf0e10cSrcweir 
254cdf0e10cSrcweir       @return a pointer to a null-terminated byte string representing the
255cdf0e10cSrcweir       characters of this string object.
256cdf0e10cSrcweir     */
257cdf0e10cSrcweir     const sal_Char * getStr() const SAL_THROW(()) { return pData->buffer; }
258cdf0e10cSrcweir 
259cdf0e10cSrcweir     /**
260cdf0e10cSrcweir       Compares two strings.
261cdf0e10cSrcweir 
262cdf0e10cSrcweir       The comparison is based on the numeric value of each character in
263cdf0e10cSrcweir       the strings and return a value indicating their relationship.
264cdf0e10cSrcweir       This function can't be used for language specific sorting.
265cdf0e10cSrcweir 
266cdf0e10cSrcweir       @param    str         the object to be compared.
267cdf0e10cSrcweir       @return   0 - if both strings are equal
268cdf0e10cSrcweir                 < 0 - if this string is less than the string argument
269cdf0e10cSrcweir                 > 0 - if this string is greater than the string argument
270cdf0e10cSrcweir     */
271cdf0e10cSrcweir     sal_Int32 compareTo( const OString & str ) const SAL_THROW(())
272cdf0e10cSrcweir     {
273cdf0e10cSrcweir         return rtl_str_compare_WithLength( pData->buffer, pData->length,
274cdf0e10cSrcweir                                            str.pData->buffer, str.pData->length );
275cdf0e10cSrcweir     }
276cdf0e10cSrcweir 
277cdf0e10cSrcweir     /**
278cdf0e10cSrcweir       Compares two strings with an maximum count of characters.
279cdf0e10cSrcweir 
280cdf0e10cSrcweir       The comparison is based on the numeric value of each character in
281cdf0e10cSrcweir       the strings and return a value indicating their relationship.
282cdf0e10cSrcweir       This function can't be used for language specific sorting.
283cdf0e10cSrcweir 
284cdf0e10cSrcweir       @param    str         the object to be compared.
285cdf0e10cSrcweir       @param    maxLength   the maximum count of characters to be compared.
286cdf0e10cSrcweir       @return   0 - if both strings are equal
287cdf0e10cSrcweir                 < 0 - if this string is less than the string argument
288cdf0e10cSrcweir                 > 0 - if this string is greater than the string argument
289cdf0e10cSrcweir     */
290cdf0e10cSrcweir     sal_Int32 compareTo( const OString & rObj, sal_Int32 maxLength ) const SAL_THROW(())
291cdf0e10cSrcweir     {
292cdf0e10cSrcweir         return rtl_str_shortenedCompare_WithLength( pData->buffer, pData->length,
293cdf0e10cSrcweir                                                     rObj.pData->buffer, rObj.pData->length, maxLength );
294cdf0e10cSrcweir     }
295cdf0e10cSrcweir 
296cdf0e10cSrcweir     /**
297cdf0e10cSrcweir       Compares two strings in reverse order.
298cdf0e10cSrcweir 
299cdf0e10cSrcweir       The comparison is based on the numeric value of each character in
300cdf0e10cSrcweir       the strings and return a value indicating their relationship.
301cdf0e10cSrcweir       This function can't be used for language specific sorting.
302cdf0e10cSrcweir 
303cdf0e10cSrcweir       @param    str         the object to be compared.
304cdf0e10cSrcweir       @return   0 - if both strings are equal
305cdf0e10cSrcweir                 < 0 - if this string is less than the string argument
306cdf0e10cSrcweir                 > 0 - if this string is greater than the string argument
307cdf0e10cSrcweir     */
308cdf0e10cSrcweir     sal_Int32 reverseCompareTo( const OString & str ) const SAL_THROW(())
309cdf0e10cSrcweir     {
310cdf0e10cSrcweir         return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
311cdf0e10cSrcweir                                                   str.pData->buffer, str.pData->length );
312cdf0e10cSrcweir     }
313cdf0e10cSrcweir 
314cdf0e10cSrcweir     /**
315cdf0e10cSrcweir       Perform a comparison of two strings.
316cdf0e10cSrcweir 
317cdf0e10cSrcweir       The result is true if and only if second string
318cdf0e10cSrcweir       represents the same sequence of characters as the first string.
319cdf0e10cSrcweir       This function can't be used for language specific comparison.
320cdf0e10cSrcweir 
321cdf0e10cSrcweir       @param    str         the object to be compared.
322cdf0e10cSrcweir       @return   sal_True if the strings are equal;
323cdf0e10cSrcweir                 sal_False, otherwise.
324cdf0e10cSrcweir     */
325cdf0e10cSrcweir     sal_Bool equals( const OString & str ) const SAL_THROW(())
326cdf0e10cSrcweir     {
327cdf0e10cSrcweir         if ( pData->length != str.pData->length )
328cdf0e10cSrcweir             return sal_False;
329cdf0e10cSrcweir         if ( pData == str.pData )
330cdf0e10cSrcweir             return sal_True;
331cdf0e10cSrcweir         return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
332cdf0e10cSrcweir                                                   str.pData->buffer, str.pData->length ) == 0;
333cdf0e10cSrcweir     }
334cdf0e10cSrcweir 
335cdf0e10cSrcweir     /**
336cdf0e10cSrcweir       Perform a ASCII lowercase comparison of two strings.
337cdf0e10cSrcweir 
338cdf0e10cSrcweir       The result is true if and only if second string
339cdf0e10cSrcweir       represents the same sequence of characters as the first string,
340cdf0e10cSrcweir       ignoring the case.
341cdf0e10cSrcweir       Character values between 65 and 90 (ASCII A-Z) are interpreted as
342cdf0e10cSrcweir       values between 97 and 122 (ASCII a-z).
343cdf0e10cSrcweir       This function can't be used for language specific comparison.
344cdf0e10cSrcweir 
345cdf0e10cSrcweir       @param    str         the object to be compared.
346cdf0e10cSrcweir       @return   sal_True if the strings are equal;
347cdf0e10cSrcweir                 sal_False, otherwise.
348cdf0e10cSrcweir     */
349cdf0e10cSrcweir     sal_Bool equalsIgnoreAsciiCase( const OString & str ) const SAL_THROW(())
350cdf0e10cSrcweir     {
351cdf0e10cSrcweir         if ( pData->length != str.pData->length )
352cdf0e10cSrcweir             return sal_False;
353cdf0e10cSrcweir         if ( pData == str.pData )
354cdf0e10cSrcweir             return sal_True;
355cdf0e10cSrcweir         return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
356cdf0e10cSrcweir                                                           str.pData->buffer, str.pData->length ) == 0;
357cdf0e10cSrcweir     }
358cdf0e10cSrcweir 
359cdf0e10cSrcweir     /**
360cdf0e10cSrcweir       Match against a substring appearing in this string.
361cdf0e10cSrcweir 
362cdf0e10cSrcweir       The result is true if and only if the second string appears as a substring
363cdf0e10cSrcweir       of this string, at the given position.
364cdf0e10cSrcweir       This function can't be used for language specific comparison.
365cdf0e10cSrcweir 
366cdf0e10cSrcweir       @param    str         the object (substring) to be compared.
367cdf0e10cSrcweir       @param    fromIndex   the index to start the comparion from.
368cdf0e10cSrcweir                             The index must be greater or equal than 0
369cdf0e10cSrcweir                             and less or equal as the string length.
370cdf0e10cSrcweir       @return   sal_True if str match with the characters in the string
371cdf0e10cSrcweir                 at the given position;
372cdf0e10cSrcweir                 sal_False, otherwise.
373cdf0e10cSrcweir     */
374cdf0e10cSrcweir     sal_Bool match( const OString & str, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
375cdf0e10cSrcweir     {
376cdf0e10cSrcweir         return rtl_str_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
377cdf0e10cSrcweir                                                     str.pData->buffer, str.pData->length, str.pData->length ) == 0;
378cdf0e10cSrcweir     }
379cdf0e10cSrcweir 
380cdf0e10cSrcweir     /**
381cdf0e10cSrcweir       Match against a substring appearing in this string, ignoring the case of
382cdf0e10cSrcweir       ASCII letters.
383cdf0e10cSrcweir 
384cdf0e10cSrcweir       The result is true if and only if the second string appears as a substring
385cdf0e10cSrcweir       of this string, at the given position.
386cdf0e10cSrcweir       Character values between 65 and 90 (ASCII A-Z) are interpreted as
387cdf0e10cSrcweir       values between 97 and 122 (ASCII a-z).
388cdf0e10cSrcweir       This function can't be used for language specific comparison.
389cdf0e10cSrcweir 
390cdf0e10cSrcweir       @param    str         the object (substring) to be compared.
391cdf0e10cSrcweir       @param    fromIndex   the index to start the comparion from.
392cdf0e10cSrcweir                             The index must be greater or equal than 0
393cdf0e10cSrcweir                             and less or equal as the string length.
394cdf0e10cSrcweir       @return   sal_True if str match with the characters in the string
395cdf0e10cSrcweir                 at the given position;
396cdf0e10cSrcweir                 sal_False, otherwise.
397cdf0e10cSrcweir     */
398cdf0e10cSrcweir     sal_Bool matchIgnoreAsciiCase( const OString & str, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
399cdf0e10cSrcweir     {
400cdf0e10cSrcweir         return rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
401cdf0e10cSrcweir                                                                    str.pData->buffer, str.pData->length,
402cdf0e10cSrcweir                                                                    str.pData->length ) == 0;
403cdf0e10cSrcweir     }
404cdf0e10cSrcweir 
405cdf0e10cSrcweir     friend sal_Bool     operator == ( const OString& rStr1, const OString& rStr2 ) SAL_THROW(())
406cdf0e10cSrcweir                         { return rStr1.getLength() == rStr2.getLength() && rStr1.compareTo( rStr2 ) == 0; }
407cdf0e10cSrcweir     friend sal_Bool     operator == ( const OString& rStr1, const sal_Char * pStr2 ) SAL_THROW(())
408cdf0e10cSrcweir                         { return rStr1.compareTo( pStr2 ) == 0; }
409cdf0e10cSrcweir     friend sal_Bool     operator == ( const sal_Char * pStr1,   const OString& rStr2 ) SAL_THROW(())
410cdf0e10cSrcweir                         { return OString( pStr1 ).compareTo( rStr2 ) == 0; }
411cdf0e10cSrcweir 
412cdf0e10cSrcweir     friend sal_Bool     operator != ( const OString& rStr1,     const OString& rStr2 ) SAL_THROW(())
413cdf0e10cSrcweir                         { return !(operator == ( rStr1, rStr2 )); }
414cdf0e10cSrcweir     friend sal_Bool     operator != ( const OString& rStr1, const sal_Char * pStr2 ) SAL_THROW(())
415cdf0e10cSrcweir                         { return !(operator == ( rStr1, pStr2 )); }
416cdf0e10cSrcweir     friend sal_Bool     operator != ( const sal_Char * pStr1,   const OString& rStr2 ) SAL_THROW(())
417cdf0e10cSrcweir                         { return !(operator == ( pStr1, rStr2 )); }
418cdf0e10cSrcweir 
419cdf0e10cSrcweir     friend sal_Bool     operator <  ( const OString& rStr1,    const OString& rStr2 ) SAL_THROW(())
420cdf0e10cSrcweir                         { return rStr1.compareTo( rStr2 ) < 0; }
421cdf0e10cSrcweir     friend sal_Bool     operator >  ( const OString& rStr1,    const OString& rStr2 ) SAL_THROW(())
422cdf0e10cSrcweir                         { return rStr1.compareTo( rStr2 ) > 0; }
423cdf0e10cSrcweir     friend sal_Bool     operator <= ( const OString& rStr1,    const OString& rStr2 ) SAL_THROW(())
424cdf0e10cSrcweir                         { return rStr1.compareTo( rStr2 ) <= 0; }
425cdf0e10cSrcweir     friend sal_Bool     operator >= ( const OString& rStr1,    const OString& rStr2 ) SAL_THROW(())
426cdf0e10cSrcweir                         { return rStr1.compareTo( rStr2 ) >= 0; }
427cdf0e10cSrcweir 
428cdf0e10cSrcweir     /**
429cdf0e10cSrcweir       Returns a hashcode for this string.
430cdf0e10cSrcweir 
431cdf0e10cSrcweir       @return   a hash code value for this object.
432cdf0e10cSrcweir 
433b597708bSHerbert Dürr       @see rtl::OStringHash for convenient use of hash_map / unordered_map
434cdf0e10cSrcweir     */
435cdf0e10cSrcweir     sal_Int32 hashCode() const SAL_THROW(())
436cdf0e10cSrcweir     {
437cdf0e10cSrcweir         return rtl_str_hashCode_WithLength( pData->buffer, pData->length );
438cdf0e10cSrcweir     }
439cdf0e10cSrcweir 
440cdf0e10cSrcweir     /**
441cdf0e10cSrcweir       Returns the index within this string of the first occurrence of the
442cdf0e10cSrcweir       specified character, starting the search at the specified index.
443cdf0e10cSrcweir 
444cdf0e10cSrcweir       @param    ch          character to be located.
445cdf0e10cSrcweir       @param    fromIndex   the index to start the search from.
446cdf0e10cSrcweir                             The index must be greater or equal than 0
447cdf0e10cSrcweir                             and less or equal as the string length.
448cdf0e10cSrcweir       @return   the index of the first occurrence of the character in the
449cdf0e10cSrcweir                 character sequence represented by this string that is
450cdf0e10cSrcweir                 greater than or equal to fromIndex, or
451cdf0e10cSrcweir                 -1 if the character does not occur.
452cdf0e10cSrcweir     */
453cdf0e10cSrcweir     sal_Int32 indexOf( sal_Char ch, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
454cdf0e10cSrcweir     {
455cdf0e10cSrcweir         sal_Int32 ret = rtl_str_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
456cdf0e10cSrcweir         return (ret < 0 ? ret : ret+fromIndex);
457cdf0e10cSrcweir     }
458cdf0e10cSrcweir 
459cdf0e10cSrcweir     /**
460cdf0e10cSrcweir       Returns the index within this string of the last occurrence of the
461cdf0e10cSrcweir       specified character, searching backward starting at the end.
462cdf0e10cSrcweir 
463cdf0e10cSrcweir       @param    ch          character to be located.
464cdf0e10cSrcweir       @return   the index of the last occurrence of the character in the
465cdf0e10cSrcweir                 character sequence represented by this string, or
466cdf0e10cSrcweir                 -1 if the character does not occur.
467cdf0e10cSrcweir     */
468cdf0e10cSrcweir     sal_Int32 lastIndexOf( sal_Char ch ) const SAL_THROW(())
469cdf0e10cSrcweir     {
470cdf0e10cSrcweir         return rtl_str_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
471cdf0e10cSrcweir     }
472cdf0e10cSrcweir 
473cdf0e10cSrcweir     /**
474cdf0e10cSrcweir       Returns the index within this string of the last occurrence of the
475cdf0e10cSrcweir       specified character, searching backward starting before the specified
476cdf0e10cSrcweir       index.
477cdf0e10cSrcweir 
478cdf0e10cSrcweir       @param    ch          character to be located.
479cdf0e10cSrcweir       @param    fromIndex   the index before which to start the search.
480cdf0e10cSrcweir       @return   the index of the last occurrence of the character in the
481cdf0e10cSrcweir                 character sequence represented by this string that
482cdf0e10cSrcweir                 is less than fromIndex, or -1
483cdf0e10cSrcweir                 if the character does not occur before that point.
484cdf0e10cSrcweir     */
485cdf0e10cSrcweir     sal_Int32 lastIndexOf( sal_Char ch, sal_Int32 fromIndex ) const SAL_THROW(())
486cdf0e10cSrcweir     {
487cdf0e10cSrcweir         return rtl_str_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
488cdf0e10cSrcweir     }
489cdf0e10cSrcweir 
490cdf0e10cSrcweir     /**
491cdf0e10cSrcweir       Returns the index within this string of the first occurrence of the
492cdf0e10cSrcweir       specified substring, starting at the specified index.
493cdf0e10cSrcweir 
494cdf0e10cSrcweir       If str doesn't include any character, always -1 is
495cdf0e10cSrcweir       returned. This is also the case, if both strings are empty.
496cdf0e10cSrcweir 
497cdf0e10cSrcweir       @param    str         the substring to search for.
498cdf0e10cSrcweir       @param    fromIndex   the index to start the search from.
499cdf0e10cSrcweir       @return   If the string argument occurs one or more times as a substring
500cdf0e10cSrcweir                 within this string at the starting index, then the index
501cdf0e10cSrcweir                 of the first character of the first such substring is
502cdf0e10cSrcweir                 returned. If it does not occur as a substring starting
503cdf0e10cSrcweir                 at fromIndex or beyond, -1 is returned.
504cdf0e10cSrcweir     */
505cdf0e10cSrcweir     sal_Int32 indexOf( const OString & str, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
506cdf0e10cSrcweir     {
507cdf0e10cSrcweir         sal_Int32 ret = rtl_str_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
508cdf0e10cSrcweir                                                        str.pData->buffer, str.pData->length );
509cdf0e10cSrcweir         return (ret < 0 ? ret : ret+fromIndex);
510cdf0e10cSrcweir     }
511cdf0e10cSrcweir 
512cdf0e10cSrcweir     /**
513cdf0e10cSrcweir       Returns the index within this string of the last occurrence of
514cdf0e10cSrcweir       the specified substring, searching backward starting at the end.
515cdf0e10cSrcweir 
516cdf0e10cSrcweir       The returned index indicates the starting index of the substring
517cdf0e10cSrcweir       in this string.
518cdf0e10cSrcweir       If str doesn't include any character, always -1 is
519cdf0e10cSrcweir       returned. This is also the case, if both strings are empty.
520cdf0e10cSrcweir 
521cdf0e10cSrcweir       @param    str         the substring to search for.
522cdf0e10cSrcweir       @return   If the string argument occurs one or more times as a substring
523cdf0e10cSrcweir                 within this string, then the index of the first character of
524cdf0e10cSrcweir                 the last such substring is returned. If it does not occur as
525cdf0e10cSrcweir                 a substring, -1 is returned.
526cdf0e10cSrcweir     */
527cdf0e10cSrcweir     sal_Int32 lastIndexOf( const OString & str ) const SAL_THROW(())
528cdf0e10cSrcweir     {
529cdf0e10cSrcweir         return rtl_str_lastIndexOfStr_WithLength( pData->buffer, pData->length,
530cdf0e10cSrcweir                                                   str.pData->buffer, str.pData->length );
531cdf0e10cSrcweir     }
532cdf0e10cSrcweir 
533cdf0e10cSrcweir     /**
534cdf0e10cSrcweir       Returns the index within this string of the last occurrence of
535cdf0e10cSrcweir       the specified substring, searching backward starting before the specified
536cdf0e10cSrcweir       index.
537cdf0e10cSrcweir 
538cdf0e10cSrcweir       The returned index indicates the starting index of the substring
539cdf0e10cSrcweir       in this string.
540cdf0e10cSrcweir       If str doesn't include any character, always -1 is
541cdf0e10cSrcweir       returned. This is also the case, if both strings are empty.
542cdf0e10cSrcweir 
543cdf0e10cSrcweir       @param    str         the substring to search for.
544cdf0e10cSrcweir       @param    fromIndex   the index before which to start the search.
545cdf0e10cSrcweir       @return   If the string argument occurs one or more times as a substring
546cdf0e10cSrcweir                 within this string before the starting index, then the index
547cdf0e10cSrcweir                 of the first character of the last such substring is
548cdf0e10cSrcweir                 returned. Otherwise, -1 is returned.
549cdf0e10cSrcweir     */
550cdf0e10cSrcweir     sal_Int32 lastIndexOf( const OString & str, sal_Int32 fromIndex ) const SAL_THROW(())
551cdf0e10cSrcweir     {
552cdf0e10cSrcweir         return rtl_str_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
553cdf0e10cSrcweir                                                   str.pData->buffer, str.pData->length );
554cdf0e10cSrcweir     }
555cdf0e10cSrcweir 
556cdf0e10cSrcweir     /**
557cdf0e10cSrcweir       Returns a new string that is a substring of this string.
558cdf0e10cSrcweir 
559cdf0e10cSrcweir       The substring begins at the specified beginIndex.  It is an error for
560cdf0e10cSrcweir       beginIndex to be negative or to be greater than the length of this string.
561cdf0e10cSrcweir 
562cdf0e10cSrcweir       @param     beginIndex   the beginning index, inclusive.
563cdf0e10cSrcweir       @return    the specified substring.
564cdf0e10cSrcweir     */
565cdf0e10cSrcweir     OString copy( sal_Int32 beginIndex ) const SAL_THROW(())
566cdf0e10cSrcweir     {
567cdf0e10cSrcweir         OSL_ASSERT(beginIndex >= 0 && beginIndex <= getLength());
568cdf0e10cSrcweir         if ( beginIndex == 0 )
569cdf0e10cSrcweir             return *this;
570cdf0e10cSrcweir         else
571cdf0e10cSrcweir         {
572cdf0e10cSrcweir             rtl_String* pNew = 0;
573cdf0e10cSrcweir             rtl_string_newFromStr_WithLength( &pNew, pData->buffer+beginIndex, getLength()-beginIndex );
574cdf0e10cSrcweir             return OString( pNew, (DO_NOT_ACQUIRE*)0 );
575cdf0e10cSrcweir         }
576cdf0e10cSrcweir     }
577cdf0e10cSrcweir 
578cdf0e10cSrcweir     /**
579cdf0e10cSrcweir       Returns a new string that is a substring of this string.
580cdf0e10cSrcweir 
581cdf0e10cSrcweir       The substring begins at the specified beginIndex and contains count
582cdf0e10cSrcweir       characters.  It is an error for either beginIndex or count to be negative,
583cdf0e10cSrcweir       or for beginIndex + count to be greater than the length of this string.
584cdf0e10cSrcweir 
585cdf0e10cSrcweir       @param     beginIndex   the beginning index, inclusive.
586cdf0e10cSrcweir       @param     count        the number of characters.
587cdf0e10cSrcweir       @return    the specified substring.
588cdf0e10cSrcweir     */
589cdf0e10cSrcweir     OString copy( sal_Int32 beginIndex, sal_Int32 count ) const SAL_THROW(())
590cdf0e10cSrcweir     {
591cdf0e10cSrcweir         OSL_ASSERT(beginIndex >= 0 && beginIndex <= getLength()
592cdf0e10cSrcweir                    && count >= 0 && count <= getLength() - beginIndex);
593cdf0e10cSrcweir         if ( (beginIndex == 0) && (count == getLength()) )
594cdf0e10cSrcweir             return *this;
595cdf0e10cSrcweir         else
596cdf0e10cSrcweir         {
597cdf0e10cSrcweir             rtl_String* pNew = 0;
598cdf0e10cSrcweir             rtl_string_newFromStr_WithLength( &pNew, pData->buffer+beginIndex, count );
599cdf0e10cSrcweir             return OString( pNew, (DO_NOT_ACQUIRE*)0 );
600cdf0e10cSrcweir         }
601cdf0e10cSrcweir     }
602cdf0e10cSrcweir 
603cdf0e10cSrcweir     /**
604cdf0e10cSrcweir       Concatenates the specified string to the end of this string.
605cdf0e10cSrcweir 
606cdf0e10cSrcweir       @param    str   the string that is concatenated to the end
607cdf0e10cSrcweir                       of this string.
608cdf0e10cSrcweir       @return   a string that represents the concatenation of this string
609cdf0e10cSrcweir                 followed by the string argument.
610cdf0e10cSrcweir     */
611cdf0e10cSrcweir     OString concat( const OString & str ) const SAL_THROW(())
612cdf0e10cSrcweir     {
613cdf0e10cSrcweir         rtl_String* pNew = 0;
614cdf0e10cSrcweir         rtl_string_newConcat( &pNew, pData, str.pData );
615cdf0e10cSrcweir         return OString( pNew, (DO_NOT_ACQUIRE*)0 );
616cdf0e10cSrcweir     }
617cdf0e10cSrcweir 
618cdf0e10cSrcweir     friend OString operator+( const OString & str1, const OString & str2  ) SAL_THROW(())
619cdf0e10cSrcweir     {
620cdf0e10cSrcweir         return str1.concat( str2 );
621cdf0e10cSrcweir     }
622cdf0e10cSrcweir 
623cdf0e10cSrcweir     /**
624cdf0e10cSrcweir       Returns a new string resulting from replacing n = count characters
625cdf0e10cSrcweir       from position index in this string with newStr.
626cdf0e10cSrcweir 
627cdf0e10cSrcweir       @param  index   the replacing index in str.
628cdf0e10cSrcweir                       The index must be greater or equal as 0 and
629cdf0e10cSrcweir                       less or equal as the length of the string.
630cdf0e10cSrcweir       @param  count   the count of charcters that will replaced
631cdf0e10cSrcweir                       The count must be greater or equal as 0 and
632cdf0e10cSrcweir                       less or equal as the length of the string minus index.
633cdf0e10cSrcweir       @param  newStr  the new substring.
634cdf0e10cSrcweir       @return the new string.
635cdf0e10cSrcweir     */
636cdf0e10cSrcweir     OString replaceAt( sal_Int32 index, sal_Int32 count, const OString& newStr ) const SAL_THROW(())
637cdf0e10cSrcweir     {
638cdf0e10cSrcweir         rtl_String* pNew = 0;
639cdf0e10cSrcweir         rtl_string_newReplaceStrAt( &pNew, pData, index, count, newStr.pData );
640cdf0e10cSrcweir         return OString( pNew, (DO_NOT_ACQUIRE*)0 );
641cdf0e10cSrcweir     }
642cdf0e10cSrcweir 
643cdf0e10cSrcweir     /**
644cdf0e10cSrcweir       Returns a new string resulting from replacing all occurrences of
645cdf0e10cSrcweir       oldChar in this string with newChar.
646cdf0e10cSrcweir 
647cdf0e10cSrcweir       If the character oldChar does not occur in the character sequence
648cdf0e10cSrcweir       represented by this object, then the string is assigned with
649cdf0e10cSrcweir       str.
650cdf0e10cSrcweir 
651cdf0e10cSrcweir       @param    oldChar     the old character.
652cdf0e10cSrcweir       @param    newChar     the new character.
653cdf0e10cSrcweir       @return   a string derived from this string by replacing every
654cdf0e10cSrcweir                 occurrence of oldChar with newChar.
655cdf0e10cSrcweir     */
656cdf0e10cSrcweir     OString replace( sal_Char oldChar, sal_Char newChar ) const SAL_THROW(())
657cdf0e10cSrcweir     {
658cdf0e10cSrcweir         rtl_String* pNew = 0;
659cdf0e10cSrcweir         rtl_string_newReplace( &pNew, pData, oldChar, newChar );
660cdf0e10cSrcweir         return OString( pNew, (DO_NOT_ACQUIRE*)0 );
661cdf0e10cSrcweir     }
662cdf0e10cSrcweir 
663cdf0e10cSrcweir     /**
664cdf0e10cSrcweir       Converts from this string all ASCII uppercase characters (65-90)
665cdf0e10cSrcweir       to ASCII lowercase characters (97-122).
666cdf0e10cSrcweir 
667cdf0e10cSrcweir       This function can't be used for language specific conversion.
668cdf0e10cSrcweir       If the string doesn't contain characters which must be converted,
669cdf0e10cSrcweir       then the new string is assigned with str.
670cdf0e10cSrcweir 
671cdf0e10cSrcweir       @return   the string, converted to ASCII lowercase.
672cdf0e10cSrcweir     */
673cdf0e10cSrcweir     OString toAsciiLowerCase() const SAL_THROW(())
674cdf0e10cSrcweir     {
675cdf0e10cSrcweir         rtl_String* pNew = 0;
676cdf0e10cSrcweir         rtl_string_newToAsciiLowerCase( &pNew, pData );
677cdf0e10cSrcweir         return OString( pNew, (DO_NOT_ACQUIRE*)0 );
678cdf0e10cSrcweir     }
679cdf0e10cSrcweir 
680cdf0e10cSrcweir     /**
681cdf0e10cSrcweir       Converts from this string all ASCII lowercase characters (97-122)
682cdf0e10cSrcweir       to ASCII uppercase characters (65-90).
683cdf0e10cSrcweir 
684cdf0e10cSrcweir       This function can't be used for language specific conversion.
685cdf0e10cSrcweir       If the string doesn't contain characters which must be converted,
686cdf0e10cSrcweir       then the new string is assigned with str.
687cdf0e10cSrcweir 
688cdf0e10cSrcweir       @return   the string, converted to ASCII uppercase.
689cdf0e10cSrcweir     */
690cdf0e10cSrcweir     OString toAsciiUpperCase() const SAL_THROW(())
691cdf0e10cSrcweir     {
692cdf0e10cSrcweir         rtl_String* pNew = 0;
693cdf0e10cSrcweir         rtl_string_newToAsciiUpperCase( &pNew, pData );
694cdf0e10cSrcweir         return OString( pNew, (DO_NOT_ACQUIRE*)0 );
695cdf0e10cSrcweir     }
696cdf0e10cSrcweir 
697cdf0e10cSrcweir     /**
698cdf0e10cSrcweir       Returns a new string resulting from removing white space from both ends
699cdf0e10cSrcweir       of the string.
700cdf0e10cSrcweir 
701cdf0e10cSrcweir       All characters that have codes less than or equal to
702cdf0e10cSrcweir       32 (the space character) are considered to be white space.
703cdf0e10cSrcweir       If the string doesn't contain white spaces at both ends,
704cdf0e10cSrcweir       then the new string is assigned with str.
705cdf0e10cSrcweir 
706cdf0e10cSrcweir       @return   the string, with white space removed from the front and end.
707cdf0e10cSrcweir     */
708cdf0e10cSrcweir     OString trim() const SAL_THROW(())
709cdf0e10cSrcweir     {
710cdf0e10cSrcweir         rtl_String* pNew = 0;
711cdf0e10cSrcweir         rtl_string_newTrim( &pNew, pData );
712cdf0e10cSrcweir         return OString( pNew, (DO_NOT_ACQUIRE*)0 );
713cdf0e10cSrcweir     }
714cdf0e10cSrcweir 
715cdf0e10cSrcweir     /**
716cdf0e10cSrcweir       Returns a token in the string.
717cdf0e10cSrcweir 
718cdf0e10cSrcweir       Example:
719cdf0e10cSrcweir         sal_Int32 nIndex = 0;
720cdf0e10cSrcweir         do
721cdf0e10cSrcweir         {
722cdf0e10cSrcweir             ...
723cdf0e10cSrcweir             OString aToken = aStr.getToken( 0, ';', nIndex );
724cdf0e10cSrcweir             ...
725cdf0e10cSrcweir         }
726cdf0e10cSrcweir         while ( nIndex >= 0 );
727cdf0e10cSrcweir 
728cdf0e10cSrcweir       @param    token       the number of the token to return.
729cdf0e10cSrcweir       @param    cTok        the character which seperate the tokens.
730cdf0e10cSrcweir       @param    index       the position at which the token is searched in the
731cdf0e10cSrcweir                             string.
732cdf0e10cSrcweir                             The index must not be greater thanthe length of the
733cdf0e10cSrcweir                             string.
734cdf0e10cSrcweir                             This param is set to the position of the
735cdf0e10cSrcweir                             next token or to -1, if it is the last token.
736cdf0e10cSrcweir       @return   the token; if either token or index is negative, an empty token
737cdf0e10cSrcweir                 is returned (and index is set to -1)
738cdf0e10cSrcweir     */
739cdf0e10cSrcweir     OString getToken( sal_Int32 token, sal_Char cTok, sal_Int32& index ) const SAL_THROW(())
740cdf0e10cSrcweir     {
741cdf0e10cSrcweir         rtl_String * pNew = 0;
742cdf0e10cSrcweir         index = rtl_string_getToken( &pNew, pData, token, cTok, index );
743cdf0e10cSrcweir         return OString( pNew, (DO_NOT_ACQUIRE *)0 );
744cdf0e10cSrcweir     }
745cdf0e10cSrcweir 
746cdf0e10cSrcweir     /**
747cdf0e10cSrcweir       Returns the Boolean value from this string.
748cdf0e10cSrcweir 
749cdf0e10cSrcweir       This function can't be used for language specific conversion.
750cdf0e10cSrcweir 
751cdf0e10cSrcweir       @return   sal_True, if the string is 1 or "True" in any ASCII case.
752cdf0e10cSrcweir                 sal_False in any other case.
753cdf0e10cSrcweir     */
754cdf0e10cSrcweir     sal_Bool toBoolean() const SAL_THROW(())
755cdf0e10cSrcweir     {
756cdf0e10cSrcweir         return rtl_str_toBoolean( pData->buffer );
757cdf0e10cSrcweir     }
758cdf0e10cSrcweir 
759cdf0e10cSrcweir     /**
760cdf0e10cSrcweir       Returns the first character from this string.
761cdf0e10cSrcweir 
762cdf0e10cSrcweir       @return   the first character from this string or 0, if this string
763cdf0e10cSrcweir                 is emptry.
764cdf0e10cSrcweir     */
765cdf0e10cSrcweir     sal_Char toChar() const SAL_THROW(())
766cdf0e10cSrcweir     {
767cdf0e10cSrcweir         return pData->buffer[0];
768cdf0e10cSrcweir     }
769cdf0e10cSrcweir 
770cdf0e10cSrcweir     /**
771cdf0e10cSrcweir       Returns the int32 value from this string.
772cdf0e10cSrcweir 
773cdf0e10cSrcweir       This function can't be used for language specific conversion.
774cdf0e10cSrcweir 
775cdf0e10cSrcweir       @param    radix       the radix (between 2 and 36)
776cdf0e10cSrcweir       @return   the int32 represented from this string.
777cdf0e10cSrcweir                 0 if this string represents no number.
778cdf0e10cSrcweir     */
779cdf0e10cSrcweir     sal_Int32 toInt32( sal_Int16 radix = 10 ) const SAL_THROW(())
780cdf0e10cSrcweir     {
781cdf0e10cSrcweir         return rtl_str_toInt32( pData->buffer, radix );
782cdf0e10cSrcweir     }
783cdf0e10cSrcweir 
784cdf0e10cSrcweir     /**
785cdf0e10cSrcweir       Returns the int64 value from this string.
786cdf0e10cSrcweir 
787cdf0e10cSrcweir       This function can't be used for language specific conversion.
788cdf0e10cSrcweir 
789cdf0e10cSrcweir       @param    radix       the radix (between 2 and 36)
790cdf0e10cSrcweir       @return   the int64 represented from this string.
791cdf0e10cSrcweir                 0 if this string represents no number.
792cdf0e10cSrcweir     */
793cdf0e10cSrcweir     sal_Int64 toInt64( sal_Int16 radix = 10 ) const SAL_THROW(())
794cdf0e10cSrcweir     {
795cdf0e10cSrcweir         return rtl_str_toInt64( pData->buffer, radix );
796cdf0e10cSrcweir     }
797cdf0e10cSrcweir 
798cdf0e10cSrcweir     /**
799cdf0e10cSrcweir       Returns the float value from this string.
800cdf0e10cSrcweir 
801cdf0e10cSrcweir       This function can't be used for language specific conversion.
802cdf0e10cSrcweir 
803cdf0e10cSrcweir       @return   the float represented from this string.
804cdf0e10cSrcweir                 0.0 if this string represents no number.
805cdf0e10cSrcweir     */
806cdf0e10cSrcweir     float toFloat() const SAL_THROW(())
807cdf0e10cSrcweir     {
808cdf0e10cSrcweir         return rtl_str_toFloat( pData->buffer );
809cdf0e10cSrcweir     }
810cdf0e10cSrcweir 
811cdf0e10cSrcweir     /**
812cdf0e10cSrcweir       Returns the double value from this string.
813cdf0e10cSrcweir 
814cdf0e10cSrcweir       This function can't be used for language specific conversion.
815cdf0e10cSrcweir 
816cdf0e10cSrcweir       @return   the double represented from this string.
817cdf0e10cSrcweir                 0.0 if this string represents no number.
818cdf0e10cSrcweir     */
819cdf0e10cSrcweir     double toDouble() const SAL_THROW(())
820cdf0e10cSrcweir     {
821cdf0e10cSrcweir         return rtl_str_toDouble( pData->buffer );
822cdf0e10cSrcweir     }
823cdf0e10cSrcweir 
824cdf0e10cSrcweir     /**
825cdf0e10cSrcweir       Returns the string representation of the sal_Bool argument.
826cdf0e10cSrcweir 
827cdf0e10cSrcweir       If the sal_Bool is true, the string "true" is returned.
828cdf0e10cSrcweir       If the sal_Bool is false, the string "false" is returned.
829cdf0e10cSrcweir       This function can't be used for language specific conversion.
830cdf0e10cSrcweir 
831cdf0e10cSrcweir       @param    b   a sal_Bool.
832cdf0e10cSrcweir       @return   a string with the string representation of the argument.
833cdf0e10cSrcweir     */
834cdf0e10cSrcweir     static OString valueOf( sal_Bool b ) SAL_THROW(())
835cdf0e10cSrcweir     {
836cdf0e10cSrcweir         sal_Char aBuf[RTL_STR_MAX_VALUEOFBOOLEAN];
837cdf0e10cSrcweir         rtl_String* pNewData = 0;
838cdf0e10cSrcweir         rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfBoolean( aBuf, b ) );
839cdf0e10cSrcweir         return OString( pNewData, (DO_NOT_ACQUIRE*)0 );
840cdf0e10cSrcweir     }
841cdf0e10cSrcweir 
842cdf0e10cSrcweir     /**
843cdf0e10cSrcweir       Returns the string representation of the char argument.
844cdf0e10cSrcweir 
845cdf0e10cSrcweir       @param    c   a character.
846cdf0e10cSrcweir       @return   a string with the string representation of the argument.
847cdf0e10cSrcweir     */
848cdf0e10cSrcweir     static OString valueOf( sal_Char c ) SAL_THROW(())
849cdf0e10cSrcweir     {
850cdf0e10cSrcweir         return OString( &c, 1 );
851cdf0e10cSrcweir     }
852cdf0e10cSrcweir 
853cdf0e10cSrcweir     /**
854cdf0e10cSrcweir       Returns the string representation of the int argument.
855cdf0e10cSrcweir 
856cdf0e10cSrcweir       This function can't be used for language specific conversion.
857cdf0e10cSrcweir 
858cdf0e10cSrcweir       @param    i           a int32.
859cdf0e10cSrcweir       @param    radix       the radix (between 2 and 36)
860cdf0e10cSrcweir       @return   a string with the string representation of the argument.
861cdf0e10cSrcweir     */
862cdf0e10cSrcweir     static OString valueOf( sal_Int32 i, sal_Int16 radix = 10 ) SAL_THROW(())
863cdf0e10cSrcweir     {
864cdf0e10cSrcweir         sal_Char aBuf[RTL_STR_MAX_VALUEOFINT32];
865cdf0e10cSrcweir         rtl_String* pNewData = 0;
866cdf0e10cSrcweir         rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfInt32( aBuf, i, radix ) );
867cdf0e10cSrcweir         return OString( pNewData, (DO_NOT_ACQUIRE*)0 );
868cdf0e10cSrcweir     }
869cdf0e10cSrcweir 
870cdf0e10cSrcweir     /**
871cdf0e10cSrcweir       Returns the string representation of the long argument.
872cdf0e10cSrcweir 
873cdf0e10cSrcweir       This function can't be used for language specific conversion.
874cdf0e10cSrcweir 
875cdf0e10cSrcweir       @param    ll          a int64.
876cdf0e10cSrcweir       @param    radix       the radix (between 2 and 36)
877cdf0e10cSrcweir       @return   a string with the string representation of the argument.
878cdf0e10cSrcweir     */
879cdf0e10cSrcweir     static OString valueOf( sal_Int64 ll, sal_Int16 radix = 10 ) SAL_THROW(())
880cdf0e10cSrcweir     {
881cdf0e10cSrcweir         sal_Char aBuf[RTL_STR_MAX_VALUEOFINT64];
882cdf0e10cSrcweir         rtl_String* pNewData = 0;
883cdf0e10cSrcweir         rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfInt64( aBuf, ll, radix ) );
884cdf0e10cSrcweir         return OString( pNewData, (DO_NOT_ACQUIRE*)0 );
885cdf0e10cSrcweir     }
886cdf0e10cSrcweir 
887cdf0e10cSrcweir     /**
888cdf0e10cSrcweir       Returns the string representation of the float argument.
889cdf0e10cSrcweir 
890cdf0e10cSrcweir       This function can't be used for language specific conversion.
891cdf0e10cSrcweir 
892cdf0e10cSrcweir       @param    f           a float.
893cdf0e10cSrcweir       @return   a string with the string representation of the argument.
894cdf0e10cSrcweir     */
895cdf0e10cSrcweir     static OString valueOf( float f ) SAL_THROW(())
896cdf0e10cSrcweir     {
897cdf0e10cSrcweir         sal_Char aBuf[RTL_STR_MAX_VALUEOFFLOAT];
898cdf0e10cSrcweir         rtl_String* pNewData = 0;
899cdf0e10cSrcweir         rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfFloat( aBuf, f ) );
900cdf0e10cSrcweir         return OString( pNewData, (DO_NOT_ACQUIRE*)0 );
901cdf0e10cSrcweir     }
902cdf0e10cSrcweir 
903cdf0e10cSrcweir     /**
904cdf0e10cSrcweir       Returns the string representation of the double argument.
905cdf0e10cSrcweir 
906cdf0e10cSrcweir       This function can't be used for language specific conversion.
907cdf0e10cSrcweir 
908cdf0e10cSrcweir       @param    d           a double.
909cdf0e10cSrcweir       @return   a string with the string representation of the argument.
910cdf0e10cSrcweir     */
911cdf0e10cSrcweir     static OString valueOf( double d ) SAL_THROW(())
912cdf0e10cSrcweir     {
913cdf0e10cSrcweir         sal_Char aBuf[RTL_STR_MAX_VALUEOFDOUBLE];
914cdf0e10cSrcweir         rtl_String* pNewData = 0;
915cdf0e10cSrcweir         rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfDouble( aBuf, d ) );
916cdf0e10cSrcweir         return OString( pNewData, (DO_NOT_ACQUIRE*)0 );
917cdf0e10cSrcweir     }
918cdf0e10cSrcweir };
919cdf0e10cSrcweir 
920cdf0e10cSrcweir /* ======================================================================= */
921cdf0e10cSrcweir 
922cdf0e10cSrcweir /** A helper to use OStrings with hash maps.
923cdf0e10cSrcweir 
924cdf0e10cSrcweir     Instances of this class are unary function objects that can be used as
925b597708bSHerbert Dürr     hash function arguments to unordered_map, hash_map and similar constructs.
926cdf0e10cSrcweir  */
927cdf0e10cSrcweir struct OStringHash
928cdf0e10cSrcweir {
929cdf0e10cSrcweir     /** Compute a hash code for a string.
930cdf0e10cSrcweir 
931cdf0e10cSrcweir         @param rString
932cdf0e10cSrcweir         a string.
933cdf0e10cSrcweir 
934cdf0e10cSrcweir         @return
935cdf0e10cSrcweir         a hash code for the string.  This hash code should not be stored
936cdf0e10cSrcweir         persistently, as its computation may change in later revisions.
937cdf0e10cSrcweir      */
938cdf0e10cSrcweir     size_t operator()( const rtl::OString& rString ) const
939cdf0e10cSrcweir         { return (size_t)rString.hashCode(); }
940cdf0e10cSrcweir };
941cdf0e10cSrcweir 
942cdf0e10cSrcweir /* ======================================================================= */
943cdf0e10cSrcweir 
944fda69661SHerbert Dürr /** Equality functor for classic c-strings (i.e. null-terminated char* strings) */
945fda69661SHerbert Dürr struct CStringEqual
946fda69661SHerbert Dürr {
947fda69661SHerbert Dürr 	bool operator()( const char* p1, const char* p2) const {
948fda69661SHerbert Dürr 		while( *p1)
949fda69661SHerbert Dürr 			if( *(p1++) != *(p2++))
950fda69661SHerbert Dürr 				return false;
951fda69661SHerbert Dürr 		return true;
952fda69661SHerbert Dürr 	}
953fda69661SHerbert Dürr };
954fda69661SHerbert Dürr 
955fda69661SHerbert Dürr /** Hashing functor for classic c-strings (i.e. null-terminated char* strings) */
956fda69661SHerbert Dürr struct CStringHash
957fda69661SHerbert Dürr {
958fda69661SHerbert Dürr 	size_t operator()( const char* p) const {
959fda69661SHerbert Dürr 		size_t n = 0;
960fda69661SHerbert Dürr 		while( *p)
961b3f482f2SHerbert Dürr 			n += 4*n + *reinterpret_cast<const unsigned char*>(p++);
962fda69661SHerbert Dürr 		return n;
963fda69661SHerbert Dürr 	}
964fda69661SHerbert Dürr };
965fda69661SHerbert Dürr 
966cdf0e10cSrcweir } /* Namespace */
967cdf0e10cSrcweir 
968*24c56ab9SHerbert Dürr /* Helper method to support OString messages in OSL_ENSURE */
969*24c56ab9SHerbert Dürr inline sal_Bool SAL_CALL osl_assertFailedLine( const sal_Char* pszFileName, sal_Int32 nLine, const ::rtl::OString& rMessage)
970*24c56ab9SHerbert Dürr { return osl_assertFailedLine( pszFileName, nLine, rMessage.getStr()); }
971*24c56ab9SHerbert Dürr 
972cdf0e10cSrcweir #endif /* __cplusplus */
973cdf0e10cSrcweir 
974cdf0e10cSrcweir #endif /* _RTL_STRING_HXX_ */
975fda69661SHerbert Dürr 
976