update dev300-m58
[ooovba.git] / sal / inc / rtl / ustring.hxx
blobae3247545384c2cb9c23ee6dfd1159fdc4ec6036
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ustring.hxx,v $
10 * $Revision: 1.32 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _RTL_USTRING_HXX_
32 #define _RTL_USTRING_HXX_
34 #ifdef __cplusplus
36 #ifndef _RTL_DIAGNOSE_H_
37 #include "osl/diagnose.h"
38 #endif
39 #include <rtl/ustring.h>
40 #include <rtl/string.hxx>
41 #include <rtl/memory.h>
43 #if defined EXCEPTIONS_OFF
44 #include <stdlib.h>
45 #else
46 #include <new>
47 #endif
49 namespace rtl
51 /* ======================================================================= */
53 /**
54 This String class provide base functionality for C++ like Unicode
55 character array handling. The advantage of this class is, that it
56 handle all the memory managament for you - and it do it
57 more efficient. If you assign a string to another string, the
58 data of both strings are shared (without any copy operation or
59 memory allocation) as long as you do not change the string. This class
60 stores also the length of the string, so that many operations are
61 faster as the C-str-functions.
63 This class provide only readonly string handling. So you could create
64 a string and you could only query the content from this string.
65 It provide also functionality to change the string, but this results
66 in every case in a new string instance (in the most cases with an
67 memory allocation). You don't have functionality to change the
68 content of the string. If you want change the string content, than
69 you should us the OStringBuffer class, which provide these
70 functionality and avoid to much memory allocation.
72 The design of this class is similar to the string classes in Java
73 and so more people should have fewer understanding problems when they
74 use this class.
77 class OUString
79 public:
80 /** @internal */
81 rtl_uString * pData;
83 private:
84 /** @internal */
85 class DO_NOT_ACQUIRE{};
87 /** @internal */
88 OUString( rtl_uString * value, DO_NOT_ACQUIRE * )
90 pData = value;
93 public:
94 /**
95 New string containing no characters.
97 OUString() SAL_THROW(())
99 pData = 0;
100 rtl_uString_new( &pData );
104 New string from OUString.
106 @param str a OUString.
108 OUString( const OUString & str ) SAL_THROW(())
110 pData = str.pData;
111 rtl_uString_acquire( pData );
115 New string from OUString data.
117 @param str a OUString data.
119 OUString( rtl_uString * str ) SAL_THROW(())
121 pData = str;
122 rtl_uString_acquire( pData );
124 /** New OUString from OUString data without acquiring it. Takeover of ownership.
126 @param str
127 OUString data
128 @param dummy
129 SAL_NO_ACQUIRE to distinguish from other ctors
131 inline OUString( rtl_uString * str, __sal_NoAcquire ) SAL_THROW( () )
132 { pData = str; }
136 New string from a single Unicode character.
138 @param value a Unicode character.
140 explicit OUString( sal_Unicode value ) SAL_THROW(())
141 : pData (0)
143 rtl_uString_newFromStr_WithLength( &pData, &value, 1 );
147 New string from a Unicode character buffer array.
149 @param value a NULL-terminated Unicode character array.
151 OUString( const sal_Unicode * value ) SAL_THROW(())
153 pData = 0;
154 rtl_uString_newFromStr( &pData, value );
158 New string from a Uniocde character buffer array.
160 @param value a Unicode character array.
161 @param length the number of character which should be copied.
162 The character array length must be greater or
163 equal than this value.
165 OUString( const sal_Unicode * value, sal_Int32 length ) SAL_THROW(())
167 pData = 0;
168 rtl_uString_newFromStr_WithLength( &pData, value, length );
172 New string from a 8-Bit character buffer array.
174 @param value a 8-Bit character array.
175 @param length the number of character which should be converted.
176 The 8-Bit character array length must be
177 greater or equal than this value.
178 @param encoding the text encoding from which the 8-Bit character
179 sequence should be converted.
180 @param convertFlags flags which controls the conversion.
181 see RTL_TEXTTOUNICODE_FLAGS_...
183 @exception std::bad_alloc is thrown if an out-of-memory condition occurs
185 OUString( const sal_Char * value, sal_Int32 length,
186 rtl_TextEncoding encoding,
187 sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS )
189 pData = 0;
190 rtl_string2UString( &pData, value, length, encoding, convertFlags );
191 #if defined EXCEPTIONS_OFF
192 OSL_ASSERT(pData != NULL);
193 #else
194 if (pData == 0) {
195 throw std::bad_alloc();
197 #endif
200 /** Create a new string from an array of Unicode code points.
202 @param codePoints
203 an array of at least codePointCount code points, which each must be in
204 the range from 0 to 0x10FFFF, inclusive. May be null if codePointCount
205 is zero.
207 @param codePointCount
208 the non-negative number of code points.
210 @exception std::bad_alloc
211 is thrown if either an out-of-memory condition occurs or the resulting
212 number of UTF-16 code units would have been larger than SAL_MAX_INT32.
214 @since UDK 3.2.7
216 inline explicit OUString(
217 sal_uInt32 const * codePoints, sal_Int32 codePointCount):
218 pData(NULL)
220 rtl_uString_newFromCodePoints(&pData, codePoints, codePointCount);
221 if (pData == NULL) {
222 #if defined EXCEPTIONS_OFF
223 abort();
224 #else
225 throw std::bad_alloc();
226 #endif
231 Release the string data.
233 ~OUString() SAL_THROW(())
235 rtl_uString_release( pData );
238 /** Provides an OUString const & passing a storage pointer of an
239 rtl_uString * handle.
240 It is more convenient to use C++ OUString member functions when dealing
241 with rtl_uString * handles. Using this function avoids unnecessary
242 acquire()/release() calls for a temporary OUString object.
244 @param ppHandle
245 pointer to storage
246 @return
247 OUString const & based on given storage
249 static inline OUString const & unacquired( rtl_uString * const * ppHandle )
250 { return * reinterpret_cast< OUString const * >( ppHandle ); }
253 Assign a new string.
255 @param str a OUString.
257 OUString & operator=( const OUString & str ) SAL_THROW(())
259 rtl_uString_assign( &pData, str.pData );
260 return *this;
264 Append a string to this string.
266 @param str a OUString.
268 OUString & operator+=( const OUString & str ) SAL_THROW(())
270 rtl_uString_newConcat( &pData, pData, str.pData );
271 return *this;
275 Returns the length of this string.
277 The length is equal to the number of Unicode characters in this string.
279 @return the length of the sequence of characters represented by this
280 object.
282 sal_Int32 getLength() const SAL_THROW(()) { return pData->length; }
285 Returns a pointer to the Unicode character buffer from this string.
287 It isn't necessarily NULL terminated.
289 @return a pointer to the Unicode characters buffer from this object.
291 operator const sal_Unicode *() const SAL_THROW(()) { return pData->buffer; }
294 Returns a pointer to the Unicode character buffer from this string.
296 It isn't necessarily NULL terminated.
298 @return a pointer to the Unicode characters buffer from this object.
300 const sal_Unicode * getStr() const SAL_THROW(()) { return pData->buffer; }
303 Compares two strings.
305 The comparison is based on the numeric value of each character in
306 the strings and return a value indicating their relationship.
307 This function can't be used for language specific sorting.
309 @param str the object to be compared.
310 @return 0 - if both strings are equal
311 < 0 - if this string is less than the string argument
312 > 0 - if this string is greater than the string argument
314 sal_Int32 compareTo( const OUString & str ) const SAL_THROW(())
316 return rtl_ustr_compare_WithLength( pData->buffer, pData->length,
317 str.pData->buffer, str.pData->length );
321 Compares two strings with an maximum count of characters.
323 The comparison is based on the numeric value of each character in
324 the strings and return a value indicating their relationship.
325 This function can't be used for language specific sorting.
327 @param str the object to be compared.
328 @param maxLength the maximum count of characters to be compared.
329 @return 0 - if both strings are equal
330 < 0 - if this string is less than the string argument
331 > 0 - if this string is greater than the string argument
333 sal_Int32 compareTo( const OUString & str, sal_Int32 maxLength ) const SAL_THROW(())
335 return rtl_ustr_shortenedCompare_WithLength( pData->buffer, pData->length,
336 str.pData->buffer, str.pData->length, maxLength );
340 Compares two strings in reverse order.
342 The comparison is based on the numeric value of each character in
343 the strings and return a value indicating their relationship.
344 This function can't be used for language specific sorting.
346 @param str the object to be compared.
347 @return 0 - if both strings are equal
348 < 0 - if this string is less than the string argument
349 > 0 - if this string is greater than the string argument
351 sal_Int32 reverseCompareTo( const OUString & str ) const SAL_THROW(())
353 return rtl_ustr_reverseCompare_WithLength( pData->buffer, pData->length,
354 str.pData->buffer, str.pData->length );
358 Perform a comparison of two strings.
360 The result is true if and only if second string
361 represents the same sequence of characters as the first string.
362 This function can't be used for language specific comparison.
364 @param str the object to be compared.
365 @return sal_True if the strings are equal;
366 sal_False, otherwise.
368 sal_Bool equals( const OUString & str ) const SAL_THROW(())
370 if ( pData->length != str.pData->length )
371 return sal_False;
372 if ( pData == str.pData )
373 return sal_True;
374 return rtl_ustr_reverseCompare_WithLength( pData->buffer, pData->length,
375 str.pData->buffer, str.pData->length ) == 0;
379 Perform a ASCII lowercase comparison of two strings.
381 The result is true if and only if second string
382 represents the same sequence of characters as the first string,
383 ignoring the case.
384 Character values between 65 and 90 (ASCII A-Z) are interpreted as
385 values between 97 and 122 (ASCII a-z).
386 This function can't be used for language specific comparison.
388 @param str the object to be compared.
389 @return sal_True if the strings are equal;
390 sal_False, otherwise.
392 sal_Bool equalsIgnoreAsciiCase( const OUString & str ) const SAL_THROW(())
394 if ( pData->length != str.pData->length )
395 return sal_False;
396 if ( pData == str.pData )
397 return sal_True;
398 return rtl_ustr_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
399 str.pData->buffer, str.pData->length ) == 0;
403 Match against a substring appearing in this string.
405 The result is true if and only if the second string appears as a substring
406 of this string, at the given position.
407 This function can't be used for language specific comparison.
409 @param str the object (substring) to be compared.
410 @param fromIndex the index to start the comparion from.
411 The index must be greater or equal than 0
412 and less or equal as the string length.
413 @return sal_True if str match with the characters in the string
414 at the given position;
415 sal_False, otherwise.
417 sal_Bool match( const OUString & str, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
419 return rtl_ustr_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
420 str.pData->buffer, str.pData->length, str.pData->length ) == 0;
424 Match against a substring appearing in this string, ignoring the case of
425 ASCII letters.
427 The result is true if and only if the second string appears as a substring
428 of this string, at the given position.
429 Character values between 65 and 90 (ASCII A-Z) are interpreted as
430 values between 97 and 122 (ASCII a-z).
431 This function can't be used for language specific comparison.
433 @param str the object (substring) to be compared.
434 @param fromIndex the index to start the comparion from.
435 The index must be greater or equal than 0
436 and less or equal as the string length.
437 @return sal_True if str match with the characters in the string
438 at the given position;
439 sal_False, otherwise.
441 sal_Bool matchIgnoreAsciiCase( const OUString & str, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
443 return rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
444 str.pData->buffer, str.pData->length,
445 str.pData->length ) == 0;
449 Compares two strings.
451 The comparison is based on the numeric value of each character in
452 the strings and return a value indicating their relationship.
453 Since this method is optimized for performance, the ASCII character
454 values are not converted in any way. The caller has to make sure that
455 all ASCII characters are in the allowed range between 0 and
456 127. The ASCII string must be NULL-terminated.
457 This function can't be used for language specific sorting.
459 @param asciiStr the 8-Bit ASCII character string to be compared.
460 @return 0 - if both strings are equal
461 < 0 - if this string is less than the string argument
462 > 0 - if this string is greater than the string argument
464 sal_Int32 compareToAscii( const sal_Char* asciiStr ) const SAL_THROW(())
466 return rtl_ustr_ascii_compare_WithLength( pData->buffer, pData->length, asciiStr );
470 Compares two strings with an maximum count of characters.
472 The comparison is based on the numeric value of each character in
473 the strings and return a value indicating their relationship.
474 Since this method is optimized for performance, the ASCII character
475 values are not converted in any way. The caller has to make sure that
476 all ASCII characters are in the allowed range between 0 and
477 127. The ASCII string must be NULL-terminated.
478 This function can't be used for language specific sorting.
480 @param asciiStr the 8-Bit ASCII character string to be compared.
481 @param maxLength the maximum count of characters to be compared.
482 @return 0 - if both strings are equal
483 < 0 - if this string is less than the string argument
484 > 0 - if this string is greater than the string argument
486 sal_Int32 compareToAscii( const sal_Char * asciiStr, sal_Int32 maxLength ) const SAL_THROW(())
488 return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer, pData->length,
489 asciiStr, maxLength );
493 Compares two strings in reverse order.
495 This could be useful, if normally both strings start with the same
496 content. The comparison is based on the numeric value of each character
497 in the strings and return a value indicating their relationship.
498 Since this method is optimized for performance, the ASCII character
499 values are not converted in any way. The caller has to make sure that
500 all ASCII characters are in the allowed range between 0 and
501 127. The ASCII string must be NULL-terminated and must be greater or
502 equal as asciiStrLength.
503 This function can't be used for language specific sorting.
505 @param asciiStr the 8-Bit ASCII character string to be compared.
506 @param asciiStrLength the length of the ascii string
507 @return 0 - if both strings are equal
508 < 0 - if this string is less than the string argument
509 > 0 - if this string is greater than the string argument
511 sal_Int32 reverseCompareToAsciiL( const sal_Char * asciiStr, sal_Int32 asciiStrLength ) const SAL_THROW(())
513 return rtl_ustr_asciil_reverseCompare_WithLength( pData->buffer, pData->length,
514 asciiStr, asciiStrLength );
518 Perform a comparison of two strings.
520 The result is true if and only if second string
521 represents the same sequence of characters as the first string.
522 Since this method is optimized for performance, the ASCII character
523 values are not converted in any way. The caller has to make sure that
524 all ASCII characters are in the allowed range between 0 and
525 127. The ASCII string must be NULL-terminated.
526 This function can't be used for language specific comparison.
528 @param asciiStr the 8-Bit ASCII character string to be compared.
529 @return sal_True if the strings are equal;
530 sal_False, otherwise.
532 sal_Bool equalsAscii( const sal_Char* asciiStr ) const SAL_THROW(())
534 return rtl_ustr_ascii_compare_WithLength( pData->buffer, pData->length,
535 asciiStr ) == 0;
539 Perform a comparison of two strings.
541 The result is true if and only if second string
542 represents the same sequence of characters as the first string.
543 Since this method is optimized for performance, the ASCII character
544 values are not converted in any way. The caller has to make sure that
545 all ASCII characters are in the allowed range between 0 and
546 127. The ASCII string must be NULL-terminated and must be greater or
547 equal as asciiStrLength.
548 This function can't be used for language specific comparison.
550 @param asciiStr the 8-Bit ASCII character string to be compared.
551 @param asciiStrLength the length of the ascii string
552 @return sal_True if the strings are equal;
553 sal_False, otherwise.
555 sal_Bool equalsAsciiL( const sal_Char* asciiStr, sal_Int32 asciiStrLength ) const SAL_THROW(())
557 if ( pData->length != asciiStrLength )
558 return sal_False;
560 return rtl_ustr_asciil_reverseEquals_WithLength(
561 pData->buffer, asciiStr, asciiStrLength );
565 Perform a ASCII lowercase comparison of two strings.
567 The result is true if and only if second string
568 represents the same sequence of characters as the first string,
569 ignoring the case.
570 Character values between 65 and 90 (ASCII A-Z) are interpreted as
571 values between 97 and 122 (ASCII a-z).
572 Since this method is optimized for performance, the ASCII character
573 values are not converted in any way. The caller has to make sure that
574 all ASCII characters are in the allowed range between 0 and
575 127. The ASCII string must be NULL-terminated.
576 This function can't be used for language specific comparison.
578 @param asciiStr the 8-Bit ASCII character string to be compared.
579 @return sal_True if the strings are equal;
580 sal_False, otherwise.
582 sal_Bool equalsIgnoreAsciiCaseAscii( const sal_Char * asciiStr ) const SAL_THROW(())
584 return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr ) == 0;
588 Perform a ASCII lowercase comparison of two strings.
590 The result is true if and only if second string
591 represents the same sequence of characters as the first string,
592 ignoring the case.
593 Character values between 65 and 90 (ASCII A-Z) are interpreted as
594 values between 97 and 122 (ASCII a-z).
595 Since this method is optimized for performance, the ASCII character
596 values are not converted in any way. The caller has to make sure that
597 all ASCII characters are in the allowed range between 0 and
598 127. The ASCII string must be NULL-terminated and must be greater or
599 equal as asciiStrLength.
600 This function can't be used for language specific comparison.
602 @param asciiStr the 8-Bit ASCII character string to be compared.
603 @param asciiStrLength the length of the ascii string
604 @return sal_True if the strings are equal;
605 sal_False, otherwise.
607 sal_Bool equalsIgnoreAsciiCaseAsciiL( const sal_Char * asciiStr, sal_Int32 asciiStrLength ) const SAL_THROW(())
609 if ( pData->length != asciiStrLength )
610 return sal_False;
612 return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr ) == 0;
616 Match against a substring appearing in this string.
618 The result is true if and only if the second string appears as a substring
619 of this string, at the given position.
620 Since this method is optimized for performance, the ASCII character
621 values are not converted in any way. The caller has to make sure that
622 all ASCII characters are in the allowed range between 0 and
623 127. The ASCII string must be NULL-terminated and must be greater or
624 equal as asciiStrLength.
625 This function can't be used for language specific comparison.
627 @param str the object (substring) to be compared.
628 @param fromIndex the index to start the comparion from.
629 The index must be greater or equal than 0
630 and less or equal as the string length.
631 @return sal_True if str match with the characters in the string
632 at the given position;
633 sal_False, otherwise.
635 sal_Bool matchAsciiL( const sal_Char* asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
637 return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
638 asciiStr, asciiStrLength ) == 0;
642 Match against a substring appearing in this string, ignoring the case of
643 ASCII letters.
645 The result is true if and only if the second string appears as a substring
646 of this string, at the given position.
647 Character values between 65 and 90 (ASCII A-Z) are interpreted as
648 values between 97 and 122 (ASCII a-z).
649 Since this method is optimized for performance, the ASCII character
650 values are not converted in any way. The caller has to make sure that
651 all ASCII characters are in the allowed range between 0 and
652 127. The ASCII string must be NULL-terminated and must be greater or
653 equal as asciiStrLength.
654 This function can't be used for language specific comparison.
656 @param asciiStr the 8-Bit ASCII character string to be compared.
657 @param asciiStrLength the length of the ascii string
658 @param fromIndex the index to start the comparion from.
659 The index must be greater or equal than 0
660 and less or equal as the string length.
661 @return sal_True if str match with the characters in the string
662 at the given position;
663 sal_False, otherwise.
665 sal_Bool matchIgnoreAsciiCaseAsciiL( const sal_Char* asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
667 return rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
668 asciiStr, asciiStrLength ) == 0;
672 Check whether this string ends with a given ASCII string.
674 @param asciiStr a sequence of at least asciiStrLength ASCII characters
675 (bytes in the range 0x00--0x7F)
676 @param asciiStrLen the length of asciiStr; must be non-negative
677 @return true if this string ends with asciiStr; otherwise, false is
678 returned
680 @since UDK 3.2.7
682 inline bool endsWithAsciiL(char const * asciiStr, sal_Int32 asciiStrLength)
683 const
685 return asciiStrLength <= pData->length
686 && rtl_ustr_asciil_reverseEquals_WithLength(
687 pData->buffer + pData->length - asciiStrLength, asciiStr,
688 asciiStrLength);
692 Check whether this string ends with a given ASCII string, ignoring the
693 case of ASCII letters.
695 @param asciiStr a sequence of at least asciiStrLength ASCII characters
696 (bytes in the range 0x00--0x7F)
697 @param asciiStrLen the length of asciiStr; must be non-negative
698 @return true if this string ends with asciiStr, ignoring the case of ASCII
699 letters ("A"--"Z" and "a"--"z"); otherwise, false is returned
701 inline bool endsWithIgnoreAsciiCaseAsciiL(
702 char const * asciiStr, sal_Int32 asciiStrLength) const
704 return asciiStrLength <= pData->length
705 && (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
706 pData->buffer + pData->length - asciiStrLength,
707 asciiStrLength, asciiStr, asciiStrLength)
708 == 0);
711 friend sal_Bool operator == ( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
712 { return rStr1.getLength() == rStr2.getLength() && rStr1.compareTo( rStr2 ) == 0; }
713 friend sal_Bool operator == ( const OUString& rStr1, const sal_Unicode * pStr2 ) SAL_THROW(())
714 { return rStr1.compareTo( pStr2 ) == 0; }
715 friend sal_Bool operator == ( const sal_Unicode * pStr1, const OUString& rStr2 ) SAL_THROW(())
716 { return OUString( pStr1 ).compareTo( rStr2 ) == 0; }
718 friend sal_Bool operator != ( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
719 { return !(operator == ( rStr1, rStr2 )); }
720 friend sal_Bool operator != ( const OUString& rStr1, const sal_Unicode * pStr2 ) SAL_THROW(())
721 { return !(operator == ( rStr1, pStr2 )); }
722 friend sal_Bool operator != ( const sal_Unicode * pStr1, const OUString& rStr2 ) SAL_THROW(())
723 { return !(operator == ( pStr1, rStr2 )); }
725 friend sal_Bool operator < ( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
726 { return rStr1.compareTo( rStr2 ) < 0; }
727 friend sal_Bool operator > ( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
728 { return rStr1.compareTo( rStr2 ) > 0; }
729 friend sal_Bool operator <= ( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
730 { return rStr1.compareTo( rStr2 ) <= 0; }
731 friend sal_Bool operator >= ( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
732 { return rStr1.compareTo( rStr2 ) >= 0; }
735 Returns a hashcode for this string.
737 @return a hash code value for this object.
739 @see rtl::OUStringHash for convenient use of STLPort's hash_map
741 sal_Int32 hashCode() const SAL_THROW(())
743 return rtl_ustr_hashCode_WithLength( pData->buffer, pData->length );
747 Returns the index within this string of the first occurrence of the
748 specified character, starting the search at the specified index.
750 @param ch character to be located.
751 @param fromIndex the index to start the search from.
752 The index must be greater or equal than 0
753 and less or equal as the string length.
754 @return the index of the first occurrence of the character in the
755 character sequence represented by this string that is
756 greater than or equal to fromIndex, or
757 -1 if the character does not occur.
759 sal_Int32 indexOf( sal_Unicode ch, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
761 sal_Int32 ret = rtl_ustr_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
762 return (ret < 0 ? ret : ret+fromIndex);
766 Returns the index within this string of the last occurrence of the
767 specified character, searching backward starting at the end.
769 @param ch character to be located.
770 @return the index of the last occurrence of the character in the
771 character sequence represented by this string, or
772 -1 if the character does not occur.
774 sal_Int32 lastIndexOf( sal_Unicode ch ) const SAL_THROW(())
776 return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
780 Returns the index within this string of the last occurrence of the
781 specified character, searching backward starting before the specified
782 index.
784 @param ch character to be located.
785 @param fromIndex the index before which to start the search.
786 @return the index of the last occurrence of the character in the
787 character sequence represented by this string that
788 is less than fromIndex, or -1
789 if the character does not occur before that point.
791 sal_Int32 lastIndexOf( sal_Unicode ch, sal_Int32 fromIndex ) const SAL_THROW(())
793 return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
797 Returns the index within this string of the first occurrence of the
798 specified substring, starting at the specified index.
800 If str doesn't include any character, always -1 is
801 returned. This is also the case, if both strings are empty.
803 @param str the substring to search for.
804 @param fromIndex the index to start the search from.
805 @return If the string argument occurs one or more times as a substring
806 within this string at the starting index, then the index
807 of the first character of the first such substring is
808 returned. If it does not occur as a substring starting
809 at fromIndex or beyond, -1 is returned.
811 sal_Int32 indexOf( const OUString & str, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
813 sal_Int32 ret = rtl_ustr_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
814 str.pData->buffer, str.pData->length );
815 return (ret < 0 ? ret : ret+fromIndex);
819 Returns the index within this string of the first occurrence of the
820 specified ASCII substring, starting at the specified index.
822 @param str
823 the substring to be searched for. Need not be null-terminated, but must
824 be at least as long as the specified len. Must only contain characters
825 in the ASCII range 0x00--7F.
827 @param len
828 the length of the substring; must be non-negative.
830 @param fromIndex
831 the index to start the search from. Must be in the range from zero to
832 the length of this string, inclusive.
834 @return
835 the index (starting at 0) of the first character of the first occurrence
836 of the substring within this string starting at the given fromIndex, or
837 -1 if the substring does not occur. If len is zero, -1 is returned.
839 @since UDK 3.2.7
841 sal_Int32 indexOfAsciiL(
842 char const * str, sal_Int32 len, sal_Int32 fromIndex = 0) const
843 SAL_THROW(())
845 sal_Int32 ret = rtl_ustr_indexOfAscii_WithLength(
846 pData->buffer + fromIndex, pData->length - fromIndex, str, len);
847 return ret < 0 ? ret : ret + fromIndex;
851 Returns the index within this string of the last occurrence of
852 the specified substring, searching backward starting at the end.
854 The returned index indicates the starting index of the substring
855 in this string.
856 If str doesn't include any character, always -1 is
857 returned. This is also the case, if both strings are empty.
859 @param str the substring to search for.
860 @return If the string argument occurs one or more times as a substring
861 within this string, then the index of the first character of
862 the last such substring is returned. If it does not occur as
863 a substring, -1 is returned.
865 sal_Int32 lastIndexOf( const OUString & str ) const SAL_THROW(())
867 return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, pData->length,
868 str.pData->buffer, str.pData->length );
872 Returns the index within this string of the last occurrence of
873 the specified substring, searching backward starting before the specified
874 index.
876 The returned index indicates the starting index of the substring
877 in this string.
878 If str doesn't include any character, always -1 is
879 returned. This is also the case, if both strings are empty.
881 @param str the substring to search for.
882 @param fromIndex the index before which to start the search.
883 @return If the string argument occurs one or more times as a substring
884 within this string before the starting index, then the index
885 of the first character of the last such substring is
886 returned. Otherwise, -1 is returned.
888 sal_Int32 lastIndexOf( const OUString & str, sal_Int32 fromIndex ) const SAL_THROW(())
890 return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
891 str.pData->buffer, str.pData->length );
895 Returns the index within this string of the last occurrence of the
896 specified ASCII substring.
898 @param str
899 the substring to be searched for. Need not be null-terminated, but must
900 be at least as long as the specified len. Must only contain characters
901 in the ASCII range 0x00--7F.
903 @param len
904 the length of the substring; must be non-negative.
906 @return
907 the index (starting at 0) of the first character of the last occurrence
908 of the substring within this string, or -1 if the substring does not
909 occur. If len is zero, -1 is returned.
911 @since UDK 3.2.7
913 sal_Int32 lastIndexOfAsciiL(char const * str, sal_Int32 len) const
914 SAL_THROW(())
916 return rtl_ustr_lastIndexOfAscii_WithLength(
917 pData->buffer, pData->length, str, len);
921 Returns a new string that is a substring of this string.
923 The substring begins at the specified beginIndex. It is an error for
924 beginIndex to be negative or to be greater than the length of this string.
926 @param beginIndex the beginning index, inclusive.
927 @return the specified substring.
929 OUString copy( sal_Int32 beginIndex ) const SAL_THROW(())
931 OSL_ASSERT(beginIndex >= 0 && beginIndex <= getLength());
932 if ( beginIndex == 0 )
933 return *this;
934 else
936 rtl_uString* pNew = 0;
937 rtl_uString_newFromStr_WithLength( &pNew, pData->buffer+beginIndex, getLength()-beginIndex );
938 return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
943 Returns a new string that is a substring of this string.
945 The substring begins at the specified beginIndex and contains count
946 characters. It is an error for either beginIndex or count to be negative,
947 or for beginIndex + count to be greater than the length of this string.
949 @param beginIndex the beginning index, inclusive.
950 @param count the number of characters.
951 @return the specified substring.
953 OUString copy( sal_Int32 beginIndex, sal_Int32 count ) const SAL_THROW(())
955 OSL_ASSERT(beginIndex >= 0 && beginIndex <= getLength()
956 && count >= 0 && count <= getLength() - beginIndex);
957 if ( (beginIndex == 0) && (count == getLength()) )
958 return *this;
959 else
961 rtl_uString* pNew = 0;
962 rtl_uString_newFromStr_WithLength( &pNew, pData->buffer+beginIndex, count );
963 return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
968 Concatenates the specified string to the end of this string.
970 @param str the string that is concatenated to the end
971 of this string.
972 @return a string that represents the concatenation of this string
973 followed by the string argument.
975 OUString concat( const OUString & str ) const SAL_THROW(())
977 rtl_uString* pNew = 0;
978 rtl_uString_newConcat( &pNew, pData, str.pData );
979 return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
982 friend OUString operator+( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
984 return rStr1.concat( rStr2 );
988 Returns a new string resulting from replacing n = count characters
989 from position index in this string with newStr.
991 @param index the replacing index in str.
992 The index must be greater or equal as 0 and
993 less or equal as the length of the string.
994 @param count the count of charcters that will replaced
995 The count must be greater or equal as 0 and
996 less or equal as the length of the string minus index.
997 @param newStr the new substring.
998 @return the new string.
1000 OUString replaceAt( sal_Int32 index, sal_Int32 count, const OUString& newStr ) const SAL_THROW(())
1002 rtl_uString* pNew = 0;
1003 rtl_uString_newReplaceStrAt( &pNew, pData, index, count, newStr.pData );
1004 return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1008 Returns a new string resulting from replacing all occurrences of
1009 oldChar in this string with newChar.
1011 If the character oldChar does not occur in the character sequence
1012 represented by this object, then the string is assigned with
1013 str.
1015 @param oldChar the old character.
1016 @param newChar the new character.
1017 @return a string derived from this string by replacing every
1018 occurrence of oldChar with newChar.
1020 OUString replace( sal_Unicode oldChar, sal_Unicode newChar ) const SAL_THROW(())
1022 rtl_uString* pNew = 0;
1023 rtl_uString_newReplace( &pNew, pData, oldChar, newChar );
1024 return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1028 Converts from this string all ASCII uppercase characters (65-90)
1029 to ASCII lowercase characters (97-122).
1031 This function can't be used for language specific conversion.
1032 If the string doesn't contain characters which must be converted,
1033 then the new string is assigned with str.
1035 @return the string, converted to ASCII lowercase.
1037 OUString toAsciiLowerCase() const SAL_THROW(())
1039 rtl_uString* pNew = 0;
1040 rtl_uString_newToAsciiLowerCase( &pNew, pData );
1041 return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1045 Converts from this string all ASCII lowercase characters (97-122)
1046 to ASCII uppercase characters (65-90).
1048 This function can't be used for language specific conversion.
1049 If the string doesn't contain characters which must be converted,
1050 then the new string is assigned with str.
1052 @return the string, converted to ASCII uppercase.
1054 OUString toAsciiUpperCase() const SAL_THROW(())
1056 rtl_uString* pNew = 0;
1057 rtl_uString_newToAsciiUpperCase( &pNew, pData );
1058 return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1062 Returns a new string resulting from removing white space from both ends
1063 of the string.
1065 All characters that have codes less than or equal to
1066 32 (the space character) are considered to be white space.
1067 If the string doesn't contain white spaces at both ends,
1068 then the new string is assigned with str.
1070 @return the string, with white space removed from the front and end.
1072 OUString trim() const SAL_THROW(())
1074 rtl_uString* pNew = 0;
1075 rtl_uString_newTrim( &pNew, pData );
1076 return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1080 Returns a token in the string.
1082 Example:
1083 sal_Int32 nIndex = 0;
1087 OUString aToken = aStr.getToken( 0, ';', nIndex );
1090 while ( nIndex >= 0 );
1092 @param token the number of the token to return
1093 @param cTok the character which seperate the tokens.
1094 @param index the position at which the token is searched in the
1095 string.
1096 The index must not be greater than the length of the
1097 string.
1098 This param is set to the position of the
1099 next token or to -1, if it is the last token.
1100 @return the token; if either token or index is negative, an empty token
1101 is returned (and index is set to -1)
1103 OUString getToken( sal_Int32 token, sal_Unicode cTok, sal_Int32& index ) const SAL_THROW(())
1105 rtl_uString * pNew = 0;
1106 index = rtl_uString_getToken( &pNew, pData, token, cTok, index );
1107 return OUString( pNew, (DO_NOT_ACQUIRE *)0 );
1111 Returns the Boolean value from this string.
1113 This function can't be used for language specific conversion.
1115 @return sal_True, if the string is 1 or "True" in any ASCII case.
1116 sal_False in any other case.
1118 sal_Bool toBoolean() const SAL_THROW(())
1120 return rtl_ustr_toBoolean( pData->buffer );
1124 Returns the first character from this string.
1126 @return the first character from this string or 0, if this string
1127 is emptry.
1129 sal_Unicode toChar() const SAL_THROW(())
1131 return pData->buffer[0];
1135 Returns the int32 value from this string.
1137 This function can't be used for language specific conversion.
1139 @param radix the radix (between 2 and 36)
1140 @return the int32 represented from this string.
1141 0 if this string represents no number.
1143 sal_Int32 toInt32( sal_Int16 radix = 10 ) const SAL_THROW(())
1145 return rtl_ustr_toInt32( pData->buffer, radix );
1149 Returns the int64 value from this string.
1151 This function can't be used for language specific conversion.
1153 @param radix the radix (between 2 and 36)
1154 @return the int64 represented from this string.
1155 0 if this string represents no number.
1157 sal_Int64 toInt64( sal_Int16 radix = 10 ) const SAL_THROW(())
1159 return rtl_ustr_toInt64( pData->buffer, radix );
1163 Returns the float value from this string.
1165 This function can't be used for language specific conversion.
1167 @return the float represented from this string.
1168 0.0 if this string represents no number.
1170 float toFloat() const SAL_THROW(())
1172 return rtl_ustr_toFloat( pData->buffer );
1176 Returns the double value from this string.
1178 This function can't be used for language specific conversion.
1180 @return the double represented from this string.
1181 0.0 if this string represents no number.
1183 double toDouble() const SAL_THROW(())
1185 return rtl_ustr_toDouble( pData->buffer );
1190 Return a canonical representation for a string.
1192 A pool of strings, initially empty is maintained privately
1193 by the string class. On invocation, if present in the pool
1194 the original string will be returned. Otherwise this string,
1195 or a copy thereof will be added to the pool and returned.
1197 @return
1198 a version of the string from the pool.
1200 @exception std::bad_alloc is thrown if an out-of-memory condition occurs
1202 @since UDK 3.2.7
1204 OUString intern() const
1206 rtl_uString * pNew = 0;
1207 rtl_uString_intern( &pNew, pData );
1208 #if defined EXCEPTIONS_OFF
1209 OSL_ASSERT(pNew != NULL);
1210 #else
1211 if (pNew == 0) {
1212 throw std::bad_alloc();
1214 #endif
1215 return OUString( pNew, (DO_NOT_ACQUIRE *)0 );
1219 Return a canonical representation for a converted string.
1221 A pool of strings, initially empty is maintained privately
1222 by the string class. On invocation, if present in the pool
1223 the original string will be returned. Otherwise this string,
1224 or a copy thereof will be added to the pool and returned.
1226 @param value a 8-Bit character array.
1227 @param length the number of character which should be converted.
1228 The 8-Bit character array length must be
1229 greater or equal than this value.
1230 @param encoding the text encoding from which the 8-Bit character
1231 sequence should be converted.
1232 @param convertFlags flags which controls the conversion.
1233 see RTL_TEXTTOUNICODE_FLAGS_...
1234 @param pInfo pointer to return conversion status or NULL.
1236 @return
1237 a version of the converted string from the pool.
1239 @exception std::bad_alloc is thrown if an out-of-memory condition occurs
1241 @since UDK 3.2.7
1243 static OUString intern( const sal_Char * value, sal_Int32 length,
1244 rtl_TextEncoding encoding,
1245 sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS,
1246 sal_uInt32 *pInfo = NULL )
1248 rtl_uString * pNew = 0;
1249 rtl_uString_internConvert( &pNew, value, length, encoding,
1250 convertFlags, pInfo );
1251 #if defined EXCEPTIONS_OFF
1252 OSL_ASSERT(pNew != NULL);
1253 #else
1254 if (pNew == 0) {
1255 throw std::bad_alloc();
1257 #endif
1258 return OUString( pNew, (DO_NOT_ACQUIRE *)0 );
1262 Converts to an OString, signalling failure.
1264 @param pTarget
1265 An out parameter receiving the converted OString. Must not be null; the
1266 contents are not modified if conversion fails (convertToOString returns
1267 false).
1269 @param nEncoding
1270 The text encoding to convert into. Must be an octet encoding (i.e.,
1271 rtl_isOctetTextEncoding(nEncoding) must return true).
1273 @param nFlags
1274 A combination of RTL_UNICODETOTEXT_FLAGS that detail how to do the
1275 conversion (see rtl_convertUnicodeToText). RTL_UNICODETOTEXT_FLAGS_FLUSH
1276 need not be included, it is implicitly assumed. Typical uses are either
1277 RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
1278 RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR (fail if a Unicode character cannot
1279 be converted to the target nEncoding) or OUSTRING_TO_OSTRING_CVTFLAGS
1280 (make a best efforts conversion).
1282 @return
1283 True if the conversion succeeded, false otherwise.
1285 inline bool convertToString(OString * pTarget, rtl_TextEncoding nEncoding,
1286 sal_uInt32 nFlags) const
1288 return rtl_convertUStringToString(&pTarget->pData, pData->buffer,
1289 pData->length, nEncoding, nFlags);
1292 /** Iterate through this string based on code points instead of UTF-16 code
1293 units.
1295 See Chapter 3 of The Unicode Standard 5.0 (Addison--Wesley, 2006) for
1296 definitions of the various terms used in this description.
1298 This string is interpreted as a sequence of zero or more UTF-16 code
1299 units. For each index into this sequence (from zero to one less than
1300 the length of the sequence, inclusive), a code point represented
1301 starting at the given index is computed as follows:
1303 - If the UTF-16 code unit addressed by the index constitutes a
1304 well-formed UTF-16 code unit sequence, the computed code point is the
1305 scalar value encoded by that UTF-16 code unit sequence.
1307 - Otherwise, if the index is at least two UTF-16 code units away from
1308 the end of the sequence, and the sequence of two UTF-16 code units
1309 addressed by the index constitutes a well-formed UTF-16 code unit
1310 sequence, the computed code point is the scalar value encoded by that
1311 UTF-16 code unit sequence.
1313 - Otherwise, the computed code point is the UTF-16 code unit addressed
1314 by the index. (This last case catches unmatched surrogates as well as
1315 indices pointing into the middle of surrogate pairs.)
1317 @param indexUtf16
1318 pointer to a UTF-16 based index into this string; must not be null. On
1319 entry, the index must be in the range from zero to the length of this
1320 string (in UTF-16 code units), inclusive. Upon successful return, the
1321 index will be updated to address the UTF-16 code unit that is the given
1322 incrementCodePoints away from the initial index.
1324 @param incrementCodePoints
1325 the number of code points to move the given *indexUtf16. If
1326 non-negative, moving is done after determining the code point at the
1327 index. If negative, moving is done before determining the code point
1328 at the (then updated) index. The value must be such that the resulting
1329 UTF-16 based index is in the range from zero to the length of this
1330 string (in UTF-16 code units), inclusive.
1332 @return
1333 the code point (an integer in the range from 0 to 0x10FFFF, inclusive)
1334 that is represented within this string starting at the index computed as
1335 follows: If incrementCodePoints is non-negative, the index is the
1336 initial value of *indexUtf16; if incrementCodePoints is negative, the
1337 index is the updated value of *indexUtf16. In either case, the computed
1338 index must be in the range from zero to one less than the length of this
1339 string (in UTF-16 code units), inclusive.
1341 @since UDK 3.2.7
1343 inline sal_uInt32 iterateCodePoints(
1344 sal_Int32 * indexUtf16, sal_Int32 incrementCodePoints = 1) const
1346 return rtl_uString_iterateCodePoints(
1347 pData, indexUtf16, incrementCodePoints);
1351 Returns the string representation of the sal_Bool argument.
1353 If the sal_Bool is true, the string "true" is returned.
1354 If the sal_Bool is false, the string "false" is returned.
1355 This function can't be used for language specific conversion.
1357 @param b a sal_Bool.
1358 @return a string with the string representation of the argument.
1360 static OUString valueOf( sal_Bool b ) SAL_THROW(())
1362 sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFBOOLEAN];
1363 rtl_uString* pNewData = 0;
1364 rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfBoolean( aBuf, b ) );
1365 return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
1369 Returns the string representation of the char argument.
1371 @param c a character.
1372 @return a string with the string representation of the argument.
1374 static OUString valueOf( sal_Unicode c ) SAL_THROW(())
1376 return OUString( &c, 1 );
1380 Returns the string representation of the int argument.
1382 This function can't be used for language specific conversion.
1384 @param i a int32.
1385 @param radix the radix (between 2 and 36)
1386 @return a string with the string representation of the argument.
1388 static OUString valueOf( sal_Int32 i, sal_Int16 radix = 10 ) SAL_THROW(())
1390 sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFINT32];
1391 rtl_uString* pNewData = 0;
1392 rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfInt32( aBuf, i, radix ) );
1393 return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
1397 Returns the string representation of the long argument.
1399 This function can't be used for language specific conversion.
1401 @param ll a int64.
1402 @param radix the radix (between 2 and 36)
1403 @return a string with the string representation of the argument.
1405 static OUString valueOf( sal_Int64 ll, sal_Int16 radix = 10 ) SAL_THROW(())
1407 sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFINT64];
1408 rtl_uString* pNewData = 0;
1409 rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfInt64( aBuf, ll, radix ) );
1410 return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
1414 Returns the string representation of the float argument.
1416 This function can't be used for language specific conversion.
1418 @param f a float.
1419 @return a string with the string representation of the argument.
1421 static OUString valueOf( float f ) SAL_THROW(())
1423 sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFFLOAT];
1424 rtl_uString* pNewData = 0;
1425 rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfFloat( aBuf, f ) );
1426 return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
1430 Returns the string representation of the double argument.
1432 This function can't be used for language specific conversion.
1434 @param d a double.
1435 @return a string with the string representation of the argument.
1437 static OUString valueOf( double d ) SAL_THROW(())
1439 sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFDOUBLE];
1440 rtl_uString* pNewData = 0;
1441 rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfDouble( aBuf, d ) );
1442 return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
1446 Returns a OUString copied without conversion from an ASCII
1447 character string.
1449 Since this method is optimized for performance, the ASCII character
1450 values are not converted in any way. The caller has to make sure that
1451 all ASCII characters are in the allowed range between 0 and
1452 127. The ASCII string must be NULL-terminated.
1454 @param value the 8-Bit ASCII character string
1455 @return a string with the string representation of the argument.
1457 static OUString createFromAscii( const sal_Char * value ) SAL_THROW(())
1459 rtl_uString* pNew = 0;
1460 rtl_uString_newFromAscii( &pNew, value );
1461 return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1465 /* ======================================================================= */
1467 /** A helper to use OUStrings with hash maps.
1469 Instances of this class are unary function objects that can be used as
1470 hash function arguments to STLPort's hash_map and similar constructs.
1472 struct OUStringHash
1474 /** Compute a hash code for a string.
1476 @param rString
1477 a string.
1479 @return
1480 a hash code for the string. This hash code should not be stored
1481 persistently, as its computation may change in later revisions.
1483 size_t operator()(const rtl::OUString& rString) const
1484 { return (size_t)rString.hashCode(); }
1487 /* ======================================================================= */
1489 /** Convert an OString to an OUString, using a specific text encoding.
1491 The lengths of the two strings may differ (e.g., for double-byte
1492 encodings, UTF-7, UTF-8).
1494 @param rStr
1495 an OString to convert.
1497 @param encoding
1498 the text encoding to use for conversion.
1500 @param convertFlags
1501 flags which control the conversion. Either use
1502 OSTRING_TO_OUSTRING_CVTFLAGS, or see
1503 <http://udk.openoffice.org/cpp/man/spec/textconversion.html> for more
1504 details.
1506 inline OUString OStringToOUString( const OString & rStr,
1507 rtl_TextEncoding encoding,
1508 sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS )
1510 return OUString( rStr.getStr(), rStr.getLength(), encoding, convertFlags );
1513 /** Convert an OUString to an OString, using a specific text encoding.
1515 The lengths of the two strings may differ (e.g., for double-byte
1516 encodings, UTF-7, UTF-8).
1518 @param rStr
1519 an OUString to convert.
1521 @param encoding
1522 the text encoding to use for conversion.
1524 @param convertFlags
1525 flags which control the conversion. Either use
1526 OUSTRING_TO_OSTRING_CVTFLAGS, or see
1527 <http://udk.openoffice.org/cpp/man/spec/textconversion.html> for more
1528 details.
1530 inline OString OUStringToOString( const OUString & rUnicode,
1531 rtl_TextEncoding encoding,
1532 sal_uInt32 convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS )
1534 return OString( rUnicode.getStr(), rUnicode.getLength(), encoding, convertFlags );
1537 /* ======================================================================= */
1539 } /* Namespace */
1541 #endif /* __cplusplus */
1543 #endif /* _RTL_USTRING_HXX */