xref: /aoo42x/main/sal/inc/rtl/ustring.hxx (revision 86e1cf34)
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_USTRING_HXX_
25cdf0e10cSrcweir #define _RTL_USTRING_HXX_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #ifdef __cplusplus
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #ifndef _RTL_DIAGNOSE_H_
30cdf0e10cSrcweir #include "osl/diagnose.h"
31cdf0e10cSrcweir #endif
32cdf0e10cSrcweir #include <rtl/ustring.h>
33cdf0e10cSrcweir #include <rtl/string.hxx>
34cdf0e10cSrcweir #include <rtl/memory.h>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #if defined EXCEPTIONS_OFF
37cdf0e10cSrcweir #include <stdlib.h>
38cdf0e10cSrcweir #else
39cdf0e10cSrcweir #include <new>
40cdf0e10cSrcweir #endif
41cdf0e10cSrcweir 
42cdf0e10cSrcweir namespace rtl
43cdf0e10cSrcweir {
44cdf0e10cSrcweir /* ======================================================================= */
45cdf0e10cSrcweir 
46cdf0e10cSrcweir /**
47cdf0e10cSrcweir   This String class provide base functionality for C++ like Unicode
48cdf0e10cSrcweir   character array handling. The advantage of this class is, that it
49cdf0e10cSrcweir   handle all the memory managament for you - and it do it
50cdf0e10cSrcweir   more efficient. If you assign a string to another string, the
51cdf0e10cSrcweir   data of both strings are shared (without any copy operation or
52cdf0e10cSrcweir   memory allocation) as long as you do not change the string. This class
53cdf0e10cSrcweir   stores also the length of the string, so that many operations are
54cdf0e10cSrcweir   faster as the C-str-functions.
55cdf0e10cSrcweir 
56cdf0e10cSrcweir   This class provide only readonly string handling. So you could create
57cdf0e10cSrcweir   a string and you could only query the content from this string.
58cdf0e10cSrcweir   It provide also functionality to change the string, but this results
59cdf0e10cSrcweir   in every case in a new string instance (in the most cases with an
60cdf0e10cSrcweir   memory allocation). You don't have functionality to change the
61cdf0e10cSrcweir   content of the string. If you want change the string content, than
62cdf0e10cSrcweir   you should us the OStringBuffer class, which provide these
63cdf0e10cSrcweir   functionality and avoid to much memory allocation.
64cdf0e10cSrcweir 
65cdf0e10cSrcweir   The design of this class is similar to the string classes in Java
66cdf0e10cSrcweir   and so more people should have fewer understanding problems when they
67cdf0e10cSrcweir   use this class.
68cdf0e10cSrcweir */
69cdf0e10cSrcweir 
70cdf0e10cSrcweir class OUString
71cdf0e10cSrcweir {
72cdf0e10cSrcweir public:
73cdf0e10cSrcweir     /** @internal */
74cdf0e10cSrcweir     rtl_uString * pData;
75cdf0e10cSrcweir 
76cdf0e10cSrcweir private:
77cdf0e10cSrcweir     /** @internal */
78cdf0e10cSrcweir     class DO_NOT_ACQUIRE{};
79cdf0e10cSrcweir 
80cdf0e10cSrcweir     /** @internal */
OUString(rtl_uString * value,DO_NOT_ACQUIRE *)81cdf0e10cSrcweir     OUString( rtl_uString * value, DO_NOT_ACQUIRE * )
82cdf0e10cSrcweir     {
83cdf0e10cSrcweir         pData = value;
84cdf0e10cSrcweir     }
85cdf0e10cSrcweir 
86cdf0e10cSrcweir public:
87cdf0e10cSrcweir     /**
88cdf0e10cSrcweir       New string containing no characters.
89cdf0e10cSrcweir     */
90cdf0e10cSrcweir     OUString() SAL_THROW(())
91cdf0e10cSrcweir     {
92cdf0e10cSrcweir         pData = 0;
93cdf0e10cSrcweir         rtl_uString_new( &pData );
94cdf0e10cSrcweir     }
95cdf0e10cSrcweir 
96cdf0e10cSrcweir     /**
97cdf0e10cSrcweir       New string from OUString.
98cdf0e10cSrcweir 
99cdf0e10cSrcweir       @param    str         a OUString.
100cdf0e10cSrcweir     */
101cdf0e10cSrcweir     OUString( const OUString & str ) SAL_THROW(())
102cdf0e10cSrcweir     {
103cdf0e10cSrcweir         pData = str.pData;
104cdf0e10cSrcweir         rtl_uString_acquire( pData );
105cdf0e10cSrcweir     }
106cdf0e10cSrcweir 
107cdf0e10cSrcweir     /**
108cdf0e10cSrcweir       New string from OUString data.
109cdf0e10cSrcweir 
110cdf0e10cSrcweir       @param    str         a OUString data.
111cdf0e10cSrcweir     */
112cdf0e10cSrcweir     OUString( rtl_uString * str )  SAL_THROW(())
113cdf0e10cSrcweir     {
114cdf0e10cSrcweir         pData = str;
115cdf0e10cSrcweir         rtl_uString_acquire( pData );
116cdf0e10cSrcweir     }
117cdf0e10cSrcweir     /** New OUString from OUString data without acquiring it.  Takeover of ownership.
118cdf0e10cSrcweir 
119cdf0e10cSrcweir         @param str
120cdf0e10cSrcweir                OUString data
121cdf0e10cSrcweir         @param dummy
122cdf0e10cSrcweir                SAL_NO_ACQUIRE to distinguish from other ctors
123cdf0e10cSrcweir     */
OUString(rtl_uString * str,__sal_NoAcquire)124cdf0e10cSrcweir     inline OUString( rtl_uString * str, __sal_NoAcquire ) SAL_THROW( () )
125cdf0e10cSrcweir         { pData = str; }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 
128cdf0e10cSrcweir     /**
129cdf0e10cSrcweir       New string from a single Unicode character.
130cdf0e10cSrcweir 
131cdf0e10cSrcweir       @param    value       a Unicode character.
132cdf0e10cSrcweir     */
133cdf0e10cSrcweir 	explicit OUString( sal_Unicode value ) SAL_THROW(())
134cdf0e10cSrcweir         : pData (0)
135cdf0e10cSrcweir 	{
136cdf0e10cSrcweir         rtl_uString_newFromStr_WithLength( &pData, &value, 1 );
137cdf0e10cSrcweir 	}
138cdf0e10cSrcweir 
139cdf0e10cSrcweir     /**
140cdf0e10cSrcweir       New string from a Unicode character buffer array.
141cdf0e10cSrcweir 
142cdf0e10cSrcweir       @param    value       a NULL-terminated Unicode character array.
143cdf0e10cSrcweir     */
144cdf0e10cSrcweir     OUString( const sal_Unicode * value ) SAL_THROW(())
145cdf0e10cSrcweir     {
146cdf0e10cSrcweir         pData = 0;
147cdf0e10cSrcweir         rtl_uString_newFromStr( &pData, value );
148cdf0e10cSrcweir     }
149cdf0e10cSrcweir 
150cdf0e10cSrcweir     /**
151cdf0e10cSrcweir       New string from a Uniocde character buffer array.
152cdf0e10cSrcweir 
153cdf0e10cSrcweir       @param    value       a Unicode character array.
154cdf0e10cSrcweir       @param    length      the number of character which should be copied.
155cdf0e10cSrcweir                             The character array length must be greater or
156cdf0e10cSrcweir                             equal than this value.
157cdf0e10cSrcweir     */
OUString(const sal_Unicode * value,sal_Int32 length)158cdf0e10cSrcweir     OUString( const sal_Unicode * value, sal_Int32 length ) SAL_THROW(())
159cdf0e10cSrcweir     {
160cdf0e10cSrcweir         pData = 0;
161cdf0e10cSrcweir         rtl_uString_newFromStr_WithLength( &pData, value, length );
162cdf0e10cSrcweir     }
163cdf0e10cSrcweir 
164cdf0e10cSrcweir     /**
165cdf0e10cSrcweir       New string from a 8-Bit character buffer array.
166cdf0e10cSrcweir 
167cdf0e10cSrcweir       @param    value           a 8-Bit character array.
168cdf0e10cSrcweir       @param    length          the number of character which should be converted.
169cdf0e10cSrcweir                                 The 8-Bit character array length must be
170cdf0e10cSrcweir                                 greater or equal than this value.
171cdf0e10cSrcweir       @param    encoding        the text encoding from which the 8-Bit character
172cdf0e10cSrcweir                                 sequence should be converted.
173cdf0e10cSrcweir       @param    convertFlags    flags which controls the conversion.
174cdf0e10cSrcweir                                 see RTL_TEXTTOUNICODE_FLAGS_...
175cdf0e10cSrcweir 
176cdf0e10cSrcweir       @exception std::bad_alloc is thrown if an out-of-memory condition occurs
177cdf0e10cSrcweir     */
OUString(const sal_Char * value,sal_Int32 length,rtl_TextEncoding encoding,sal_uInt32 convertFlags=OSTRING_TO_OUSTRING_CVTFLAGS)178cdf0e10cSrcweir     OUString( const sal_Char * value, sal_Int32 length,
179cdf0e10cSrcweir               rtl_TextEncoding encoding,
180cdf0e10cSrcweir               sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS )
181cdf0e10cSrcweir     {
182cdf0e10cSrcweir         pData = 0;
183cdf0e10cSrcweir         rtl_string2UString( &pData, value, length, encoding, convertFlags );
184cdf0e10cSrcweir #if defined EXCEPTIONS_OFF
185cdf0e10cSrcweir         OSL_ASSERT(pData != NULL);
186cdf0e10cSrcweir #else
187cdf0e10cSrcweir         if (pData == 0) {
188cdf0e10cSrcweir             throw std::bad_alloc();
189cdf0e10cSrcweir         }
190cdf0e10cSrcweir #endif
191cdf0e10cSrcweir     }
192cdf0e10cSrcweir 
193cdf0e10cSrcweir     /** Create a new string from an array of Unicode code points.
194cdf0e10cSrcweir 
195cdf0e10cSrcweir         @param codePoints
196cdf0e10cSrcweir         an array of at least codePointCount code points, which each must be in
197cdf0e10cSrcweir         the range from 0 to 0x10FFFF, inclusive.  May be null if codePointCount
198cdf0e10cSrcweir         is zero.
199cdf0e10cSrcweir 
200cdf0e10cSrcweir         @param codePointCount
201cdf0e10cSrcweir         the non-negative number of code points.
202cdf0e10cSrcweir 
203cdf0e10cSrcweir         @exception std::bad_alloc
204cdf0e10cSrcweir         is thrown if either an out-of-memory condition occurs or the resulting
205cdf0e10cSrcweir         number of UTF-16 code units would have been larger than SAL_MAX_INT32.
206cdf0e10cSrcweir 
207cdf0e10cSrcweir         @since UDK 3.2.7
208cdf0e10cSrcweir     */
OUString(sal_uInt32 const * codePoints,sal_Int32 codePointCount)209cdf0e10cSrcweir     inline explicit OUString(
210cdf0e10cSrcweir         sal_uInt32 const * codePoints, sal_Int32 codePointCount):
211cdf0e10cSrcweir         pData(NULL)
212cdf0e10cSrcweir     {
213cdf0e10cSrcweir         rtl_uString_newFromCodePoints(&pData, codePoints, codePointCount);
214cdf0e10cSrcweir         if (pData == NULL) {
215cdf0e10cSrcweir #if defined EXCEPTIONS_OFF
216cdf0e10cSrcweir             abort();
217cdf0e10cSrcweir #else
218cdf0e10cSrcweir             throw std::bad_alloc();
219cdf0e10cSrcweir #endif
220cdf0e10cSrcweir         }
221cdf0e10cSrcweir     }
222cdf0e10cSrcweir 
223cdf0e10cSrcweir     /**
224cdf0e10cSrcweir       Release the string data.
225cdf0e10cSrcweir     */
226cdf0e10cSrcweir     ~OUString() SAL_THROW(())
227cdf0e10cSrcweir     {
228cdf0e10cSrcweir         rtl_uString_release( pData );
229cdf0e10cSrcweir     }
230cdf0e10cSrcweir 
231cdf0e10cSrcweir     /** Provides an OUString const & passing a storage pointer of an
232cdf0e10cSrcweir         rtl_uString * handle.
233cdf0e10cSrcweir         It is more convenient to use C++ OUString member functions when dealing
234cdf0e10cSrcweir         with rtl_uString * handles.  Using this function avoids unnecessary
235cdf0e10cSrcweir         acquire()/release() calls for a temporary OUString object.
236cdf0e10cSrcweir 
237cdf0e10cSrcweir         @param ppHandle
238cdf0e10cSrcweir                pointer to storage
239cdf0e10cSrcweir         @return
240cdf0e10cSrcweir                OUString const & based on given storage
241cdf0e10cSrcweir     */
unacquired(rtl_uString * const * ppHandle)242cdf0e10cSrcweir     static inline OUString const & unacquired( rtl_uString * const * ppHandle )
243cdf0e10cSrcweir         { return * reinterpret_cast< OUString const * >( ppHandle ); }
244cdf0e10cSrcweir 
245cdf0e10cSrcweir     /**
246cdf0e10cSrcweir       Assign a new string.
247cdf0e10cSrcweir 
248cdf0e10cSrcweir       @param    str         a OUString.
249cdf0e10cSrcweir     */
operator =(const OUString & str)250cdf0e10cSrcweir     OUString & operator=( const OUString & str ) SAL_THROW(())
251cdf0e10cSrcweir     {
252cdf0e10cSrcweir         rtl_uString_assign( &pData, str.pData );
253cdf0e10cSrcweir         return *this;
254cdf0e10cSrcweir     }
255cdf0e10cSrcweir 
256cdf0e10cSrcweir     /**
257cdf0e10cSrcweir       Append a string to this string.
258cdf0e10cSrcweir 
259cdf0e10cSrcweir       @param    str         a OUString.
260cdf0e10cSrcweir     */
operator +=(const OUString & str)261cdf0e10cSrcweir     OUString & operator+=( const OUString & str ) SAL_THROW(())
262cdf0e10cSrcweir     {
263cdf0e10cSrcweir         rtl_uString_newConcat( &pData, pData, str.pData );
264cdf0e10cSrcweir         return *this;
265cdf0e10cSrcweir     }
266cdf0e10cSrcweir 
267cdf0e10cSrcweir     /**
268cdf0e10cSrcweir       Returns the length of this string.
269cdf0e10cSrcweir 
270cdf0e10cSrcweir       The length is equal to the number of Unicode characters in this string.
271cdf0e10cSrcweir 
272cdf0e10cSrcweir       @return   the length of the sequence of characters represented by this
273cdf0e10cSrcweir                 object.
274cdf0e10cSrcweir     */
getLength() const275cdf0e10cSrcweir     sal_Int32 getLength() const SAL_THROW(()) { return pData->length; }
276cdf0e10cSrcweir 
27724c56ab9SHerbert Dürr private:
278cdf0e10cSrcweir     /**
279cdf0e10cSrcweir       Returns a pointer to the Unicode character buffer from this string.
280cdf0e10cSrcweir 
28124c56ab9SHerbert Dürr       NOTE: the implicit cast to a UTF-16 pointer is obsolete
28224c56ab9SHerbert Dürr             because it is too dangerous #i123068#
28324c56ab9SHerbert Dürr 
284cdf0e10cSrcweir       It isn't necessarily NULL terminated.
285cdf0e10cSrcweir 
286cdf0e10cSrcweir       @return   a pointer to the Unicode characters buffer from this object.
287cdf0e10cSrcweir     */
288cdf0e10cSrcweir     operator const sal_Unicode *() const SAL_THROW(()) { return pData->buffer; }
28924c56ab9SHerbert Dürr public:
29024c56ab9SHerbert Dürr     /** Returns a reference to a UTF-16 element of this string. */
operator [](int n)29124c56ab9SHerbert Dürr     sal_Unicode& operator[]( int n ) { return pData->buffer[n]; }
29224c56ab9SHerbert Dürr     /** Returns a const reference to a UTF-16 element of this string. */
operator [](int n) const29324c56ab9SHerbert Dürr     const sal_Unicode& operator[]( int n ) const { return pData->buffer[n]; }
29424c56ab9SHerbert Dürr     /** Returns a bool indicating whether this string is empty. */
isEmpty() const29524c56ab9SHerbert Dürr     bool isEmpty() const { return (pData->length == 0); }
29624c56ab9SHerbert Dürr 
297cdf0e10cSrcweir 
298cdf0e10cSrcweir     /**
299cdf0e10cSrcweir       Returns a pointer to the Unicode character buffer from this string.
300cdf0e10cSrcweir 
301cdf0e10cSrcweir       It isn't necessarily NULL terminated.
302cdf0e10cSrcweir 
303cdf0e10cSrcweir       @return   a pointer to the Unicode characters buffer from this object.
304cdf0e10cSrcweir     */
getStr() const305cdf0e10cSrcweir     const sal_Unicode * getStr() const SAL_THROW(()) { return pData->buffer; }
306cdf0e10cSrcweir 
307cdf0e10cSrcweir     /**
308cdf0e10cSrcweir       Compares two strings.
309cdf0e10cSrcweir 
310cdf0e10cSrcweir       The comparison is based on the numeric value of each character in
311cdf0e10cSrcweir       the strings and return a value indicating their relationship.
312cdf0e10cSrcweir       This function can't be used for language specific sorting.
313cdf0e10cSrcweir 
314cdf0e10cSrcweir       @param    str         the object to be compared.
315cdf0e10cSrcweir       @return   0 - if both strings are equal
316cdf0e10cSrcweir                 < 0 - if this string is less than the string argument
317cdf0e10cSrcweir                 > 0 - if this string is greater than the string argument
318cdf0e10cSrcweir     */
compareTo(const OUString & str) const319cdf0e10cSrcweir     sal_Int32 compareTo( const OUString & str ) const SAL_THROW(())
320cdf0e10cSrcweir     {
321cdf0e10cSrcweir         return rtl_ustr_compare_WithLength( pData->buffer, pData->length,
322cdf0e10cSrcweir                                             str.pData->buffer, str.pData->length );
323cdf0e10cSrcweir     }
324cdf0e10cSrcweir 
325cdf0e10cSrcweir     /**
326cdf0e10cSrcweir       Compares two strings with an maximum count of characters.
327cdf0e10cSrcweir 
328cdf0e10cSrcweir       The comparison is based on the numeric value of each character in
329cdf0e10cSrcweir       the strings and return a value indicating their relationship.
330cdf0e10cSrcweir       This function can't be used for language specific sorting.
331cdf0e10cSrcweir 
332cdf0e10cSrcweir       @param    str         the object to be compared.
333cdf0e10cSrcweir       @param    maxLength   the maximum count of characters to be compared.
334cdf0e10cSrcweir       @return   0 - if both strings are equal
335cdf0e10cSrcweir                 < 0 - if this string is less than the string argument
336cdf0e10cSrcweir                 > 0 - if this string is greater than the string argument
337cdf0e10cSrcweir     */
compareTo(const OUString & str,sal_Int32 maxLength) const338cdf0e10cSrcweir     sal_Int32 compareTo( const OUString & str, sal_Int32 maxLength ) const SAL_THROW(())
339cdf0e10cSrcweir     {
340cdf0e10cSrcweir         return rtl_ustr_shortenedCompare_WithLength( pData->buffer, pData->length,
341cdf0e10cSrcweir                                                      str.pData->buffer, str.pData->length, maxLength );
342cdf0e10cSrcweir     }
343cdf0e10cSrcweir 
344cdf0e10cSrcweir     /**
345cdf0e10cSrcweir       Compares two strings in reverse order.
346cdf0e10cSrcweir 
347cdf0e10cSrcweir       The comparison is based on the numeric value of each character in
348cdf0e10cSrcweir       the strings and return a value indicating their relationship.
349cdf0e10cSrcweir       This function can't be used for language specific sorting.
350cdf0e10cSrcweir 
351cdf0e10cSrcweir       @param    str         the object to be compared.
352cdf0e10cSrcweir       @return   0 - if both strings are equal
353cdf0e10cSrcweir                 < 0 - if this string is less than the string argument
354cdf0e10cSrcweir                 > 0 - if this string is greater than the string argument
355cdf0e10cSrcweir     */
reverseCompareTo(const OUString & str) const356cdf0e10cSrcweir     sal_Int32 reverseCompareTo( const OUString & str ) const SAL_THROW(())
357cdf0e10cSrcweir     {
358cdf0e10cSrcweir         return rtl_ustr_reverseCompare_WithLength( pData->buffer, pData->length,
359cdf0e10cSrcweir                                                    str.pData->buffer, str.pData->length );
360cdf0e10cSrcweir     }
361cdf0e10cSrcweir 
362cdf0e10cSrcweir     /**
363cdf0e10cSrcweir       Perform a comparison of two strings.
364cdf0e10cSrcweir 
365cdf0e10cSrcweir       The result is true if and only if second string
366cdf0e10cSrcweir       represents the same sequence of characters as the first string.
367cdf0e10cSrcweir       This function can't be used for language specific comparison.
368cdf0e10cSrcweir 
369cdf0e10cSrcweir       @param    str         the object to be compared.
370cdf0e10cSrcweir       @return   sal_True if the strings are equal;
371cdf0e10cSrcweir                 sal_False, otherwise.
372cdf0e10cSrcweir     */
equals(const OUString & str) const373cdf0e10cSrcweir     sal_Bool equals( const OUString & str ) const SAL_THROW(())
374cdf0e10cSrcweir     {
375cdf0e10cSrcweir         if ( pData->length != str.pData->length )
376cdf0e10cSrcweir             return sal_False;
377cdf0e10cSrcweir         if ( pData == str.pData )
378cdf0e10cSrcweir             return sal_True;
379cdf0e10cSrcweir         return rtl_ustr_reverseCompare_WithLength( pData->buffer, pData->length,
380cdf0e10cSrcweir                                                    str.pData->buffer, str.pData->length ) == 0;
381cdf0e10cSrcweir     }
382cdf0e10cSrcweir 
383cdf0e10cSrcweir     /**
384cdf0e10cSrcweir       Perform a ASCII lowercase comparison of two strings.
385cdf0e10cSrcweir 
386cdf0e10cSrcweir       The result is true if and only if second string
387cdf0e10cSrcweir       represents the same sequence of characters as the first string,
388cdf0e10cSrcweir       ignoring the case.
389cdf0e10cSrcweir       Character values between 65 and 90 (ASCII A-Z) are interpreted as
390cdf0e10cSrcweir       values between 97 and 122 (ASCII a-z).
391cdf0e10cSrcweir       This function can't be used for language specific comparison.
392cdf0e10cSrcweir 
393cdf0e10cSrcweir       @param    str         the object to be compared.
394cdf0e10cSrcweir       @return   sal_True if the strings are equal;
395cdf0e10cSrcweir                 sal_False, otherwise.
396cdf0e10cSrcweir     */
equalsIgnoreAsciiCase(const OUString & str) const397cdf0e10cSrcweir     sal_Bool equalsIgnoreAsciiCase( const OUString & str ) const SAL_THROW(())
398cdf0e10cSrcweir     {
399cdf0e10cSrcweir         if ( pData->length != str.pData->length )
400cdf0e10cSrcweir             return sal_False;
401cdf0e10cSrcweir         if ( pData == str.pData )
402cdf0e10cSrcweir             return sal_True;
403cdf0e10cSrcweir         return rtl_ustr_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
404cdf0e10cSrcweir                                                            str.pData->buffer, str.pData->length ) == 0;
405cdf0e10cSrcweir     }
406cdf0e10cSrcweir 
407cdf0e10cSrcweir     /**
408cdf0e10cSrcweir       Match against a substring appearing in this string.
409cdf0e10cSrcweir 
410cdf0e10cSrcweir       The result is true if and only if the second string appears as a substring
411cdf0e10cSrcweir       of this string, at the given position.
412cdf0e10cSrcweir       This function can't be used for language specific comparison.
413cdf0e10cSrcweir 
414cdf0e10cSrcweir       @param    str         the object (substring) to be compared.
415cdf0e10cSrcweir       @param    fromIndex   the index to start the comparion from.
416cdf0e10cSrcweir                             The index must be greater or equal than 0
417cdf0e10cSrcweir                             and less or equal as the string length.
418cdf0e10cSrcweir       @return   sal_True if str match with the characters in the string
419cdf0e10cSrcweir                 at the given position;
420cdf0e10cSrcweir                 sal_False, otherwise.
421cdf0e10cSrcweir     */
match(const OUString & str,sal_Int32 fromIndex=0) const422cdf0e10cSrcweir     sal_Bool match( const OUString & str, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
423cdf0e10cSrcweir     {
424cdf0e10cSrcweir         return rtl_ustr_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
425cdf0e10cSrcweir                                                      str.pData->buffer, str.pData->length, str.pData->length ) == 0;
426cdf0e10cSrcweir     }
427cdf0e10cSrcweir 
428cdf0e10cSrcweir     /**
429cdf0e10cSrcweir       Match against a substring appearing in this string, ignoring the case of
430cdf0e10cSrcweir       ASCII letters.
431cdf0e10cSrcweir 
432cdf0e10cSrcweir       The result is true if and only if the second string appears as a substring
433cdf0e10cSrcweir       of this string, at the given position.
434cdf0e10cSrcweir       Character values between 65 and 90 (ASCII A-Z) are interpreted as
435cdf0e10cSrcweir       values between 97 and 122 (ASCII a-z).
436cdf0e10cSrcweir       This function can't be used for language specific comparison.
437cdf0e10cSrcweir 
438cdf0e10cSrcweir       @param    str         the object (substring) to be compared.
439cdf0e10cSrcweir       @param    fromIndex   the index to start the comparion from.
440cdf0e10cSrcweir                             The index must be greater or equal than 0
441cdf0e10cSrcweir                             and less or equal as the string length.
442cdf0e10cSrcweir       @return   sal_True if str match with the characters in the string
443cdf0e10cSrcweir                 at the given position;
444cdf0e10cSrcweir                 sal_False, otherwise.
445cdf0e10cSrcweir     */
matchIgnoreAsciiCase(const OUString & str,sal_Int32 fromIndex=0) const446cdf0e10cSrcweir     sal_Bool matchIgnoreAsciiCase( const OUString & str, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
447cdf0e10cSrcweir     {
448cdf0e10cSrcweir         return rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
449cdf0e10cSrcweir                                                                     str.pData->buffer, str.pData->length,
450cdf0e10cSrcweir                                                                     str.pData->length ) == 0;
451cdf0e10cSrcweir     }
452cdf0e10cSrcweir 
453cdf0e10cSrcweir     /**
454cdf0e10cSrcweir       Compares two strings.
455cdf0e10cSrcweir 
456cdf0e10cSrcweir       The comparison is based on the numeric value of each character in
457cdf0e10cSrcweir       the strings and return a value indicating their relationship.
458cdf0e10cSrcweir       Since this method is optimized for performance, the ASCII character
459cdf0e10cSrcweir       values are not converted in any way. The caller has to make sure that
460cdf0e10cSrcweir       all ASCII characters are in the allowed range between 0 and
461cdf0e10cSrcweir       127. The ASCII string must be NULL-terminated.
462cdf0e10cSrcweir       This function can't be used for language specific sorting.
463cdf0e10cSrcweir 
464cdf0e10cSrcweir       @param  asciiStr      the 8-Bit ASCII character string to be compared.
465cdf0e10cSrcweir       @return   0 - if both strings are equal
466cdf0e10cSrcweir                 < 0 - if this string is less than the string argument
467cdf0e10cSrcweir                 > 0 - if this string is greater than the string argument
468cdf0e10cSrcweir     */
compareToAscii(const sal_Char * asciiStr) const469cdf0e10cSrcweir     sal_Int32 compareToAscii( const sal_Char* asciiStr ) const SAL_THROW(())
470cdf0e10cSrcweir     {
471cdf0e10cSrcweir         return rtl_ustr_ascii_compare_WithLength( pData->buffer, pData->length, asciiStr );
472cdf0e10cSrcweir     }
473cdf0e10cSrcweir 
474cdf0e10cSrcweir     /**
475cdf0e10cSrcweir       Compares two strings with an maximum count of characters.
476cdf0e10cSrcweir 
477cdf0e10cSrcweir       The comparison is based on the numeric value of each character in
478cdf0e10cSrcweir       the strings and return a value indicating their relationship.
479cdf0e10cSrcweir       Since this method is optimized for performance, the ASCII character
480cdf0e10cSrcweir       values are not converted in any way. The caller has to make sure that
481cdf0e10cSrcweir       all ASCII characters are in the allowed range between 0 and
482cdf0e10cSrcweir       127. The ASCII string must be NULL-terminated.
483cdf0e10cSrcweir       This function can't be used for language specific sorting.
484cdf0e10cSrcweir 
485cdf0e10cSrcweir       @param  asciiStr          the 8-Bit ASCII character string to be compared.
486cdf0e10cSrcweir       @param  maxLength         the maximum count of characters to be compared.
487cdf0e10cSrcweir       @return   0 - if both strings are equal
488cdf0e10cSrcweir                 < 0 - if this string is less than the string argument
489cdf0e10cSrcweir                 > 0 - if this string is greater than the string argument
490cdf0e10cSrcweir     */
compareToAscii(const sal_Char * asciiStr,sal_Int32 maxLength) const491cdf0e10cSrcweir     sal_Int32 compareToAscii( const sal_Char * asciiStr, sal_Int32 maxLength ) const SAL_THROW(())
492cdf0e10cSrcweir     {
493cdf0e10cSrcweir         return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer, pData->length,
494cdf0e10cSrcweir                                                            asciiStr, maxLength );
495cdf0e10cSrcweir     }
496cdf0e10cSrcweir 
497cdf0e10cSrcweir     /**
498cdf0e10cSrcweir       Compares two strings in reverse order.
499cdf0e10cSrcweir 
500cdf0e10cSrcweir       This could be useful, if normally both strings start with the same
501cdf0e10cSrcweir       content. The comparison is based on the numeric value of each character
502cdf0e10cSrcweir       in the strings and return a value indicating their relationship.
503cdf0e10cSrcweir       Since this method is optimized for performance, the ASCII character
504cdf0e10cSrcweir       values are not converted in any way. The caller has to make sure that
505cdf0e10cSrcweir       all ASCII characters are in the allowed range between 0 and
506cdf0e10cSrcweir       127. The ASCII string must be NULL-terminated and must be greater or
507cdf0e10cSrcweir       equal as asciiStrLength.
508cdf0e10cSrcweir       This function can't be used for language specific sorting.
509cdf0e10cSrcweir 
510cdf0e10cSrcweir       @param    asciiStr        the 8-Bit ASCII character string to be compared.
511cdf0e10cSrcweir       @param    asciiStrLength  the length of the ascii string
512cdf0e10cSrcweir       @return   0 - if both strings are equal
513cdf0e10cSrcweir                 < 0 - if this string is less than the string argument
514cdf0e10cSrcweir                 > 0 - if this string is greater than the string argument
515cdf0e10cSrcweir     */
reverseCompareToAsciiL(const sal_Char * asciiStr,sal_Int32 asciiStrLength) const516cdf0e10cSrcweir     sal_Int32 reverseCompareToAsciiL( const sal_Char * asciiStr, sal_Int32 asciiStrLength ) const SAL_THROW(())
517cdf0e10cSrcweir     {
518cdf0e10cSrcweir         return rtl_ustr_asciil_reverseCompare_WithLength( pData->buffer, pData->length,
519cdf0e10cSrcweir                                                           asciiStr, asciiStrLength );
520cdf0e10cSrcweir     }
521cdf0e10cSrcweir 
522cdf0e10cSrcweir     /**
523cdf0e10cSrcweir       Perform a comparison of two strings.
524cdf0e10cSrcweir 
525cdf0e10cSrcweir       The result is true if and only if second string
526cdf0e10cSrcweir       represents the same sequence of characters as the first string.
527cdf0e10cSrcweir       Since this method is optimized for performance, the ASCII character
528cdf0e10cSrcweir       values are not converted in any way. The caller has to make sure that
529cdf0e10cSrcweir       all ASCII characters are in the allowed range between 0 and
530cdf0e10cSrcweir       127. The ASCII string must be NULL-terminated.
531cdf0e10cSrcweir       This function can't be used for language specific comparison.
532cdf0e10cSrcweir 
533cdf0e10cSrcweir       @param    asciiStr        the 8-Bit ASCII character string to be compared.
534cdf0e10cSrcweir       @return   sal_True if the strings are equal;
535cdf0e10cSrcweir                 sal_False, otherwise.
536cdf0e10cSrcweir     */
equalsAscii(const sal_Char * asciiStr) const537cdf0e10cSrcweir     sal_Bool equalsAscii( const sal_Char* asciiStr ) const SAL_THROW(())
538cdf0e10cSrcweir     {
539cdf0e10cSrcweir         return rtl_ustr_ascii_compare_WithLength( pData->buffer, pData->length,
540cdf0e10cSrcweir                                                   asciiStr ) == 0;
541cdf0e10cSrcweir     }
542cdf0e10cSrcweir 
543cdf0e10cSrcweir     /**
544cdf0e10cSrcweir       Perform a comparison of two strings.
545cdf0e10cSrcweir 
546cdf0e10cSrcweir       The result is true if and only if second string
547cdf0e10cSrcweir       represents the same sequence of characters as the first string.
548cdf0e10cSrcweir       Since this method is optimized for performance, the ASCII character
549cdf0e10cSrcweir       values are not converted in any way. The caller has to make sure that
550cdf0e10cSrcweir       all ASCII characters are in the allowed range between 0 and
551cdf0e10cSrcweir       127. The ASCII string must be NULL-terminated and must be greater or
552cdf0e10cSrcweir       equal as asciiStrLength.
553cdf0e10cSrcweir       This function can't be used for language specific comparison.
554cdf0e10cSrcweir 
555cdf0e10cSrcweir       @param    asciiStr         the 8-Bit ASCII character string to be compared.
556cdf0e10cSrcweir       @param    asciiStrLength   the length of the ascii string
557cdf0e10cSrcweir       @return   sal_True if the strings are equal;
558cdf0e10cSrcweir                 sal_False, otherwise.
559cdf0e10cSrcweir     */
equalsAsciiL(const sal_Char * asciiStr,sal_Int32 asciiStrLength) const560cdf0e10cSrcweir     sal_Bool equalsAsciiL( const sal_Char* asciiStr, sal_Int32 asciiStrLength ) const SAL_THROW(())
561cdf0e10cSrcweir     {
562cdf0e10cSrcweir         if ( pData->length != asciiStrLength )
563cdf0e10cSrcweir             return sal_False;
564cdf0e10cSrcweir 
565cdf0e10cSrcweir         return rtl_ustr_asciil_reverseEquals_WithLength(
566cdf0e10cSrcweir 					pData->buffer, asciiStr, asciiStrLength );
567cdf0e10cSrcweir     }
568cdf0e10cSrcweir 
569cdf0e10cSrcweir     /**
570cdf0e10cSrcweir       Perform a ASCII lowercase comparison of two strings.
571cdf0e10cSrcweir 
572cdf0e10cSrcweir       The result is true if and only if second string
573cdf0e10cSrcweir       represents the same sequence of characters as the first string,
574cdf0e10cSrcweir       ignoring the case.
575cdf0e10cSrcweir       Character values between 65 and 90 (ASCII A-Z) are interpreted as
576cdf0e10cSrcweir       values between 97 and 122 (ASCII a-z).
577cdf0e10cSrcweir       Since this method is optimized for performance, the ASCII character
578cdf0e10cSrcweir       values are not converted in any way. The caller has to make sure that
579cdf0e10cSrcweir       all ASCII characters are in the allowed range between 0 and
580cdf0e10cSrcweir       127. The ASCII string must be NULL-terminated.
581cdf0e10cSrcweir       This function can't be used for language specific comparison.
582cdf0e10cSrcweir 
583cdf0e10cSrcweir       @param    asciiStr        the 8-Bit ASCII character string to be compared.
584cdf0e10cSrcweir       @return   sal_True if the strings are equal;
585cdf0e10cSrcweir                 sal_False, otherwise.
586cdf0e10cSrcweir     */
equalsIgnoreAsciiCaseAscii(const sal_Char * asciiStr) const587cdf0e10cSrcweir     sal_Bool equalsIgnoreAsciiCaseAscii( const sal_Char * asciiStr ) const SAL_THROW(())
588cdf0e10cSrcweir     {
589cdf0e10cSrcweir         return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr ) == 0;
590cdf0e10cSrcweir     }
591cdf0e10cSrcweir 
592cdf0e10cSrcweir     /**
593cdf0e10cSrcweir       Perform a ASCII lowercase comparison of two strings.
594cdf0e10cSrcweir 
595cdf0e10cSrcweir       The result is true if and only if second string
596cdf0e10cSrcweir       represents the same sequence of characters as the first string,
597cdf0e10cSrcweir       ignoring the case.
598cdf0e10cSrcweir       Character values between 65 and 90 (ASCII A-Z) are interpreted as
599cdf0e10cSrcweir       values between 97 and 122 (ASCII a-z).
600cdf0e10cSrcweir       Since this method is optimized for performance, the ASCII character
601cdf0e10cSrcweir       values are not converted in any way. The caller has to make sure that
602cdf0e10cSrcweir       all ASCII characters are in the allowed range between 0 and
603cdf0e10cSrcweir       127. The ASCII string must be NULL-terminated and must be greater or
604cdf0e10cSrcweir       equal as asciiStrLength.
605cdf0e10cSrcweir       This function can't be used for language specific comparison.
606cdf0e10cSrcweir 
607cdf0e10cSrcweir       @param    asciiStr        the 8-Bit ASCII character string to be compared.
608cdf0e10cSrcweir       @param    asciiStrLength  the length of the ascii string
609cdf0e10cSrcweir       @return   sal_True if the strings are equal;
610cdf0e10cSrcweir                 sal_False, otherwise.
611cdf0e10cSrcweir     */
equalsIgnoreAsciiCaseAsciiL(const sal_Char * asciiStr,sal_Int32 asciiStrLength) const612cdf0e10cSrcweir     sal_Bool equalsIgnoreAsciiCaseAsciiL( const sal_Char * asciiStr, sal_Int32 asciiStrLength ) const SAL_THROW(())
613cdf0e10cSrcweir     {
614cdf0e10cSrcweir         if ( pData->length != asciiStrLength )
615cdf0e10cSrcweir             return sal_False;
616cdf0e10cSrcweir 
617cdf0e10cSrcweir         return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr ) == 0;
618cdf0e10cSrcweir     }
619cdf0e10cSrcweir 
620cdf0e10cSrcweir     /**
621cdf0e10cSrcweir       Match against a substring appearing in this string.
622cdf0e10cSrcweir 
623cdf0e10cSrcweir       The result is true if and only if the second string appears as a substring
624cdf0e10cSrcweir       of this string, at the given position.
625cdf0e10cSrcweir       Since this method is optimized for performance, the ASCII character
626cdf0e10cSrcweir       values are not converted in any way. The caller has to make sure that
627cdf0e10cSrcweir       all ASCII characters are in the allowed range between 0 and
628cdf0e10cSrcweir       127. The ASCII string must be NULL-terminated and must be greater or
629cdf0e10cSrcweir       equal as asciiStrLength.
630cdf0e10cSrcweir       This function can't be used for language specific comparison.
631cdf0e10cSrcweir 
632cdf0e10cSrcweir       @param    str         the object (substring) to be compared.
633cdf0e10cSrcweir       @param    fromIndex   the index to start the comparion from.
634cdf0e10cSrcweir                             The index must be greater or equal than 0
635cdf0e10cSrcweir                             and less or equal as the string length.
636cdf0e10cSrcweir       @return   sal_True if str match with the characters in the string
637cdf0e10cSrcweir                 at the given position;
638cdf0e10cSrcweir                 sal_False, otherwise.
639cdf0e10cSrcweir     */
matchAsciiL(const sal_Char * asciiStr,sal_Int32 asciiStrLength,sal_Int32 fromIndex=0) const640cdf0e10cSrcweir     sal_Bool matchAsciiL( const sal_Char* asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
641cdf0e10cSrcweir     {
642cdf0e10cSrcweir         return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
643cdf0e10cSrcweir                                                            asciiStr, asciiStrLength ) == 0;
644cdf0e10cSrcweir     }
645cdf0e10cSrcweir 
646cdf0e10cSrcweir     /**
647cdf0e10cSrcweir       Match against a substring appearing in this string, ignoring the case of
648cdf0e10cSrcweir       ASCII letters.
649cdf0e10cSrcweir 
650cdf0e10cSrcweir       The result is true if and only if the second string appears as a substring
651cdf0e10cSrcweir       of this string, at the given position.
652cdf0e10cSrcweir       Character values between 65 and 90 (ASCII A-Z) are interpreted as
653cdf0e10cSrcweir       values between 97 and 122 (ASCII a-z).
654cdf0e10cSrcweir       Since this method is optimized for performance, the ASCII character
655cdf0e10cSrcweir       values are not converted in any way. The caller has to make sure that
656cdf0e10cSrcweir       all ASCII characters are in the allowed range between 0 and
657cdf0e10cSrcweir       127. The ASCII string must be NULL-terminated and must be greater or
658cdf0e10cSrcweir       equal as asciiStrLength.
659cdf0e10cSrcweir       This function can't be used for language specific comparison.
660cdf0e10cSrcweir 
661cdf0e10cSrcweir       @param    asciiStr        the 8-Bit ASCII character string to be compared.
662cdf0e10cSrcweir       @param    asciiStrLength  the length of the ascii string
663cdf0e10cSrcweir       @param    fromIndex       the index to start the comparion from.
664cdf0e10cSrcweir                                 The index must be greater or equal than 0
665cdf0e10cSrcweir                                 and less or equal as the string length.
666cdf0e10cSrcweir       @return   sal_True if str match with the characters in the string
667cdf0e10cSrcweir                 at the given position;
668cdf0e10cSrcweir                 sal_False, otherwise.
669cdf0e10cSrcweir     */
matchIgnoreAsciiCaseAsciiL(const sal_Char * asciiStr,sal_Int32 asciiStrLength,sal_Int32 fromIndex=0) const670cdf0e10cSrcweir     sal_Bool matchIgnoreAsciiCaseAsciiL( const sal_Char* asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
671cdf0e10cSrcweir     {
672cdf0e10cSrcweir         return rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
673cdf0e10cSrcweir                                                                           asciiStr, asciiStrLength ) == 0;
674cdf0e10cSrcweir     }
675cdf0e10cSrcweir 
676cdf0e10cSrcweir     /**
677cdf0e10cSrcweir       Check whether this string ends with a given ASCII string.
678cdf0e10cSrcweir 
679cdf0e10cSrcweir       @param asciiStr a sequence of at least asciiStrLength ASCII characters
680cdf0e10cSrcweir           (bytes in the range 0x00--0x7F)
681cdf0e10cSrcweir       @param asciiStrLen the length of asciiStr; must be non-negative
682cdf0e10cSrcweir       @return true if this string ends with asciiStr; otherwise, false is
683cdf0e10cSrcweir       returned
684cdf0e10cSrcweir 
685cdf0e10cSrcweir       @since UDK 3.2.7
686cdf0e10cSrcweir      */
endsWithAsciiL(char const * asciiStr,sal_Int32 asciiStrLength) const687cdf0e10cSrcweir     inline bool endsWithAsciiL(char const * asciiStr, sal_Int32 asciiStrLength)
688cdf0e10cSrcweir         const
689cdf0e10cSrcweir     {
690cdf0e10cSrcweir         return asciiStrLength <= pData->length
691cdf0e10cSrcweir             && rtl_ustr_asciil_reverseEquals_WithLength(
692cdf0e10cSrcweir                 pData->buffer + pData->length - asciiStrLength, asciiStr,
693cdf0e10cSrcweir                 asciiStrLength);
694cdf0e10cSrcweir     }
695cdf0e10cSrcweir 
696cdf0e10cSrcweir     /**
697cdf0e10cSrcweir       Check whether this string ends with a given ASCII string, ignoring the
698cdf0e10cSrcweir       case of ASCII letters.
699cdf0e10cSrcweir 
700cdf0e10cSrcweir       @param asciiStr a sequence of at least asciiStrLength ASCII characters
701cdf0e10cSrcweir           (bytes in the range 0x00--0x7F)
702cdf0e10cSrcweir       @param asciiStrLen the length of asciiStr; must be non-negative
703cdf0e10cSrcweir       @return true if this string ends with asciiStr, ignoring the case of ASCII
704cdf0e10cSrcweir       letters ("A"--"Z" and "a"--"z"); otherwise, false is returned
705cdf0e10cSrcweir      */
endsWithIgnoreAsciiCaseAsciiL(char const * asciiStr,sal_Int32 asciiStrLength) const706cdf0e10cSrcweir     inline bool endsWithIgnoreAsciiCaseAsciiL(
707cdf0e10cSrcweir         char const * asciiStr, sal_Int32 asciiStrLength) const
708cdf0e10cSrcweir     {
709cdf0e10cSrcweir         return asciiStrLength <= pData->length
710cdf0e10cSrcweir             && (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
711cdf0e10cSrcweir                     pData->buffer + pData->length - asciiStrLength,
712cdf0e10cSrcweir                     asciiStrLength, asciiStr, asciiStrLength)
713cdf0e10cSrcweir                 == 0);
714cdf0e10cSrcweir     }
715cdf0e10cSrcweir 
operator ==(const OUString & rStr1,const OUString & rStr2)716cdf0e10cSrcweir     friend sal_Bool     operator == ( const OUString& rStr1,    const OUString& rStr2 ) SAL_THROW(())
717cdf0e10cSrcweir                         { return rStr1.getLength() == rStr2.getLength() && rStr1.compareTo( rStr2 ) == 0; }
operator ==(const OUString & rStr1,const sal_Unicode * pStr2)718cdf0e10cSrcweir     friend sal_Bool     operator == ( const OUString& rStr1,    const sal_Unicode * pStr2 ) SAL_THROW(())
719cdf0e10cSrcweir                         { return rStr1.compareTo( pStr2 ) == 0; }
operator ==(const sal_Unicode * pStr1,const OUString & rStr2)720cdf0e10cSrcweir     friend sal_Bool     operator == ( const sal_Unicode * pStr1,    const OUString& rStr2 ) SAL_THROW(())
721cdf0e10cSrcweir                         { return OUString( pStr1 ).compareTo( rStr2 ) == 0; }
722cdf0e10cSrcweir 
operator !=(const OUString & rStr1,const OUString & rStr2)723cdf0e10cSrcweir     friend sal_Bool     operator != ( const OUString& rStr1,        const OUString& rStr2 ) SAL_THROW(())
724cdf0e10cSrcweir                         { return !(operator == ( rStr1, rStr2 )); }
operator !=(const OUString & rStr1,const sal_Unicode * pStr2)725cdf0e10cSrcweir     friend sal_Bool     operator != ( const OUString& rStr1,    const sal_Unicode * pStr2 ) SAL_THROW(())
726cdf0e10cSrcweir                         { return !(operator == ( rStr1, pStr2 )); }
operator !=(const sal_Unicode * pStr1,const OUString & rStr2)727cdf0e10cSrcweir     friend sal_Bool     operator != ( const sal_Unicode * pStr1,    const OUString& rStr2 ) SAL_THROW(())
728cdf0e10cSrcweir                         { return !(operator == ( pStr1, rStr2 )); }
729cdf0e10cSrcweir 
operator <(const OUString & rStr1,const OUString & rStr2)730cdf0e10cSrcweir     friend sal_Bool     operator <  ( const OUString& rStr1,    const OUString& rStr2 ) SAL_THROW(())
731cdf0e10cSrcweir                         { return rStr1.compareTo( rStr2 ) < 0; }
operator >(const OUString & rStr1,const OUString & rStr2)732cdf0e10cSrcweir     friend sal_Bool     operator >  ( const OUString& rStr1,    const OUString& rStr2 ) SAL_THROW(())
733cdf0e10cSrcweir                         { return rStr1.compareTo( rStr2 ) > 0; }
operator <=(const OUString & rStr1,const OUString & rStr2)734cdf0e10cSrcweir     friend sal_Bool     operator <= ( const OUString& rStr1,    const OUString& rStr2 ) SAL_THROW(())
735cdf0e10cSrcweir                         { return rStr1.compareTo( rStr2 ) <= 0; }
operator >=(const OUString & rStr1,const OUString & rStr2)736cdf0e10cSrcweir     friend sal_Bool     operator >= ( const OUString& rStr1,    const OUString& rStr2 ) SAL_THROW(())
737cdf0e10cSrcweir                         { return rStr1.compareTo( rStr2 ) >= 0; }
738cdf0e10cSrcweir 
739cdf0e10cSrcweir     /**
740cdf0e10cSrcweir       Returns a hashcode for this string.
741cdf0e10cSrcweir 
742cdf0e10cSrcweir       @return   a hash code value for this object.
743cdf0e10cSrcweir 
744cdf0e10cSrcweir       @see rtl::OUStringHash for convenient use of STLPort's hash_map
745cdf0e10cSrcweir     */
hashCode() const746cdf0e10cSrcweir     sal_Int32 hashCode() const SAL_THROW(())
747cdf0e10cSrcweir     {
748cdf0e10cSrcweir         return rtl_ustr_hashCode_WithLength( pData->buffer, pData->length );
749cdf0e10cSrcweir     }
750cdf0e10cSrcweir 
751cdf0e10cSrcweir     /**
752cdf0e10cSrcweir       Returns the index within this string of the first occurrence of the
753cdf0e10cSrcweir       specified character, starting the search at the specified index.
754cdf0e10cSrcweir 
755cdf0e10cSrcweir       @param    ch          character to be located.
756cdf0e10cSrcweir       @param    fromIndex   the index to start the search from.
757cdf0e10cSrcweir                             The index must be greater or equal than 0
758cdf0e10cSrcweir                             and less or equal as the string length.
759cdf0e10cSrcweir       @return   the index of the first occurrence of the character in the
760cdf0e10cSrcweir                 character sequence represented by this string that is
761cdf0e10cSrcweir                 greater than or equal to fromIndex, or
762cdf0e10cSrcweir                 -1 if the character does not occur.
763cdf0e10cSrcweir     */
indexOf(sal_Unicode ch,sal_Int32 fromIndex=0) const764cdf0e10cSrcweir     sal_Int32 indexOf( sal_Unicode ch, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
765cdf0e10cSrcweir     {
766cdf0e10cSrcweir         sal_Int32 ret = rtl_ustr_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
767cdf0e10cSrcweir         return (ret < 0 ? ret : ret+fromIndex);
768cdf0e10cSrcweir     }
769cdf0e10cSrcweir 
770cdf0e10cSrcweir     /**
771cdf0e10cSrcweir       Returns the index within this string of the last occurrence of the
772cdf0e10cSrcweir       specified character, searching backward starting at the end.
773cdf0e10cSrcweir 
774cdf0e10cSrcweir       @param    ch          character to be located.
775cdf0e10cSrcweir       @return   the index of the last occurrence of the character in the
776cdf0e10cSrcweir                 character sequence represented by this string, or
777cdf0e10cSrcweir                 -1 if the character does not occur.
778cdf0e10cSrcweir     */
lastIndexOf(sal_Unicode ch) const779cdf0e10cSrcweir     sal_Int32 lastIndexOf( sal_Unicode ch ) const SAL_THROW(())
780cdf0e10cSrcweir     {
781cdf0e10cSrcweir         return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
782cdf0e10cSrcweir     }
783cdf0e10cSrcweir 
784cdf0e10cSrcweir     /**
785cdf0e10cSrcweir       Returns the index within this string of the last occurrence of the
786cdf0e10cSrcweir       specified character, searching backward starting before the specified
787cdf0e10cSrcweir       index.
788cdf0e10cSrcweir 
789cdf0e10cSrcweir       @param    ch          character to be located.
790cdf0e10cSrcweir       @param    fromIndex   the index before which to start the search.
791cdf0e10cSrcweir       @return   the index of the last occurrence of the character in the
792cdf0e10cSrcweir                 character sequence represented by this string that
793cdf0e10cSrcweir                 is less than fromIndex, or -1
794cdf0e10cSrcweir                 if the character does not occur before that point.
795cdf0e10cSrcweir     */
lastIndexOf(sal_Unicode ch,sal_Int32 fromIndex) const796cdf0e10cSrcweir     sal_Int32 lastIndexOf( sal_Unicode ch, sal_Int32 fromIndex ) const SAL_THROW(())
797cdf0e10cSrcweir     {
798cdf0e10cSrcweir         return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
799cdf0e10cSrcweir     }
800cdf0e10cSrcweir 
801cdf0e10cSrcweir     /**
802cdf0e10cSrcweir       Returns the index within this string of the first occurrence of the
803cdf0e10cSrcweir       specified substring, starting at the specified index.
804cdf0e10cSrcweir 
805cdf0e10cSrcweir       If str doesn't include any character, always -1 is
806cdf0e10cSrcweir       returned. This is also the case, if both strings are empty.
807cdf0e10cSrcweir 
808cdf0e10cSrcweir       @param    str         the substring to search for.
809cdf0e10cSrcweir       @param    fromIndex   the index to start the search from.
810cdf0e10cSrcweir       @return   If the string argument occurs one or more times as a substring
811cdf0e10cSrcweir                 within this string at the starting index, then the index
812cdf0e10cSrcweir                 of the first character of the first such substring is
813cdf0e10cSrcweir                 returned. If it does not occur as a substring starting
814cdf0e10cSrcweir                 at fromIndex or beyond, -1 is returned.
815cdf0e10cSrcweir     */
indexOf(const OUString & str,sal_Int32 fromIndex=0) const816cdf0e10cSrcweir     sal_Int32 indexOf( const OUString & str, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
817cdf0e10cSrcweir     {
818cdf0e10cSrcweir         sal_Int32 ret = rtl_ustr_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
819cdf0e10cSrcweir                                                         str.pData->buffer, str.pData->length );
820cdf0e10cSrcweir         return (ret < 0 ? ret : ret+fromIndex);
821cdf0e10cSrcweir     }
822cdf0e10cSrcweir 
823cdf0e10cSrcweir     /**
824cdf0e10cSrcweir        Returns the index within this string of the first occurrence of the
825cdf0e10cSrcweir        specified ASCII substring, starting at the specified index.
826cdf0e10cSrcweir 
827cdf0e10cSrcweir        @param str
828cdf0e10cSrcweir        the substring to be searched for.  Need not be null-terminated, but must
829cdf0e10cSrcweir        be at least as long as the specified len.  Must only contain characters
830cdf0e10cSrcweir        in the ASCII range 0x00--7F.
831cdf0e10cSrcweir 
832cdf0e10cSrcweir        @param len
833cdf0e10cSrcweir        the length of the substring; must be non-negative.
834cdf0e10cSrcweir 
835cdf0e10cSrcweir        @param fromIndex
836cdf0e10cSrcweir        the index to start the search from.  Must be in the range from zero to
837cdf0e10cSrcweir        the length of this string, inclusive.
838cdf0e10cSrcweir 
839cdf0e10cSrcweir        @return
840cdf0e10cSrcweir        the index (starting at 0) of the first character of the first occurrence
841cdf0e10cSrcweir        of the substring within this string starting at the given fromIndex, or
842cdf0e10cSrcweir        -1 if the substring does not occur.  If len is zero, -1 is returned.
843cdf0e10cSrcweir 
844cdf0e10cSrcweir        @since UDK 3.2.7
845cdf0e10cSrcweir     */
indexOfAsciiL(char const * str,sal_Int32 len,sal_Int32 fromIndex=0) const846cdf0e10cSrcweir     sal_Int32 indexOfAsciiL(
847cdf0e10cSrcweir         char const * str, sal_Int32 len, sal_Int32 fromIndex = 0) const
848cdf0e10cSrcweir         SAL_THROW(())
849cdf0e10cSrcweir     {
850cdf0e10cSrcweir         sal_Int32 ret = rtl_ustr_indexOfAscii_WithLength(
851cdf0e10cSrcweir             pData->buffer + fromIndex, pData->length - fromIndex, str, len);
852cdf0e10cSrcweir         return ret < 0 ? ret : ret + fromIndex;
853cdf0e10cSrcweir     }
854cdf0e10cSrcweir 
855cdf0e10cSrcweir     /**
856cdf0e10cSrcweir       Returns the index within this string of the last occurrence of
857cdf0e10cSrcweir       the specified substring, searching backward starting at the end.
858cdf0e10cSrcweir 
859cdf0e10cSrcweir       The returned index indicates the starting index of the substring
860cdf0e10cSrcweir       in this string.
861cdf0e10cSrcweir       If str doesn't include any character, always -1 is
862cdf0e10cSrcweir       returned. This is also the case, if both strings are empty.
863cdf0e10cSrcweir 
864cdf0e10cSrcweir       @param    str         the substring to search for.
865cdf0e10cSrcweir       @return   If the string argument occurs one or more times as a substring
866cdf0e10cSrcweir                 within this string, then the index of the first character of
867cdf0e10cSrcweir                 the last such substring is returned. If it does not occur as
868cdf0e10cSrcweir                 a substring, -1 is returned.
869cdf0e10cSrcweir     */
lastIndexOf(const OUString & str) const870cdf0e10cSrcweir     sal_Int32 lastIndexOf( const OUString & str ) const SAL_THROW(())
871cdf0e10cSrcweir     {
872cdf0e10cSrcweir         return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, pData->length,
873cdf0e10cSrcweir                                                    str.pData->buffer, str.pData->length );
874cdf0e10cSrcweir     }
875cdf0e10cSrcweir 
876cdf0e10cSrcweir     /**
877cdf0e10cSrcweir       Returns the index within this string of the last occurrence of
878cdf0e10cSrcweir       the specified substring, searching backward starting before the specified
879cdf0e10cSrcweir       index.
880cdf0e10cSrcweir 
881cdf0e10cSrcweir       The returned index indicates the starting index of the substring
882cdf0e10cSrcweir       in this string.
883cdf0e10cSrcweir       If str doesn't include any character, always -1 is
884cdf0e10cSrcweir       returned. This is also the case, if both strings are empty.
885cdf0e10cSrcweir 
886cdf0e10cSrcweir       @param    str         the substring to search for.
887cdf0e10cSrcweir       @param    fromIndex   the index before which to start the search.
888cdf0e10cSrcweir       @return   If the string argument occurs one or more times as a substring
889cdf0e10cSrcweir                 within this string before the starting index, then the index
890cdf0e10cSrcweir                 of the first character of the last such substring is
891cdf0e10cSrcweir                 returned. Otherwise, -1 is returned.
892cdf0e10cSrcweir     */
lastIndexOf(const OUString & str,sal_Int32 fromIndex) const893cdf0e10cSrcweir     sal_Int32 lastIndexOf( const OUString & str, sal_Int32 fromIndex ) const SAL_THROW(())
894cdf0e10cSrcweir     {
895cdf0e10cSrcweir         return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
896cdf0e10cSrcweir                                                    str.pData->buffer, str.pData->length );
897cdf0e10cSrcweir     }
898cdf0e10cSrcweir 
899cdf0e10cSrcweir     /**
900cdf0e10cSrcweir        Returns the index within this string of the last occurrence of the
901cdf0e10cSrcweir        specified ASCII substring.
902cdf0e10cSrcweir 
903cdf0e10cSrcweir        @param str
904cdf0e10cSrcweir        the substring to be searched for.  Need not be null-terminated, but must
905cdf0e10cSrcweir        be at least as long as the specified len.  Must only contain characters
906cdf0e10cSrcweir        in the ASCII range 0x00--7F.
907cdf0e10cSrcweir 
908cdf0e10cSrcweir        @param len
909cdf0e10cSrcweir        the length of the substring; must be non-negative.
910cdf0e10cSrcweir 
911cdf0e10cSrcweir        @return
912cdf0e10cSrcweir        the index (starting at 0) of the first character of the last occurrence
913cdf0e10cSrcweir        of the substring within this string, or -1 if the substring does not
914cdf0e10cSrcweir        occur.  If len is zero, -1 is returned.
915cdf0e10cSrcweir 
916cdf0e10cSrcweir        @since UDK 3.2.7
917cdf0e10cSrcweir     */
lastIndexOfAsciiL(char const * str,sal_Int32 len) const918cdf0e10cSrcweir     sal_Int32 lastIndexOfAsciiL(char const * str, sal_Int32 len) const
919cdf0e10cSrcweir         SAL_THROW(())
920cdf0e10cSrcweir     {
921cdf0e10cSrcweir         return rtl_ustr_lastIndexOfAscii_WithLength(
922cdf0e10cSrcweir             pData->buffer, pData->length, str, len);
923cdf0e10cSrcweir     }
924cdf0e10cSrcweir 
925cdf0e10cSrcweir     /**
926cdf0e10cSrcweir       Returns a new string that is a substring of this string.
927cdf0e10cSrcweir 
928cdf0e10cSrcweir       The substring begins at the specified beginIndex.  It is an error for
929cdf0e10cSrcweir       beginIndex to be negative or to be greater than the length of this string.
930cdf0e10cSrcweir 
931cdf0e10cSrcweir       @param     beginIndex   the beginning index, inclusive.
932cdf0e10cSrcweir       @return    the specified substring.
933cdf0e10cSrcweir     */
copy(sal_Int32 beginIndex) const934cdf0e10cSrcweir     OUString copy( sal_Int32 beginIndex ) const SAL_THROW(())
935cdf0e10cSrcweir     {
936cdf0e10cSrcweir         OSL_ASSERT(beginIndex >= 0 && beginIndex <= getLength());
937cdf0e10cSrcweir         if ( beginIndex == 0 )
938cdf0e10cSrcweir             return *this;
939cdf0e10cSrcweir         else
940cdf0e10cSrcweir         {
941cdf0e10cSrcweir             rtl_uString* pNew = 0;
942cdf0e10cSrcweir             rtl_uString_newFromStr_WithLength( &pNew, pData->buffer+beginIndex, getLength()-beginIndex );
943cdf0e10cSrcweir             return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
944cdf0e10cSrcweir         }
945cdf0e10cSrcweir     }
946cdf0e10cSrcweir 
947cdf0e10cSrcweir     /**
948cdf0e10cSrcweir       Returns a new string that is a substring of this string.
949cdf0e10cSrcweir 
950cdf0e10cSrcweir       The substring begins at the specified beginIndex and contains count
951cdf0e10cSrcweir       characters.  It is an error for either beginIndex or count to be negative,
952cdf0e10cSrcweir       or for beginIndex + count to be greater than the length of this string.
953cdf0e10cSrcweir 
954cdf0e10cSrcweir       @param     beginIndex   the beginning index, inclusive.
955cdf0e10cSrcweir       @param     count        the number of characters.
956cdf0e10cSrcweir       @return    the specified substring.
957cdf0e10cSrcweir     */
copy(sal_Int32 beginIndex,sal_Int32 count) const958cdf0e10cSrcweir     OUString copy( sal_Int32 beginIndex, sal_Int32 count ) const SAL_THROW(())
959cdf0e10cSrcweir     {
960cdf0e10cSrcweir         OSL_ASSERT(beginIndex >= 0 && beginIndex <= getLength()
961cdf0e10cSrcweir                    && count >= 0 && count <= getLength() - beginIndex);
962cdf0e10cSrcweir         if ( (beginIndex == 0) && (count == getLength()) )
963cdf0e10cSrcweir             return *this;
964cdf0e10cSrcweir         else
965cdf0e10cSrcweir         {
966cdf0e10cSrcweir             rtl_uString* pNew = 0;
967cdf0e10cSrcweir             rtl_uString_newFromStr_WithLength( &pNew, pData->buffer+beginIndex, count );
968cdf0e10cSrcweir             return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
969cdf0e10cSrcweir         }
970cdf0e10cSrcweir     }
971cdf0e10cSrcweir 
972cdf0e10cSrcweir     /**
973cdf0e10cSrcweir       Concatenates the specified string to the end of this string.
974cdf0e10cSrcweir 
975cdf0e10cSrcweir       @param    str   the string that is concatenated to the end
976cdf0e10cSrcweir                       of this string.
977cdf0e10cSrcweir       @return   a string that represents the concatenation of this string
978cdf0e10cSrcweir                 followed by the string argument.
979cdf0e10cSrcweir     */
concat(const OUString & str) const980cdf0e10cSrcweir     OUString concat( const OUString & str ) const SAL_THROW(())
981cdf0e10cSrcweir     {
982cdf0e10cSrcweir         rtl_uString* pNew = 0;
983cdf0e10cSrcweir         rtl_uString_newConcat( &pNew, pData, str.pData );
984cdf0e10cSrcweir         return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
985cdf0e10cSrcweir     }
986cdf0e10cSrcweir 
operator +(const OUString & rStr1,const OUString & rStr2)987cdf0e10cSrcweir     friend OUString operator+( const OUString& rStr1, const OUString& rStr2  ) SAL_THROW(())
988cdf0e10cSrcweir     {
989cdf0e10cSrcweir         return rStr1.concat( rStr2 );
990cdf0e10cSrcweir     }
991cdf0e10cSrcweir 
992cdf0e10cSrcweir     /**
993cdf0e10cSrcweir       Returns a new string resulting from replacing n = count characters
994cdf0e10cSrcweir       from position index in this string with newStr.
995cdf0e10cSrcweir 
996cdf0e10cSrcweir       @param  index   the replacing index in str.
997cdf0e10cSrcweir                       The index must be greater or equal as 0 and
998cdf0e10cSrcweir                       less or equal as the length of the string.
999cdf0e10cSrcweir       @param  count   the count of charcters that will replaced
1000cdf0e10cSrcweir                       The count must be greater or equal as 0 and
1001cdf0e10cSrcweir                       less or equal as the length of the string minus index.
1002cdf0e10cSrcweir       @param  newStr  the new substring.
1003cdf0e10cSrcweir       @return the new string.
1004cdf0e10cSrcweir     */
replaceAt(sal_Int32 index,sal_Int32 count,const OUString & newStr) const1005cdf0e10cSrcweir     OUString replaceAt( sal_Int32 index, sal_Int32 count, const OUString& newStr ) const SAL_THROW(())
1006cdf0e10cSrcweir     {
1007cdf0e10cSrcweir         rtl_uString* pNew = 0;
1008cdf0e10cSrcweir         rtl_uString_newReplaceStrAt( &pNew, pData, index, count, newStr.pData );
1009cdf0e10cSrcweir         return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1010cdf0e10cSrcweir     }
1011cdf0e10cSrcweir 
1012cdf0e10cSrcweir     /**
1013cdf0e10cSrcweir       Returns a new string resulting from replacing all occurrences of
1014cdf0e10cSrcweir       oldChar in this string with newChar.
1015cdf0e10cSrcweir 
1016cdf0e10cSrcweir       If the character oldChar does not occur in the character sequence
1017cdf0e10cSrcweir       represented by this object, then the string is assigned with
1018cdf0e10cSrcweir       str.
1019cdf0e10cSrcweir 
1020cdf0e10cSrcweir       @param    oldChar     the old character.
1021cdf0e10cSrcweir       @param    newChar     the new character.
1022cdf0e10cSrcweir       @return   a string derived from this string by replacing every
1023cdf0e10cSrcweir                 occurrence of oldChar with newChar.
1024cdf0e10cSrcweir     */
replace(sal_Unicode oldChar,sal_Unicode newChar) const1025cdf0e10cSrcweir     OUString replace( sal_Unicode oldChar, sal_Unicode newChar ) const SAL_THROW(())
1026cdf0e10cSrcweir     {
1027cdf0e10cSrcweir         rtl_uString* pNew = 0;
1028cdf0e10cSrcweir         rtl_uString_newReplace( &pNew, pData, oldChar, newChar );
1029cdf0e10cSrcweir         return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1030cdf0e10cSrcweir     }
1031cdf0e10cSrcweir 
1032cdf0e10cSrcweir     /**
1033cdf0e10cSrcweir       Converts from this string all ASCII uppercase characters (65-90)
1034cdf0e10cSrcweir       to ASCII lowercase characters (97-122).
1035cdf0e10cSrcweir 
1036cdf0e10cSrcweir       This function can't be used for language specific conversion.
1037cdf0e10cSrcweir       If the string doesn't contain characters which must be converted,
1038cdf0e10cSrcweir       then the new string is assigned with str.
1039cdf0e10cSrcweir 
1040cdf0e10cSrcweir       @return   the string, converted to ASCII lowercase.
1041cdf0e10cSrcweir     */
toAsciiLowerCase() const1042cdf0e10cSrcweir     OUString toAsciiLowerCase() const SAL_THROW(())
1043cdf0e10cSrcweir     {
1044cdf0e10cSrcweir         rtl_uString* pNew = 0;
1045cdf0e10cSrcweir         rtl_uString_newToAsciiLowerCase( &pNew, pData );
1046cdf0e10cSrcweir         return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1047cdf0e10cSrcweir     }
1048cdf0e10cSrcweir 
1049cdf0e10cSrcweir     /**
1050cdf0e10cSrcweir       Converts from this string all ASCII lowercase characters (97-122)
1051cdf0e10cSrcweir       to ASCII uppercase characters (65-90).
1052cdf0e10cSrcweir 
1053cdf0e10cSrcweir       This function can't be used for language specific conversion.
1054cdf0e10cSrcweir       If the string doesn't contain characters which must be converted,
1055cdf0e10cSrcweir       then the new string is assigned with str.
1056cdf0e10cSrcweir 
1057cdf0e10cSrcweir       @return   the string, converted to ASCII uppercase.
1058cdf0e10cSrcweir     */
toAsciiUpperCase() const1059cdf0e10cSrcweir     OUString toAsciiUpperCase() const SAL_THROW(())
1060cdf0e10cSrcweir     {
1061cdf0e10cSrcweir         rtl_uString* pNew = 0;
1062cdf0e10cSrcweir         rtl_uString_newToAsciiUpperCase( &pNew, pData );
1063cdf0e10cSrcweir         return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1064cdf0e10cSrcweir     }
1065cdf0e10cSrcweir 
1066cdf0e10cSrcweir     /**
1067cdf0e10cSrcweir       Returns a new string resulting from removing white space from both ends
1068cdf0e10cSrcweir       of the string.
1069cdf0e10cSrcweir 
1070cdf0e10cSrcweir       All characters that have codes less than or equal to
1071cdf0e10cSrcweir       32 (the space character) are considered to be white space.
1072cdf0e10cSrcweir       If the string doesn't contain white spaces at both ends,
1073cdf0e10cSrcweir       then the new string is assigned with str.
1074cdf0e10cSrcweir 
1075cdf0e10cSrcweir       @return   the string, with white space removed from the front and end.
1076cdf0e10cSrcweir     */
trim() const1077cdf0e10cSrcweir     OUString trim() const SAL_THROW(())
1078cdf0e10cSrcweir     {
1079cdf0e10cSrcweir         rtl_uString* pNew = 0;
1080cdf0e10cSrcweir         rtl_uString_newTrim( &pNew, pData );
1081cdf0e10cSrcweir         return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1082cdf0e10cSrcweir     }
1083cdf0e10cSrcweir 
1084cdf0e10cSrcweir     /**
1085cdf0e10cSrcweir       Returns a token in the string.
1086cdf0e10cSrcweir 
1087cdf0e10cSrcweir       Example:
1088cdf0e10cSrcweir         sal_Int32 nIndex = 0;
1089cdf0e10cSrcweir         do
1090cdf0e10cSrcweir         {
1091cdf0e10cSrcweir             ...
1092cdf0e10cSrcweir             OUString aToken = aStr.getToken( 0, ';', nIndex );
1093cdf0e10cSrcweir             ...
1094cdf0e10cSrcweir         }
1095cdf0e10cSrcweir         while ( nIndex >= 0 );
1096cdf0e10cSrcweir 
1097cdf0e10cSrcweir       @param    token       the number of the token to return
1098*86e1cf34SPedro Giffuni       @param    cTok        the character which separate the tokens.
1099cdf0e10cSrcweir       @param    index       the position at which the token is searched in the
1100cdf0e10cSrcweir                             string.
1101cdf0e10cSrcweir                             The index must not be greater than the length of the
1102cdf0e10cSrcweir                             string.
1103cdf0e10cSrcweir                             This param is set to the position of the
1104cdf0e10cSrcweir                             next token or to -1, if it is the last token.
1105cdf0e10cSrcweir       @return   the token; if either token or index is negative, an empty token
1106cdf0e10cSrcweir                 is returned (and index is set to -1)
1107cdf0e10cSrcweir     */
getToken(sal_Int32 token,sal_Unicode cTok,sal_Int32 & index) const1108cdf0e10cSrcweir     OUString getToken( sal_Int32 token, sal_Unicode cTok, sal_Int32& index ) const SAL_THROW(())
1109cdf0e10cSrcweir     {
1110cdf0e10cSrcweir         rtl_uString * pNew = 0;
1111cdf0e10cSrcweir         index = rtl_uString_getToken( &pNew, pData, token, cTok, index );
1112cdf0e10cSrcweir         return OUString( pNew, (DO_NOT_ACQUIRE *)0 );
1113cdf0e10cSrcweir     }
1114cdf0e10cSrcweir 
1115cdf0e10cSrcweir     /**
1116cdf0e10cSrcweir       Returns the Boolean value from this string.
1117cdf0e10cSrcweir 
1118cdf0e10cSrcweir       This function can't be used for language specific conversion.
1119cdf0e10cSrcweir 
1120cdf0e10cSrcweir       @return   sal_True, if the string is 1 or "True" in any ASCII case.
1121cdf0e10cSrcweir                 sal_False in any other case.
1122cdf0e10cSrcweir     */
toBoolean() const1123cdf0e10cSrcweir     sal_Bool toBoolean() const SAL_THROW(())
1124cdf0e10cSrcweir     {
1125cdf0e10cSrcweir         return rtl_ustr_toBoolean( pData->buffer );
1126cdf0e10cSrcweir     }
1127cdf0e10cSrcweir 
1128cdf0e10cSrcweir     /**
1129cdf0e10cSrcweir       Returns the first character from this string.
1130cdf0e10cSrcweir 
1131cdf0e10cSrcweir       @return   the first character from this string or 0, if this string
1132cdf0e10cSrcweir                 is emptry.
1133cdf0e10cSrcweir     */
toChar() const1134cdf0e10cSrcweir     sal_Unicode toChar() const SAL_THROW(())
1135cdf0e10cSrcweir     {
1136cdf0e10cSrcweir         return pData->buffer[0];
1137cdf0e10cSrcweir     }
1138cdf0e10cSrcweir 
1139cdf0e10cSrcweir     /**
1140cdf0e10cSrcweir       Returns the int32 value from this string.
1141cdf0e10cSrcweir 
1142cdf0e10cSrcweir       This function can't be used for language specific conversion.
1143cdf0e10cSrcweir 
1144cdf0e10cSrcweir       @param    radix       the radix (between 2 and 36)
1145cdf0e10cSrcweir       @return   the int32 represented from this string.
1146cdf0e10cSrcweir                 0 if this string represents no number.
1147cdf0e10cSrcweir     */
toInt32(sal_Int16 radix=10) const1148cdf0e10cSrcweir     sal_Int32 toInt32( sal_Int16 radix = 10 ) const SAL_THROW(())
1149cdf0e10cSrcweir     {
1150cdf0e10cSrcweir         return rtl_ustr_toInt32( pData->buffer, radix );
1151cdf0e10cSrcweir     }
1152cdf0e10cSrcweir 
1153cdf0e10cSrcweir     /**
1154cdf0e10cSrcweir       Returns the int64 value from this string.
1155cdf0e10cSrcweir 
1156cdf0e10cSrcweir       This function can't be used for language specific conversion.
1157cdf0e10cSrcweir 
1158cdf0e10cSrcweir       @param    radix       the radix (between 2 and 36)
1159cdf0e10cSrcweir       @return   the int64 represented from this string.
1160cdf0e10cSrcweir                 0 if this string represents no number.
1161cdf0e10cSrcweir     */
toInt64(sal_Int16 radix=10) const1162cdf0e10cSrcweir     sal_Int64 toInt64( sal_Int16 radix = 10 ) const SAL_THROW(())
1163cdf0e10cSrcweir     {
1164cdf0e10cSrcweir         return rtl_ustr_toInt64( pData->buffer, radix );
1165cdf0e10cSrcweir     }
1166cdf0e10cSrcweir 
1167cdf0e10cSrcweir     /**
1168cdf0e10cSrcweir       Returns the float value from this string.
1169cdf0e10cSrcweir 
1170cdf0e10cSrcweir       This function can't be used for language specific conversion.
1171cdf0e10cSrcweir 
1172cdf0e10cSrcweir       @return   the float represented from this string.
1173cdf0e10cSrcweir                 0.0 if this string represents no number.
1174cdf0e10cSrcweir     */
toFloat() const1175cdf0e10cSrcweir     float toFloat() const SAL_THROW(())
1176cdf0e10cSrcweir     {
1177cdf0e10cSrcweir         return rtl_ustr_toFloat( pData->buffer );
1178cdf0e10cSrcweir     }
1179cdf0e10cSrcweir 
1180cdf0e10cSrcweir     /**
1181cdf0e10cSrcweir       Returns the double value from this string.
1182cdf0e10cSrcweir 
1183cdf0e10cSrcweir       This function can't be used for language specific conversion.
1184cdf0e10cSrcweir 
1185cdf0e10cSrcweir       @return   the double represented from this string.
1186cdf0e10cSrcweir                 0.0 if this string represents no number.
1187cdf0e10cSrcweir     */
toDouble() const1188cdf0e10cSrcweir     double toDouble() const SAL_THROW(())
1189cdf0e10cSrcweir     {
1190cdf0e10cSrcweir         return rtl_ustr_toDouble( pData->buffer );
1191cdf0e10cSrcweir     }
1192cdf0e10cSrcweir 
1193cdf0e10cSrcweir 
1194cdf0e10cSrcweir     /**
1195cdf0e10cSrcweir        Return a canonical representation for a string.
1196cdf0e10cSrcweir 
1197cdf0e10cSrcweir        A pool of strings, initially empty is maintained privately
1198cdf0e10cSrcweir        by the string class. On invocation, if present in the pool
1199cdf0e10cSrcweir        the original string will be returned. Otherwise this string,
1200cdf0e10cSrcweir        or a copy thereof will be added to the pool and returned.
1201cdf0e10cSrcweir 
1202cdf0e10cSrcweir        @return
1203cdf0e10cSrcweir        a version of the string from the pool.
1204cdf0e10cSrcweir 
1205cdf0e10cSrcweir        @exception std::bad_alloc is thrown if an out-of-memory condition occurs
1206cdf0e10cSrcweir 
1207cdf0e10cSrcweir        @since UDK 3.2.7
1208cdf0e10cSrcweir     */
intern() const1209cdf0e10cSrcweir     OUString intern() const
1210cdf0e10cSrcweir     {
1211cdf0e10cSrcweir         rtl_uString * pNew = 0;
1212cdf0e10cSrcweir         rtl_uString_intern( &pNew, pData );
1213cdf0e10cSrcweir #if defined EXCEPTIONS_OFF
1214cdf0e10cSrcweir         OSL_ASSERT(pNew != NULL);
1215cdf0e10cSrcweir #else
1216cdf0e10cSrcweir         if (pNew == 0) {
1217cdf0e10cSrcweir             throw std::bad_alloc();
1218cdf0e10cSrcweir         }
1219cdf0e10cSrcweir #endif
1220cdf0e10cSrcweir         return OUString( pNew, (DO_NOT_ACQUIRE *)0 );
1221cdf0e10cSrcweir     }
1222cdf0e10cSrcweir 
1223cdf0e10cSrcweir     /**
1224cdf0e10cSrcweir        Return a canonical representation for a converted string.
1225cdf0e10cSrcweir 
1226cdf0e10cSrcweir        A pool of strings, initially empty is maintained privately
1227cdf0e10cSrcweir        by the string class. On invocation, if present in the pool
1228cdf0e10cSrcweir        the original string will be returned. Otherwise this string,
1229cdf0e10cSrcweir        or a copy thereof will be added to the pool and returned.
1230cdf0e10cSrcweir 
1231cdf0e10cSrcweir        @param    value           a 8-Bit character array.
1232cdf0e10cSrcweir        @param    length          the number of character which should be converted.
1233cdf0e10cSrcweir                                  The 8-Bit character array length must be
1234cdf0e10cSrcweir                                  greater or equal than this value.
1235cdf0e10cSrcweir        @param    encoding        the text encoding from which the 8-Bit character
1236cdf0e10cSrcweir                                  sequence should be converted.
1237cdf0e10cSrcweir        @param    convertFlags    flags which controls the conversion.
1238cdf0e10cSrcweir                                  see RTL_TEXTTOUNICODE_FLAGS_...
1239cdf0e10cSrcweir        @param    pInfo           pointer to return conversion status or NULL.
1240cdf0e10cSrcweir 
1241cdf0e10cSrcweir        @return
1242cdf0e10cSrcweir        a version of the converted string from the pool.
1243cdf0e10cSrcweir 
1244cdf0e10cSrcweir        @exception std::bad_alloc is thrown if an out-of-memory condition occurs
1245cdf0e10cSrcweir 
1246cdf0e10cSrcweir        @since UDK 3.2.7
1247cdf0e10cSrcweir     */
intern(const sal_Char * value,sal_Int32 length,rtl_TextEncoding encoding,sal_uInt32 convertFlags=OSTRING_TO_OUSTRING_CVTFLAGS,sal_uInt32 * pInfo=NULL)1248cdf0e10cSrcweir     static OUString intern( const sal_Char * value, sal_Int32 length,
1249cdf0e10cSrcweir                             rtl_TextEncoding encoding,
1250cdf0e10cSrcweir                             sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS,
1251cdf0e10cSrcweir                             sal_uInt32 *pInfo = NULL )
1252cdf0e10cSrcweir     {
1253cdf0e10cSrcweir         rtl_uString * pNew = 0;
1254cdf0e10cSrcweir         rtl_uString_internConvert( &pNew, value, length, encoding,
1255cdf0e10cSrcweir                                    convertFlags, pInfo );
1256cdf0e10cSrcweir #if defined EXCEPTIONS_OFF
1257cdf0e10cSrcweir         OSL_ASSERT(pNew != NULL);
1258cdf0e10cSrcweir #else
1259cdf0e10cSrcweir         if (pNew == 0) {
1260cdf0e10cSrcweir             throw std::bad_alloc();
1261cdf0e10cSrcweir         }
1262cdf0e10cSrcweir #endif
1263cdf0e10cSrcweir         return OUString( pNew, (DO_NOT_ACQUIRE *)0 );
1264cdf0e10cSrcweir     }
1265cdf0e10cSrcweir 
1266cdf0e10cSrcweir     /**
1267cdf0e10cSrcweir       Converts to an OString, signalling failure.
1268cdf0e10cSrcweir 
1269cdf0e10cSrcweir       @param pTarget
1270cdf0e10cSrcweir       An out parameter receiving the converted OString.  Must not be null; the
1271cdf0e10cSrcweir       contents are not modified if conversion fails (convertToOString returns
1272cdf0e10cSrcweir       false).
1273cdf0e10cSrcweir 
1274cdf0e10cSrcweir       @param nEncoding
1275cdf0e10cSrcweir       The text encoding to convert into.  Must be an octet encoding (i.e.,
1276cdf0e10cSrcweir       rtl_isOctetTextEncoding(nEncoding) must return true).
1277cdf0e10cSrcweir 
1278cdf0e10cSrcweir       @param nFlags
1279cdf0e10cSrcweir       A combination of RTL_UNICODETOTEXT_FLAGS that detail how to do the
1280cdf0e10cSrcweir       conversion (see rtl_convertUnicodeToText).  RTL_UNICODETOTEXT_FLAGS_FLUSH
1281cdf0e10cSrcweir       need not be included, it is implicitly assumed.  Typical uses are either
1282cdf0e10cSrcweir       RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
1283cdf0e10cSrcweir       RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR (fail if a Unicode character cannot
1284cdf0e10cSrcweir       be converted to the target nEncoding) or OUSTRING_TO_OSTRING_CVTFLAGS
1285cdf0e10cSrcweir       (make a best efforts conversion).
1286cdf0e10cSrcweir 
1287cdf0e10cSrcweir       @return
1288cdf0e10cSrcweir       True if the conversion succeeded, false otherwise.
1289cdf0e10cSrcweir      */
convertToString(OString * pTarget,rtl_TextEncoding nEncoding,sal_uInt32 nFlags) const1290cdf0e10cSrcweir     inline bool convertToString(OString * pTarget, rtl_TextEncoding nEncoding,
1291cdf0e10cSrcweir                                 sal_uInt32 nFlags) const
1292cdf0e10cSrcweir     {
1293cdf0e10cSrcweir         return rtl_convertUStringToString(&pTarget->pData, pData->buffer,
1294cdf0e10cSrcweir                                             pData->length, nEncoding, nFlags);
1295cdf0e10cSrcweir     }
1296cdf0e10cSrcweir 
1297cdf0e10cSrcweir     /** Iterate through this string based on code points instead of UTF-16 code
1298cdf0e10cSrcweir         units.
1299cdf0e10cSrcweir 
1300cdf0e10cSrcweir         See Chapter 3 of The Unicode Standard 5.0 (Addison--Wesley, 2006) for
1301cdf0e10cSrcweir         definitions of the various terms used in this description.
1302cdf0e10cSrcweir 
1303cdf0e10cSrcweir         This string is interpreted as a sequence of zero or more UTF-16 code
1304cdf0e10cSrcweir         units.  For each index into this sequence (from zero to one less than
1305cdf0e10cSrcweir         the length of the sequence, inclusive), a code point represented
1306cdf0e10cSrcweir         starting at the given index is computed as follows:
1307cdf0e10cSrcweir 
1308cdf0e10cSrcweir         - If the UTF-16 code unit addressed by the index constitutes a
1309cdf0e10cSrcweir         well-formed UTF-16 code unit sequence, the computed code point is the
1310cdf0e10cSrcweir         scalar value encoded by that UTF-16 code unit sequence.
1311cdf0e10cSrcweir 
1312cdf0e10cSrcweir         - Otherwise, if the index is at least two UTF-16 code units away from
1313cdf0e10cSrcweir         the end of the sequence, and the sequence of two UTF-16 code units
1314cdf0e10cSrcweir         addressed by the index constitutes a well-formed UTF-16 code unit
1315cdf0e10cSrcweir         sequence, the computed code point is the scalar value encoded by that
1316cdf0e10cSrcweir         UTF-16 code unit sequence.
1317cdf0e10cSrcweir 
1318cdf0e10cSrcweir         - Otherwise, the computed code point is the UTF-16 code unit addressed
1319cdf0e10cSrcweir         by the index.  (This last case catches unmatched surrogates as well as
1320cdf0e10cSrcweir         indices pointing into the middle of surrogate pairs.)
1321cdf0e10cSrcweir 
1322cdf0e10cSrcweir         @param indexUtf16
1323cdf0e10cSrcweir         pointer to a UTF-16 based index into this string; must not be null.  On
1324cdf0e10cSrcweir         entry, the index must be in the range from zero to the length of this
1325cdf0e10cSrcweir         string (in UTF-16 code units), inclusive.  Upon successful return, the
1326cdf0e10cSrcweir         index will be updated to address the UTF-16 code unit that is the given
1327cdf0e10cSrcweir         incrementCodePoints away from the initial index.
1328cdf0e10cSrcweir 
1329cdf0e10cSrcweir         @param incrementCodePoints
1330cdf0e10cSrcweir         the number of code points to move the given *indexUtf16.  If
1331cdf0e10cSrcweir         non-negative, moving is done after determining the code point at the
1332cdf0e10cSrcweir         index.  If negative, moving is done before determining the code point
1333cdf0e10cSrcweir         at the (then updated) index.  The value must be such that the resulting
1334cdf0e10cSrcweir         UTF-16 based index is in the range from zero to the length of this
1335cdf0e10cSrcweir         string (in UTF-16 code units), inclusive.
1336cdf0e10cSrcweir 
1337cdf0e10cSrcweir         @return
1338cdf0e10cSrcweir         the code point (an integer in the range from 0 to 0x10FFFF, inclusive)
1339cdf0e10cSrcweir         that is represented within this string starting at the index computed as
1340cdf0e10cSrcweir         follows:  If incrementCodePoints is non-negative, the index is the
1341cdf0e10cSrcweir         initial value of *indexUtf16; if incrementCodePoints is negative, the
1342cdf0e10cSrcweir         index is the updated value of *indexUtf16.  In either case, the computed
1343cdf0e10cSrcweir         index must be in the range from zero to one less than the length of this
1344cdf0e10cSrcweir         string (in UTF-16 code units), inclusive.
1345cdf0e10cSrcweir 
1346cdf0e10cSrcweir         @since UDK 3.2.7
1347cdf0e10cSrcweir     */
iterateCodePoints(sal_Int32 * indexUtf16,sal_Int32 incrementCodePoints=1) const1348cdf0e10cSrcweir     inline sal_uInt32 iterateCodePoints(
1349cdf0e10cSrcweir         sal_Int32 * indexUtf16, sal_Int32 incrementCodePoints = 1) const
1350cdf0e10cSrcweir     {
1351cdf0e10cSrcweir         return rtl_uString_iterateCodePoints(
1352cdf0e10cSrcweir             pData, indexUtf16, incrementCodePoints);
1353cdf0e10cSrcweir     }
1354cdf0e10cSrcweir 
1355cdf0e10cSrcweir     /**
1356cdf0e10cSrcweir       Returns the string representation of the sal_Bool argument.
1357cdf0e10cSrcweir 
1358cdf0e10cSrcweir       If the sal_Bool is true, the string "true" is returned.
1359cdf0e10cSrcweir       If the sal_Bool is false, the string "false" is returned.
1360cdf0e10cSrcweir       This function can't be used for language specific conversion.
1361cdf0e10cSrcweir 
1362cdf0e10cSrcweir       @param    b   a sal_Bool.
1363cdf0e10cSrcweir       @return   a string with the string representation of the argument.
1364cdf0e10cSrcweir     */
valueOf(sal_Bool b)1365cdf0e10cSrcweir     static OUString valueOf( sal_Bool b ) SAL_THROW(())
1366cdf0e10cSrcweir     {
1367cdf0e10cSrcweir         sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFBOOLEAN];
1368cdf0e10cSrcweir         rtl_uString* pNewData = 0;
1369cdf0e10cSrcweir         rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfBoolean( aBuf, b ) );
1370cdf0e10cSrcweir         return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
1371cdf0e10cSrcweir     }
1372cdf0e10cSrcweir 
1373cdf0e10cSrcweir     /**
1374cdf0e10cSrcweir       Returns the string representation of the char argument.
1375cdf0e10cSrcweir 
1376cdf0e10cSrcweir       @param    c   a character.
1377cdf0e10cSrcweir       @return   a string with the string representation of the argument.
1378cdf0e10cSrcweir     */
valueOf(sal_Unicode c)1379cdf0e10cSrcweir     static OUString valueOf( sal_Unicode c ) SAL_THROW(())
1380cdf0e10cSrcweir     {
1381cdf0e10cSrcweir         return OUString( &c, 1 );
1382cdf0e10cSrcweir     }
1383cdf0e10cSrcweir 
1384cdf0e10cSrcweir     /**
1385cdf0e10cSrcweir       Returns the string representation of the int argument.
1386cdf0e10cSrcweir 
1387cdf0e10cSrcweir       This function can't be used for language specific conversion.
1388cdf0e10cSrcweir 
1389cdf0e10cSrcweir       @param    i           a int32.
1390cdf0e10cSrcweir       @param    radix       the radix (between 2 and 36)
1391cdf0e10cSrcweir       @return   a string with the string representation of the argument.
1392cdf0e10cSrcweir     */
valueOf(sal_Int32 i,sal_Int16 radix=10)1393cdf0e10cSrcweir     static OUString valueOf( sal_Int32 i, sal_Int16 radix = 10 ) SAL_THROW(())
1394cdf0e10cSrcweir     {
1395cdf0e10cSrcweir         sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFINT32];
1396cdf0e10cSrcweir         rtl_uString* pNewData = 0;
1397cdf0e10cSrcweir         rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfInt32( aBuf, i, radix ) );
1398cdf0e10cSrcweir         return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
1399cdf0e10cSrcweir     }
1400cdf0e10cSrcweir 
1401cdf0e10cSrcweir     /**
1402cdf0e10cSrcweir       Returns the string representation of the long argument.
1403cdf0e10cSrcweir 
1404cdf0e10cSrcweir       This function can't be used for language specific conversion.
1405cdf0e10cSrcweir 
1406cdf0e10cSrcweir       @param    ll          a int64.
1407cdf0e10cSrcweir       @param    radix       the radix (between 2 and 36)
1408cdf0e10cSrcweir       @return   a string with the string representation of the argument.
1409cdf0e10cSrcweir     */
valueOf(sal_Int64 ll,sal_Int16 radix=10)1410cdf0e10cSrcweir     static OUString valueOf( sal_Int64 ll, sal_Int16 radix = 10 ) SAL_THROW(())
1411cdf0e10cSrcweir     {
1412cdf0e10cSrcweir         sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFINT64];
1413cdf0e10cSrcweir         rtl_uString* pNewData = 0;
1414cdf0e10cSrcweir         rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfInt64( aBuf, ll, radix ) );
1415cdf0e10cSrcweir         return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
1416cdf0e10cSrcweir     }
1417cdf0e10cSrcweir 
1418cdf0e10cSrcweir     /**
1419cdf0e10cSrcweir       Returns the string representation of the float argument.
1420cdf0e10cSrcweir 
1421cdf0e10cSrcweir       This function can't be used for language specific conversion.
1422cdf0e10cSrcweir 
1423cdf0e10cSrcweir       @param    f           a float.
1424cdf0e10cSrcweir       @return   a string with the string representation of the argument.
1425cdf0e10cSrcweir     */
valueOf(float f)1426cdf0e10cSrcweir     static OUString valueOf( float f ) SAL_THROW(())
1427cdf0e10cSrcweir     {
1428cdf0e10cSrcweir         sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFFLOAT];
1429cdf0e10cSrcweir         rtl_uString* pNewData = 0;
1430cdf0e10cSrcweir         rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfFloat( aBuf, f ) );
1431cdf0e10cSrcweir         return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
1432cdf0e10cSrcweir     }
1433cdf0e10cSrcweir 
1434cdf0e10cSrcweir     /**
1435cdf0e10cSrcweir       Returns the string representation of the double argument.
1436cdf0e10cSrcweir 
1437cdf0e10cSrcweir       This function can't be used for language specific conversion.
1438cdf0e10cSrcweir 
1439cdf0e10cSrcweir       @param    d           a double.
1440cdf0e10cSrcweir       @return   a string with the string representation of the argument.
1441cdf0e10cSrcweir     */
valueOf(double d)1442cdf0e10cSrcweir     static OUString valueOf( double d ) SAL_THROW(())
1443cdf0e10cSrcweir     {
1444cdf0e10cSrcweir         sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFDOUBLE];
1445cdf0e10cSrcweir         rtl_uString* pNewData = 0;
1446cdf0e10cSrcweir         rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfDouble( aBuf, d ) );
1447cdf0e10cSrcweir         return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
1448cdf0e10cSrcweir     }
1449cdf0e10cSrcweir 
1450cdf0e10cSrcweir     /**
1451cdf0e10cSrcweir       Returns a OUString copied without conversion from an ASCII
1452cdf0e10cSrcweir       character string.
1453cdf0e10cSrcweir 
1454cdf0e10cSrcweir       Since this method is optimized for performance, the ASCII character
1455cdf0e10cSrcweir       values are not converted in any way. The caller has to make sure that
1456cdf0e10cSrcweir       all ASCII characters are in the allowed range between 0 and
1457cdf0e10cSrcweir       127. The ASCII string must be NULL-terminated.
1458cdf0e10cSrcweir 
1459cdf0e10cSrcweir       @param    value       the 8-Bit ASCII character string
1460cdf0e10cSrcweir       @return   a string with the string representation of the argument.
1461cdf0e10cSrcweir      */
createFromAscii(const sal_Char * value)1462cdf0e10cSrcweir     static OUString createFromAscii( const sal_Char * value ) SAL_THROW(())
1463cdf0e10cSrcweir     {
1464cdf0e10cSrcweir         rtl_uString* pNew = 0;
1465cdf0e10cSrcweir         rtl_uString_newFromAscii( &pNew, value );
1466cdf0e10cSrcweir         return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1467cdf0e10cSrcweir     }
1468cdf0e10cSrcweir };
1469cdf0e10cSrcweir 
1470cdf0e10cSrcweir /* ======================================================================= */
1471cdf0e10cSrcweir 
1472cdf0e10cSrcweir /** A helper to use OUStrings with hash maps.
1473cdf0e10cSrcweir 
1474cdf0e10cSrcweir     Instances of this class are unary function objects that can be used as
1475cdf0e10cSrcweir     hash function arguments to STLPort's hash_map and similar constructs.
1476cdf0e10cSrcweir  */
1477cdf0e10cSrcweir struct OUStringHash
1478cdf0e10cSrcweir {
1479cdf0e10cSrcweir     /** Compute a hash code for a string.
1480cdf0e10cSrcweir 
1481cdf0e10cSrcweir         @param rString
1482cdf0e10cSrcweir         a string.
1483cdf0e10cSrcweir 
1484cdf0e10cSrcweir         @return
1485cdf0e10cSrcweir         a hash code for the string.  This hash code should not be stored
1486cdf0e10cSrcweir         persistently, as its computation may change in later revisions.
1487cdf0e10cSrcweir      */
operator ()rtl::OUStringHash1488cdf0e10cSrcweir     size_t operator()(const rtl::OUString& rString) const
1489cdf0e10cSrcweir         { return (size_t)rString.hashCode(); }
1490cdf0e10cSrcweir };
1491cdf0e10cSrcweir 
1492cdf0e10cSrcweir /* ======================================================================= */
1493cdf0e10cSrcweir 
1494cdf0e10cSrcweir /** Convert an OString to an OUString, using a specific text encoding.
1495cdf0e10cSrcweir 
1496cdf0e10cSrcweir     The lengths of the two strings may differ (e.g., for double-byte
1497cdf0e10cSrcweir     encodings, UTF-7, UTF-8).
1498cdf0e10cSrcweir 
1499cdf0e10cSrcweir     @param rStr
1500cdf0e10cSrcweir     an OString to convert.
1501cdf0e10cSrcweir 
1502cdf0e10cSrcweir     @param encoding
1503cdf0e10cSrcweir     the text encoding to use for conversion.
1504cdf0e10cSrcweir 
1505cdf0e10cSrcweir     @param convertFlags
1506cdf0e10cSrcweir     flags which control the conversion.  Either use
1507cdf0e10cSrcweir     OSTRING_TO_OUSTRING_CVTFLAGS, or see
1508cdf0e10cSrcweir     <http://udk.openoffice.org/cpp/man/spec/textconversion.html> for more
1509cdf0e10cSrcweir     details.
1510cdf0e10cSrcweir  */
OStringToOUString(const OString & rStr,rtl_TextEncoding encoding,sal_uInt32 convertFlags=OSTRING_TO_OUSTRING_CVTFLAGS)1511cdf0e10cSrcweir inline OUString OStringToOUString( const OString & rStr,
1512cdf0e10cSrcweir                                    rtl_TextEncoding encoding,
1513cdf0e10cSrcweir                                    sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS )
1514cdf0e10cSrcweir {
1515cdf0e10cSrcweir     return OUString( rStr.getStr(), rStr.getLength(), encoding, convertFlags );
1516cdf0e10cSrcweir }
1517cdf0e10cSrcweir 
1518cdf0e10cSrcweir /** Convert an OUString to an OString, using a specific text encoding.
1519cdf0e10cSrcweir 
1520cdf0e10cSrcweir     The lengths of the two strings may differ (e.g., for double-byte
1521cdf0e10cSrcweir     encodings, UTF-7, UTF-8).
1522cdf0e10cSrcweir 
1523cdf0e10cSrcweir     @param rStr
1524cdf0e10cSrcweir     an OUString to convert.
1525cdf0e10cSrcweir 
1526cdf0e10cSrcweir     @param encoding
1527cdf0e10cSrcweir     the text encoding to use for conversion.
1528cdf0e10cSrcweir 
1529cdf0e10cSrcweir     @param convertFlags
1530cdf0e10cSrcweir     flags which control the conversion.  Either use
1531cdf0e10cSrcweir     OUSTRING_TO_OSTRING_CVTFLAGS, or see
1532cdf0e10cSrcweir     <http://udk.openoffice.org/cpp/man/spec/textconversion.html> for more
1533cdf0e10cSrcweir     details.
1534cdf0e10cSrcweir  */
OUStringToOString(const OUString & rUnicode,rtl_TextEncoding encoding,sal_uInt32 convertFlags=OUSTRING_TO_OSTRING_CVTFLAGS)1535cdf0e10cSrcweir inline OString OUStringToOString( const OUString & rUnicode,
1536cdf0e10cSrcweir                                   rtl_TextEncoding encoding,
1537cdf0e10cSrcweir                                   sal_uInt32 convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS )
1538cdf0e10cSrcweir {
1539cdf0e10cSrcweir     return OString( rUnicode.getStr(), rUnicode.getLength(), encoding, convertFlags );
1540cdf0e10cSrcweir }
1541cdf0e10cSrcweir 
1542cdf0e10cSrcweir /* ======================================================================= */
1543cdf0e10cSrcweir 
1544cdf0e10cSrcweir } /* Namespace */
1545cdf0e10cSrcweir 
1546cdf0e10cSrcweir #endif /* __cplusplus */
1547cdf0e10cSrcweir 
1548cdf0e10cSrcweir #endif /* _RTL_USTRING_HXX */
1549