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