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