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