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