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