LCOV - code coverage report
Current view: top level - include/rtl - ustring.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 399 418 95.5 %
Date: 2014-11-03 Functions: 899 1744 51.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_RTL_USTRING_HXX
      21             : #define INCLUDED_RTL_USTRING_HXX
      22             : 
      23             : #include <sal/config.h>
      24             : 
      25             : #include <cassert>
      26             : #include <new>
      27             : #include <ostream>
      28             : #include <string.h>
      29             : 
      30             : #include <osl/diagnose.h>
      31             : #include <rtl/ustring.h>
      32             : #include <rtl/string.hxx>
      33             : #include <rtl/stringutils.hxx>
      34             : #include <rtl/textenc.h>
      35             : #include <sal/log.hxx>
      36             : 
      37             : #ifdef RTL_FAST_STRING
      38             : #include <rtl/stringconcat.hxx>
      39             : #endif
      40             : 
      41             : // The unittest uses slightly different code to help check that the proper
      42             : // calls are made. The class is put into a different namespace to make
      43             : // sure the compiler generates a different (if generating also non-inline)
      44             : // copy of the function and does not merge them together. The class
      45             : // is "brought" into the proper rtl namespace by a typedef below.
      46             : #ifdef RTL_STRING_UNITTEST
      47             : #define rtl rtlunittest
      48             : #endif
      49             : 
      50             : namespace rtl
      51             : {
      52             : 
      53             : #ifdef RTL_STRING_UNITTEST
      54             : #undef rtl
      55             : #endif
      56             : 
      57             : /* ======================================================================= */
      58             : 
      59             : /**
      60             :   This String class provides base functionality for C++ like Unicode
      61             :   character array handling. The advantage of this class is that it
      62             :   handles all the memory management for you - and it does it
      63             :   more efficiently. If you assign a string to another string, the
      64             :   data of both strings are shared (without any copy operation or
      65             :   memory allocation) as long as you do not change the string. This class
      66             :   also stores the length of the string, so that many operations are
      67             :   faster than the C-str-functions.
      68             : 
      69             :   This class provides only readonly string handling. So you could create
      70             :   a string and you could only query the content from this string.
      71             :   It provides also functionality to change the string, but this results
      72             :   in every case in a new string instance (in the most cases with a
      73             :   memory allocation). You don't have functionality to change the
      74             :   content of the string. If you want to change the string content, then
      75             :   you should use the OStringBuffer class, which provides these
      76             :   functionalities and avoids too much memory allocation.
      77             : 
      78             :   The design of this class is similar to the string classes in Java so
      79             :   less people should have understanding problems when they use this class.
      80             : */
      81             : 
      82             : class SAL_WARN_UNUSED OUString
      83             : {
      84             : public:
      85             :     /// @cond INTERNAL
      86             :     rtl_uString * pData;
      87             :     /// @endcond
      88             : 
      89             :     /**
      90             :       New string containing no characters.
      91             :     */
      92   443205915 :     OUString()
      93             :     {
      94   443205915 :         pData = 0;
      95   443205915 :         rtl_uString_new( &pData );
      96   443205908 :     }
      97             : 
      98             :     /**
      99             :       New string from OUString.
     100             : 
     101             :       @param    str         a OUString.
     102             :     */
     103  1016961597 :     OUString( const OUString & str )
     104             :     {
     105  1016961597 :         pData = str.pData;
     106  1016961597 :         rtl_uString_acquire( pData );
     107  1016962042 :     }
     108             : 
     109             :     /**
     110             :       New string from OUString data.
     111             : 
     112             :       @param    str         a OUString data.
     113             :     */
     114     9542832 :     OUString( rtl_uString * str )
     115             :     {
     116     9542832 :         pData = str;
     117     9542832 :         rtl_uString_acquire( pData );
     118     9542832 :     }
     119             : 
     120             :     /** New OUString from OUString data without acquiring it.  Takeover of ownership.
     121             : 
     122             :         The SAL_NO_ACQUIRE dummy parameter is only there to distinguish this
     123             :         from other constructors.
     124             : 
     125             :         @param str
     126             :                OUString data
     127             :     */
     128   101546641 :     inline OUString( rtl_uString * str, __sal_NoAcquire )
     129   101546641 :         { pData = str; }
     130             : 
     131             :     /**
     132             :       New string from a single Unicode character.
     133             : 
     134             :       @param    value       a Unicode character.
     135             :     */
     136     6126730 :     explicit OUString( sal_Unicode value )
     137     6126730 :         : pData (0)
     138             :     {
     139     6126730 :         rtl_uString_newFromStr_WithLength( &pData, &value, 1 );
     140     6126730 :     }
     141             : 
     142             :     /**
     143             :       New string from a Unicode character buffer array.
     144             : 
     145             :       @param    value       a NULL-terminated Unicode character array.
     146             :     */
     147    19486617 :     OUString( const sal_Unicode * value )
     148             :     {
     149    19486617 :         pData = 0;
     150    19486617 :         rtl_uString_newFromStr( &pData, value );
     151    19486617 :     }
     152             : 
     153             :     /**
     154             :       New string from a Unicode character buffer array.
     155             : 
     156             :       @param    value       a Unicode character array.
     157             :       @param    length      the number of character which should be copied.
     158             :                             The character array length must be greater than
     159             :                             or equal to this value.
     160             :     */
     161    11697153 :     OUString( const sal_Unicode * value, sal_Int32 length )
     162             :     {
     163    11697153 :         pData = 0;
     164    11697153 :         rtl_uString_newFromStr_WithLength( &pData, value, length );
     165    11697153 :     }
     166             : 
     167             :     /**
     168             :       New string from an 8-Bit string literal that is expected to contain only
     169             :       characters in the ASCII set (i.e. first 128 characters). This constructor
     170             :       allows an efficient and convenient way to create OUString
     171             :       instances from ASCII literals. When creating strings from data that
     172             :       is not pure ASCII, it needs to be converted to OUString by explicitly
     173             :       providing the encoding to use for the conversion.
     174             : 
     175             :       If there are any embedded \0's in the string literal, the result is undefined.
     176             :       Use the overload that explicitly accepts length.
     177             : 
     178             :       @param    literal         the 8-bit ASCII string literal
     179             : 
     180             :       @since LibreOffice 3.6
     181             :     */
     182             :     template< typename T >
     183    50065706 :     OUString( T& literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type = libreoffice_internal::Dummy() )
     184             :     {
     185             :         assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
     186    50065706 :         pData = 0;
     187             :         if( libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 == 0 ) // empty string
     188     5898737 :             rtl_uString_new( &pData );
     189             :         else
     190    44166969 :             rtl_uString_newFromLiteral( &pData, literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1, 0 );
     191             : #ifdef RTL_STRING_UNITTEST
     192          64 :         rtl_string_unittest_const_literal = true;
     193             : #endif
     194    50065703 :     }
     195             : 
     196             : #ifdef RTL_STRING_UNITTEST
     197             :     /**
     198             :      * Only used by unittests to detect incorrect conversions.
     199             :      * @internal
     200             :      */
     201             :     template< typename T >
     202          36 :     OUString( T&, typename libreoffice_internal::ExceptConstCharArrayDetector< T >::Type = libreoffice_internal::Dummy() )
     203             :     {
     204          36 :         pData = 0;
     205          36 :         rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
     206          36 :         rtl_string_unittest_invalid_conversion = true;
     207          36 :     }
     208             :     /**
     209             :      * Only used by unittests to detect incorrect conversions.
     210             :      * @internal
     211             :      */
     212             :     template< typename T >
     213           4 :     OUString( const T&, typename libreoffice_internal::ExceptCharArrayDetector< T >::Type = libreoffice_internal::Dummy() )
     214             :     {
     215           4 :         pData = 0;
     216           4 :         rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
     217           4 :         rtl_string_unittest_invalid_conversion = true;
     218           4 :     }
     219             : #endif
     220             : 
     221             :     /**
     222             :       New string from an 8-Bit character buffer array.
     223             : 
     224             :       @param    value           An 8-Bit character array.
     225             :       @param    length          The number of character which should be converted.
     226             :                                 The 8-Bit character array length must be
     227             :                                 greater than or equal to this value.
     228             :       @param    encoding        The text encoding from which the 8-Bit character
     229             :                                 sequence should be converted.
     230             :       @param    convertFlags    Flags which control the conversion.
     231             :                                 see RTL_TEXTTOUNICODE_FLAGS_...
     232             : 
     233             :       @exception std::bad_alloc is thrown if an out-of-memory condition occurs
     234             :     */
     235    25207010 :     OUString( const sal_Char * value, sal_Int32 length,
     236             :               rtl_TextEncoding encoding,
     237             :               sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS )
     238             :     {
     239    25207010 :         pData = 0;
     240    25207010 :         rtl_string2UString( &pData, value, length, encoding, convertFlags );
     241    25207010 :         if (pData == 0) {
     242           0 :             throw std::bad_alloc();
     243             :         }
     244    25207010 :     }
     245             : 
     246             :     /** Create a new string from an array of Unicode code points.
     247             : 
     248             :         @param codePoints
     249             :         an array of at least codePointCount code points, which each must be in
     250             :         the range from 0 to 0x10FFFF, inclusive.  May be null if codePointCount
     251             :         is zero.
     252             : 
     253             :         @param codePointCount
     254             :         the non-negative number of code points.
     255             : 
     256             :         @exception std::bad_alloc
     257             :         is thrown if either an out-of-memory condition occurs or the resulting
     258             :         number of UTF-16 code units would have been larger than SAL_MAX_INT32.
     259             : 
     260             :         @since UDK 3.2.7
     261             :     */
     262       13787 :     inline explicit OUString(
     263             :         sal_uInt32 const * codePoints, sal_Int32 codePointCount):
     264       13787 :         pData(NULL)
     265             :     {
     266       13787 :         rtl_uString_newFromCodePoints(&pData, codePoints, codePointCount);
     267       13787 :         if (pData == NULL) {
     268           0 :             throw std::bad_alloc();
     269             :         }
     270       13787 :     }
     271             : 
     272             : #ifdef RTL_FAST_STRING
     273             :     /**
     274             :      @overload
     275             :      @internal
     276             :     */
     277             :     template< typename T1, typename T2 >
     278     8830933 :     OUString( const OUStringConcat< T1, T2 >& c )
     279             :     {
     280     8830933 :         const sal_Int32 l = c.length();
     281     8830933 :         pData = rtl_uString_alloc( l );
     282     8830933 :         if (l != 0)
     283             :         {
     284     8830495 :             sal_Unicode* end = c.addData( pData->buffer );
     285     8830495 :             pData->length = end - pData->buffer;
     286     8830495 :             *end = '\0';
     287             :             // TODO realloc in case pData->length is noticeably smaller than l?
     288             :         }
     289     8830933 :     }
     290             : #endif
     291             : 
     292             :     /**
     293             :       Release the string data.
     294             :     */
     295  1691534831 :     ~OUString()
     296             :     {
     297  1691534831 :         rtl_uString_release( pData );
     298  1691534947 :     }
     299             : 
     300             :     /** Provides an OUString const & passing a storage pointer of an
     301             :         rtl_uString * handle.
     302             :         It is more convenient to use C++ OUString member functions when dealing
     303             :         with rtl_uString * handles.  Using this function avoids unnecessary
     304             :         acquire()/release() calls for a temporary OUString object.
     305             : 
     306             :         @param ppHandle
     307             :                pointer to storage
     308             :         @return
     309             :                OUString const & based on given storage
     310             :     */
     311     6669991 :     static inline OUString const & unacquired( rtl_uString * const * ppHandle )
     312     6669991 :         { return * reinterpret_cast< OUString const * >( ppHandle ); }
     313             : 
     314             :     /**
     315             :       Assign a new string.
     316             : 
     317             :       @param    str         a OUString.
     318             :     */
     319   394577386 :     OUString & operator=( const OUString & str )
     320             :     {
     321   394577386 :         rtl_uString_assign( &pData, str.pData );
     322   394577395 :         return *this;
     323             :     }
     324             : 
     325             :     /**
     326             :       Assign a new string from an 8-Bit string literal that is expected to contain only
     327             :       characters in the ASCII set (i.e. first 128 characters). This operator
     328             :       allows an efficient and convenient way to assign OUString
     329             :       instances from ASCII literals. When assigning strings from data that
     330             :       is not pure ASCII, it needs to be converted to OUString by explicitly
     331             :       providing the encoding to use for the conversion.
     332             : 
     333             :       @param    literal         the 8-bit ASCII string literal
     334             : 
     335             :       @since LibreOffice 3.6
     336             :     */
     337             :     template< typename T >
     338    23610606 :     typename libreoffice_internal::ConstCharArrayDetector< T, OUString& >::Type operator=( T& literal )
     339             :     {
     340             :         assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
     341             :         if( libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 == 0 ) // empty string
     342    14495886 :             rtl_uString_new( &pData );
     343             :         else
     344     9114720 :             rtl_uString_newFromLiteral( &pData, literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1, 0 );
     345    23610606 :         return *this;
     346             :     }
     347             : 
     348             :     /**
     349             :       Append a string to this string.
     350             : 
     351             :       @param    str         a OUString.
     352             :     */
     353    14149404 :     OUString & operator+=( const OUString & str )
     354             :     {
     355    14149404 :         rtl_uString_newConcat( &pData, pData, str.pData );
     356    14149404 :         return *this;
     357             :     }
     358             : 
     359             : #ifdef RTL_FAST_STRING
     360             :     /**
     361             :      @overload
     362             :      @internal
     363             :     */
     364             :     template< typename T1, typename T2 >
     365       13277 :     OUString& operator+=( const OUStringConcat< T1, T2 >& c )
     366             :     {
     367       13277 :         const int l = c.length();
     368       13277 :         if( l == 0 )
     369           0 :             return *this;
     370       13277 :         rtl_uString_ensureCapacity( &pData, pData->length + l );
     371       13277 :         sal_Unicode* end = c.addData( pData->buffer + pData->length );
     372       13277 :         *end = '\0';
     373       13277 :         pData->length = end - pData->buffer;
     374       13277 :         return *this;
     375             :     }
     376             : #endif
     377             : 
     378             :     /**
     379             :       Returns the length of this string.
     380             : 
     381             :       The length is equal to the number of Unicode characters in this string.
     382             : 
     383             :       @return   the length of the sequence of characters represented by this
     384             :                 object.
     385             :     */
     386  1055879933 :     sal_Int32 getLength() const { return pData->length; }
     387             : 
     388             :     /**
     389             :       Checks if a string is empty.
     390             : 
     391             :       @return   true if the string is empty;
     392             :                 false, otherwise.
     393             : 
     394             :       @since LibreOffice 3.4
     395             :     */
     396    91043140 :     bool isEmpty() const
     397             :     {
     398    91043140 :         return pData->length == 0;
     399             :     }
     400             : 
     401             :     /**
     402             :       Returns a pointer to the Unicode character buffer for this string.
     403             : 
     404             :       It isn't necessarily NULL terminated.
     405             : 
     406             :       @return   a pointer to the Unicode characters buffer for this object.
     407             :     */
     408   480304440 :     const sal_Unicode * getStr() const { return pData->buffer; }
     409             : 
     410             :     /**
     411             :       Access to individual characters.
     412             : 
     413             :       @param index must be non-negative and less than length.
     414             : 
     415             :       @return the character at the given index.
     416             : 
     417             :       @since LibreOffice 3.5
     418             :     */
     419   388679680 :     sal_Unicode operator [](sal_Int32 index) const {
     420             :         // silence spurious -Werror=strict-overflow warnings from GCC 4.8.2
     421             :         assert(index >= 0 && static_cast<sal_uInt32>(index) < static_cast<sal_uInt32>(getLength()));
     422   388679680 :         return getStr()[index];
     423             :     }
     424             : 
     425             :     /**
     426             :       Compares two strings.
     427             : 
     428             :       The comparison is based on the numeric value of each character in
     429             :       the strings and return a value indicating their relationship.
     430             :       This function can't be used for language specific sorting.
     431             : 
     432             :       @param    str         the object to be compared.
     433             :       @return   0 - if both strings are equal
     434             :                 < 0 - if this string is less than the string argument
     435             :                 > 0 - if this string is greater than the string argument
     436             :     */
     437   345415315 :     sal_Int32 compareTo( const OUString & str ) const
     438             :     {
     439             :         return rtl_ustr_compare_WithLength( pData->buffer, pData->length,
     440   345415315 :                                             str.pData->buffer, str.pData->length );
     441             :     }
     442             : 
     443             :     /**
     444             :       Compares two strings with a maximum count of characters.
     445             : 
     446             :       The comparison is based on the numeric value of each character in
     447             :       the strings and return a value indicating their relationship.
     448             :       This function can't be used for language specific sorting.
     449             : 
     450             :       @param    str         the object to be compared.
     451             :       @param    maxLength   the maximum count of characters to be compared.
     452             :       @return   0 - if both strings are equal
     453             :                 < 0 - if this string is less than the string argument
     454             :                 > 0 - if this string is greater than the string argument
     455             : 
     456             :       @since UDK 3.2.7
     457             :     */
     458        5886 :     sal_Int32 compareTo( const OUString & str, sal_Int32 maxLength ) const
     459             :     {
     460             :         return rtl_ustr_shortenedCompare_WithLength( pData->buffer, pData->length,
     461        5886 :                                                      str.pData->buffer, str.pData->length, maxLength );
     462             :     }
     463             : 
     464             :     /**
     465             :       Compares two strings in reverse order.
     466             : 
     467             :       The comparison is based on the numeric value of each character in
     468             :       the strings and return a value indicating their relationship.
     469             :       This function can't be used for language specific sorting.
     470             : 
     471             :       @param    str         the object to be compared.
     472             :       @return   0 - if both strings are equal
     473             :                 < 0 - if this string is less than the string argument
     474             :                 > 0 - if this string is greater than the string argument
     475             :     */
     476           0 :     sal_Int32 reverseCompareTo( const OUString & str ) const
     477             :     {
     478             :         return rtl_ustr_reverseCompare_WithLength( pData->buffer, pData->length,
     479           0 :                                                    str.pData->buffer, str.pData->length );
     480             :     }
     481             : 
     482             :     /**
     483             :      @overload
     484             :      This function accepts an ASCII string literal as its argument.
     485             :      @since LibreOffice 4.1
     486             :     */
     487             :     template< typename T >
     488           2 :     typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type reverseCompareTo( T& literal ) const
     489             :     {
     490             :         assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
     491             :         return rtl_ustr_asciil_reverseCompare_WithLength( pData->buffer, pData->length,
     492           2 :             literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 );
     493             :     }
     494             : 
     495             :     /**
     496             :       Perform a comparison of two strings.
     497             : 
     498             :       The result is true if and only if second string
     499             :       represents the same sequence of characters as the first string.
     500             :       This function can't be used for language specific comparison.
     501             : 
     502             :       @param    str         the object to be compared.
     503             :       @return   true if the strings are equal;
     504             :                 false, otherwise.
     505             :     */
     506  1329327995 :     bool equals( const OUString & str ) const
     507             :     {
     508  1329327995 :         if ( pData->length != str.pData->length )
     509  1060146058 :             return false;
     510   269181937 :         if ( pData == str.pData )
     511    88033877 :             return true;
     512             :         return rtl_ustr_reverseCompare_WithLength( pData->buffer, pData->length,
     513   181148060 :                                                    str.pData->buffer, str.pData->length ) == 0;
     514             :     }
     515             : 
     516             :     /**
     517             :       Perform a ASCII lowercase comparison of two strings.
     518             : 
     519             :       The result is true if and only if second string
     520             :       represents the same sequence of characters as the first string,
     521             :       ignoring the case.
     522             :       Character values between 65 and 90 (ASCII A-Z) are interpreted as
     523             :       values between 97 and 122 (ASCII a-z).
     524             :       This function can't be used for language specific comparison.
     525             : 
     526             :       @param    str         the object to be compared.
     527             :       @return   true if the strings are equal;
     528             :                 false, otherwise.
     529             :     */
     530     4547855 :     bool equalsIgnoreAsciiCase( const OUString & str ) const
     531             :     {
     532     4547855 :         if ( pData->length != str.pData->length )
     533     3413041 :             return false;
     534     1134814 :         if ( pData == str.pData )
     535      164066 :             return true;
     536             :         return rtl_ustr_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
     537      970748 :                                                            str.pData->buffer, str.pData->length ) == 0;
     538             :     }
     539             : 
     540             :     /**
     541             :       Perform a ASCII lowercase comparison of two strings.
     542             : 
     543             :       Compare the two strings with uppercase ASCII
     544             :       character values between 65 and 90 (ASCII A-Z) interpreted as
     545             :       values between 97 and 122 (ASCII a-z).
     546             :       This function can't be used for language specific comparison.
     547             : 
     548             :       @param    str         the object to be compared.
     549             :       @return   0 - if both strings are equal
     550             :                 < 0 - if this string is less than the string argument
     551             :                 > 0 - if this string is greater than the string argument
     552             : 
     553             :       @since LibreOffice 4.0
     554             :     */
     555     8694988 :     sal_Int32 compareToIgnoreAsciiCase( const OUString & str ) const
     556             :     {
     557             :         return rtl_ustr_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
     558     8694988 :                                                            str.pData->buffer, str.pData->length );
     559             :     }
     560             : 
     561             : 
     562             :     /**
     563             :      @overload
     564             :      This function accepts an ASCII string literal as its argument.
     565             :      @since LibreOffice 3.6
     566             :     */
     567             :     template< typename T >
     568     5006041 :     typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type equalsIgnoreAsciiCase( T& literal ) const
     569             :     {
     570             :         assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
     571     5006041 :         if ( pData->length != libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 )
     572     3700456 :             return false;
     573             : 
     574     1305585 :         return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, literal ) == 0;
     575             :     }
     576             : 
     577             :    /**
     578             :       Match against a substring appearing in this string.
     579             : 
     580             :       The result is true if and only if the second string appears as a substring
     581             :       of this string, at the given position.
     582             :       This function can't be used for language specific comparison.
     583             : 
     584             :       @param    str         the object (substring) to be compared.
     585             :       @param    fromIndex   the index to start the comparion from.
     586             :                             The index must be greater than or equal to 0
     587             :                             and less or equal as the string length.
     588             :       @return   true if str match with the characters in the string
     589             :                 at the given position;
     590             :                 false, otherwise.
     591             :     */
     592    71942326 :     bool match( const OUString & str, sal_Int32 fromIndex = 0 ) const
     593             :     {
     594    71942326 :         return rtl_ustr_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
     595   143884652 :                                                      str.pData->buffer, str.pData->length, str.pData->length ) == 0;
     596             :     }
     597             : 
     598             :     /**
     599             :      @overload
     600             :      This function accepts an ASCII string literal as its argument.
     601             :      @since LibreOffice 3.6
     602             :     */
     603             :     template< typename T >
     604      520135 :     typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type match( T& literal, sal_Int32 fromIndex = 0 ) const
     605             :     {
     606             :         assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
     607      520135 :         return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
     608     1040270 :             literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 ) == 0;
     609             :     }
     610             : 
     611             :     /**
     612             :       Match against a substring appearing in this string, ignoring the case of
     613             :       ASCII letters.
     614             : 
     615             :       The result is true if and only if the second string appears as a substring
     616             :       of this string, at the given position.
     617             :       Character values between 65 and 90 (ASCII A-Z) are interpreted as
     618             :       values between 97 and 122 (ASCII a-z).
     619             :       This function can't be used for language specific comparison.
     620             : 
     621             :       @param    str         the object (substring) to be compared.
     622             :       @param    fromIndex   the index to start the comparion from.
     623             :                             The index must be greater than or equal to 0
     624             :                             and less than or equal to the string length.
     625             :       @return   true if str match with the characters in the string
     626             :                 at the given position;
     627             :                 false, otherwise.
     628             :     */
     629      140212 :     bool matchIgnoreAsciiCase( const OUString & str, sal_Int32 fromIndex = 0 ) const
     630             :     {
     631      140212 :         return rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
     632             :                                                                     str.pData->buffer, str.pData->length,
     633      280424 :                                                                     str.pData->length ) == 0;
     634             :     }
     635             : 
     636             :     /**
     637             :      @overload
     638             :      This function accepts an ASCII string literal as its argument.
     639             :      @since LibreOffice 3.6
     640             :     */
     641             :     template< typename T >
     642        1708 :     typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type matchIgnoreAsciiCase( T& literal, sal_Int32 fromIndex = 0 ) const
     643             :     {
     644             :         assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
     645        1708 :         return rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
     646        3416 :             literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 ) == 0;
     647             :     }
     648             : 
     649             :     /**
     650             :       Compares two strings.
     651             : 
     652             :       The comparison is based on the numeric value of each character in
     653             :       the strings and return a value indicating their relationship.
     654             :       Since this method is optimized for performance, the ASCII character
     655             :       values are not converted in any way. The caller has to make sure that
     656             :       all ASCII characters are in the allowed range between 0 and
     657             :       127. The ASCII string must be NULL-terminated.
     658             :       This function can't be used for language specific sorting.
     659             : 
     660             :       @param  asciiStr      the 8-Bit ASCII character string to be compared.
     661             :       @return   0 - if both strings are equal
     662             :                 < 0 - if this string is less than the string argument
     663             :                 > 0 - if this string is greater than the string argument
     664             :     */
     665       75222 :     sal_Int32 compareToAscii( const sal_Char* asciiStr ) const
     666             :     {
     667       75222 :         return rtl_ustr_ascii_compare_WithLength( pData->buffer, pData->length, asciiStr );
     668             :     }
     669             : 
     670             :     /**
     671             :       Compares two strings with a maximum count of characters.
     672             : 
     673             :       The comparison is based on the numeric value of each character in
     674             :       the strings and return a value indicating their relationship.
     675             :       Since this method is optimized for performance, the ASCII character
     676             :       values are not converted in any way. The caller has to make sure that
     677             :       all ASCII characters are in the allowed range between 0 and
     678             :       127. The ASCII string must be NULL-terminated.
     679             :       This function can't be used for language specific sorting.
     680             : 
     681             :       @deprecated  This is a confusing overload with unexpectedly different
     682             :       semantics from the one-parameter form, so it is marked as deprecated.
     683             :       Practically all uses compare the return value against zero and can thus
     684             :       be replaced with uses of startsWith.
     685             : 
     686             :       @param  asciiStr          the 8-Bit ASCII character string to be compared.
     687             :       @param  maxLength         the maximum count of characters to be compared.
     688             :       @return   0 - if both strings are equal
     689             :                 < 0 - if this string is less than the string argument
     690             :                 > 0 - if this string is greater than the string argument
     691             :     */
     692             :     SAL_DEPRECATED(
     693             :         "replace s1.compareToAscii(s2, strlen(s2)) == 0 with s1.startsWith(s2)")
     694             :     sal_Int32 compareToAscii( const sal_Char * asciiStr, sal_Int32 maxLength ) const
     695             :     {
     696             :         return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer, pData->length,
     697             :                                                            asciiStr, maxLength );
     698             :     }
     699             : 
     700             :     /**
     701             :       Compares two strings in reverse order.
     702             : 
     703             :       This could be useful, if normally both strings start with the same
     704             :       content. The comparison is based on the numeric value of each character
     705             :       in the strings and return a value indicating their relationship.
     706             :       Since this method is optimized for performance, the ASCII character
     707             :       values are not converted in any way. The caller has to make sure that
     708             :       all ASCII characters are in the allowed range between 0 and 127.
     709             :       The ASCII string must be NULL-terminated and must be greater than
     710             :       or equal to asciiStrLength.
     711             :       This function can't be used for language specific sorting.
     712             : 
     713             :       @param    asciiStr        the 8-Bit ASCII character string to be compared.
     714             :       @param    asciiStrLength  the length of the ascii string
     715             :       @return   0 - if both strings are equal
     716             :                 < 0 - if this string is less than the string argument
     717             :                 > 0 - if this string is greater than the string argument
     718             :     */
     719        6664 :     sal_Int32 reverseCompareToAsciiL( const sal_Char * asciiStr, sal_Int32 asciiStrLength ) const
     720             :     {
     721             :         return rtl_ustr_asciil_reverseCompare_WithLength( pData->buffer, pData->length,
     722        6664 :                                                           asciiStr, asciiStrLength );
     723             :     }
     724             : 
     725             :     /**
     726             :       Perform a comparison of two strings.
     727             : 
     728             :       The result is true if and only if second string
     729             :       represents the same sequence of characters as the first string.
     730             :       Since this method is optimized for performance, the ASCII character
     731             :       values are not converted in any way. The caller has to make sure that
     732             :       all ASCII characters are in the allowed range between 0 and
     733             :       127. The ASCII string must be NULL-terminated.
     734             :       This function can't be used for language specific comparison.
     735             : 
     736             :       @param    asciiStr        the 8-Bit ASCII character string to be compared.
     737             :       @return   true if the strings are equal;
     738             :                 false, otherwise.
     739             :     */
     740  1106332180 :     bool equalsAscii( const sal_Char* asciiStr ) const
     741             :     {
     742             :         return rtl_ustr_ascii_compare_WithLength( pData->buffer, pData->length,
     743  1106332180 :                                                   asciiStr ) == 0;
     744             :     }
     745             : 
     746             :     /**
     747             :       Perform a comparison of two strings.
     748             : 
     749             :       The result is true if and only if second string
     750             :       represents the same sequence of characters as the first string.
     751             :       Since this method is optimized for performance, the ASCII character
     752             :       values are not converted in any way. The caller has to make sure that
     753             :       all ASCII characters are in the allowed range between 0 and
     754             :       127. The ASCII string must be NULL-terminated and must be greater than
     755             :       or equal to asciiStrLength.
     756             :       This function can't be used for language specific comparison.
     757             : 
     758             :       @param    asciiStr         the 8-Bit ASCII character string to be compared.
     759             :       @param    asciiStrLength   the length of the ascii string
     760             :       @return   true if the strings are equal;
     761             :                 false, otherwise.
     762             :     */
     763   206895103 :     bool equalsAsciiL( const sal_Char* asciiStr, sal_Int32 asciiStrLength ) const
     764             :     {
     765   206895103 :         if ( pData->length != asciiStrLength )
     766   160922878 :             return false;
     767             : 
     768             :         return rtl_ustr_asciil_reverseEquals_WithLength(
     769    45972225 :                     pData->buffer, asciiStr, asciiStrLength );
     770             :     }
     771             : 
     772             :     /**
     773             :       Perform a ASCII lowercase comparison of two strings.
     774             : 
     775             :       The result is true if and only if second string
     776             :       represents the same sequence of characters as the first string,
     777             :       ignoring the case.
     778             :       Character values between 65 and 90 (ASCII A-Z) are interpreted as
     779             :       values between 97 and 122 (ASCII a-z).
     780             :       Since this method is optimized for performance, the ASCII character
     781             :       values are not converted in any way. The caller has to make sure that
     782             :       all ASCII characters are in the allowed range between 0 and
     783             :       127. The ASCII string must be NULL-terminated.
     784             :       This function can't be used for language specific comparison.
     785             : 
     786             :       @param    asciiStr        the 8-Bit ASCII character string to be compared.
     787             :       @return   true if the strings are equal;
     788             :                 false, otherwise.
     789             :     */
     790     1913914 :     bool equalsIgnoreAsciiCaseAscii( const sal_Char * asciiStr ) const
     791             :     {
     792     1913914 :         return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr ) == 0;
     793             :     }
     794             : 
     795             :     /**
     796             :       Compares two ASCII strings ignoring case
     797             : 
     798             :       The comparison is based on the numeric value of each character in
     799             :       the strings and return a value indicating their relationship.
     800             :       Since this method is optimized for performance, the ASCII character
     801             :       values are not converted in any way. The caller has to make sure that
     802             :       all ASCII characters are in the allowed range between 0 and
     803             :       127. The ASCII string must be NULL-terminated.
     804             :       This function can't be used for language specific sorting.
     805             : 
     806             :       @param  asciiStr      the 8-Bit ASCII character string to be compared.
     807             :       @return   0 - if both strings are equal
     808             :                 < 0 - if this string is less than the string argument
     809             :                 > 0 - if this string is greater than the string argument
     810             : 
     811             :       @since LibreOffice 3.5
     812             :     */
     813   413364153 :     sal_Int32 compareToIgnoreAsciiCaseAscii( const sal_Char * asciiStr ) const
     814             :     {
     815   413364153 :         return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr );
     816             :     }
     817             : 
     818             :     /**
     819             :       Perform an ASCII lowercase comparison of two strings.
     820             : 
     821             :       The result is true if and only if second string
     822             :       represents the same sequence of characters as the first string,
     823             :       ignoring the case.
     824             :       Character values between 65 and 90 (ASCII A-Z) are interpreted as
     825             :       values between 97 and 122 (ASCII a-z).
     826             :       Since this method is optimized for performance, the ASCII character
     827             :       values are not converted in any way. The caller has to make sure that
     828             :       all ASCII characters are in the allowed range between 0 and 127.
     829             :       The ASCII string must be NULL-terminated and must be greater than
     830             :       or equal to asciiStrLength.
     831             :       This function can't be used for language specific comparison.
     832             : 
     833             :       @param    asciiStr        the 8-Bit ASCII character string to be compared.
     834             :       @param    asciiStrLength  the length of the ascii string
     835             :       @return   true if the strings are equal;
     836             :                 false, otherwise.
     837             :     */
     838      293540 :     bool equalsIgnoreAsciiCaseAsciiL( const sal_Char * asciiStr, sal_Int32 asciiStrLength ) const
     839             :     {
     840      293540 :         if ( pData->length != asciiStrLength )
     841       48690 :             return false;
     842             : 
     843      244850 :         return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr ) == 0;
     844             :     }
     845             : 
     846             :     /**
     847             :       Match against a substring appearing in this string.
     848             : 
     849             :       The result is true if and only if the second string appears as a substring
     850             :       of this string, at the given position.
     851             :       Since this method is optimized for performance, the ASCII character
     852             :       values are not converted in any way. The caller has to make sure that
     853             :       all ASCII characters are in the allowed range between 0 and
     854             :       127. The ASCII string must be NULL-terminated and must be greater than or
     855             :       equal to asciiStrLength.
     856             :       This function can't be used for language specific comparison.
     857             : 
     858             :       @param    asciiStr    the object (substring) to be compared.
     859             :       @param    asciiStrLength the length of asciiStr.
     860             :       @param    fromIndex   the index to start the comparion from.
     861             :                             The index must be greater than or equal to 0
     862             :                             and less than or equal to the string length.
     863             :       @return   true if str match with the characters in the string
     864             :                 at the given position;
     865             :                 false, otherwise.
     866             :     */
     867      515789 :     bool matchAsciiL( const sal_Char* asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex = 0 ) const
     868             :     {
     869      515789 :         return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
     870     1031578 :                                                            asciiStr, asciiStrLength ) == 0;
     871             :     }
     872             : 
     873             :     // This overload is left undefined, to detect calls of matchAsciiL that
     874             :     // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
     875             :     // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
     876             :     // platforms):
     877             : #if SAL_TYPES_SIZEOFLONG == 8
     878             :     void matchAsciiL(char const *, sal_Int32, rtl_TextEncoding) const;
     879             : #endif
     880             : 
     881             :     /**
     882             :       Match against a substring appearing in this string, ignoring the case of
     883             :       ASCII letters.
     884             : 
     885             :       The result is true if and only if the second string appears as a substring
     886             :       of this string, at the given position.
     887             :       Character values between 65 and 90 (ASCII A-Z) are interpreted as
     888             :       values between 97 and 122 (ASCII a-z).
     889             :       Since this method is optimized for performance, the ASCII character
     890             :       values are not converted in any way. The caller has to make sure that
     891             :       all ASCII characters are in the allowed range between 0 and
     892             :       127. The ASCII string must be NULL-terminated and must be greater than or
     893             :       equal to asciiStrLength.
     894             :       This function can't be used for language specific comparison.
     895             : 
     896             :       @param    asciiStr        the 8-Bit ASCII character string to be compared.
     897             :       @param    asciiStrLength  the length of the ascii string
     898             :       @param    fromIndex       the index to start the comparion from.
     899             :                                 The index must be greater than or equal to 0
     900             :                                 and less than or equal to the string length.
     901             :       @return   true if str match with the characters in the string
     902             :                 at the given position;
     903             :                 false, otherwise.
     904             :     */
     905     3129103 :     bool matchIgnoreAsciiCaseAsciiL( const sal_Char* asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex = 0 ) const
     906             :     {
     907     3129103 :         return rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
     908     6258206 :                                                                           asciiStr, asciiStrLength ) == 0;
     909             :     }
     910             : 
     911             :     // This overload is left undefined, to detect calls of
     912             :     // matchIgnoreAsciiCaseAsciiL that erroneously use
     913             :     // RTL_CONSTASCII_USTRINGPARAM instead of RTL_CONSTASCII_STRINGPARAM (but
     914             :     // would lead to ambiguities on 32 bit platforms):
     915             : #if SAL_TYPES_SIZEOFLONG == 8
     916             :     void matchIgnoreAsciiCaseAsciiL(char const *, sal_Int32, rtl_TextEncoding)
     917             :         const;
     918             : #endif
     919             : 
     920             :     /**
     921             :       Check whether this string starts with a given substring.
     922             : 
     923             :       @param str the substring to be compared
     924             : 
     925             :       @param rest if non-null, and this function returns true, then assign a
     926             :       copy of the remainder of this string to *rest. Available since
     927             :       LibreOffice 4.2
     928             : 
     929             :       @return true if and only if the given str appears as a substring at the
     930             :       start of this string
     931             : 
     932             :       @since LibreOffice 4.0
     933             :     */
     934    70395265 :     bool startsWith(OUString const & str, OUString * rest = 0) const {
     935    70395265 :         bool b = match(str, 0);
     936    70395265 :         if (b && rest != 0) {
     937           0 :             *rest = copy(str.getLength());
     938             :         }
     939    70395265 :         return b;
     940             :     }
     941             : 
     942             :     /**
     943             :      @overload
     944             :      This function accepts an ASCII string literal as its argument.
     945             :      @since LibreOffice 4.0
     946             :     */
     947             :     template< typename T >
     948    16039972 :     typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWith(
     949             :         T & literal, OUString * rest = 0) const
     950             :     {
     951             :         assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
     952             :         bool b = libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 <= pData->length
     953             :             && rtl_ustr_asciil_reverseEquals_WithLength( pData->buffer, literal,
     954    16039972 :                 libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1);
     955    16039972 :         if (b && rest != 0) {
     956      308919 :             *rest = copy(libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1);
     957             :         }
     958    16039972 :         return b;
     959             :     }
     960             : 
     961             :     /**
     962             :       Check whether this string starts with a given string, ignoring the case of
     963             :       ASCII letters.
     964             : 
     965             :       Character values between 65 and 90 (ASCII A-Z) are interpreted as
     966             :       values between 97 and 122 (ASCII a-z).
     967             :       This function can't be used for language specific comparison.
     968             : 
     969             :       @param str the substring to be compared
     970             : 
     971             :       @param rest if non-null, and this function returns true, then assign a
     972             :       copy of the remainder of this string to *rest. Available since
     973             :       LibreOffice 4.2
     974             : 
     975             :       @return true if and only if the given str appears as a substring at the
     976             :       start of this string, ignoring the case of ASCII letters ("A"--"Z" and
     977             :       "a"--"z")
     978             : 
     979             :       @since LibreOffice 4.0
     980             :     */
     981         448 :     bool startsWithIgnoreAsciiCase(OUString const & str, OUString * rest = 0)
     982             :         const
     983             :     {
     984         448 :         bool b = matchIgnoreAsciiCase(str, 0);
     985         448 :         if (b && rest != 0) {
     986           0 :             *rest = copy(str.getLength());
     987             :         }
     988         448 :         return b;
     989             :     }
     990             : 
     991             :     /**
     992             :      @overload
     993             :      This function accepts an ASCII string literal as its argument.
     994             :      @since LibreOffice 4.0
     995             :     */
     996             :     template< typename T >
     997             :     typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
     998      281137 :     startsWithIgnoreAsciiCase(T & literal, OUString * rest = 0) const
     999             :     {
    1000             :         assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
    1001             :         bool b = (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
    1002             :                     pData->buffer,
    1003             :                     libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1, literal,
    1004      281137 :                     libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1)
    1005      281137 :                 == 0);
    1006      281137 :         if (b && rest != 0) {
    1007          24 :             *rest = copy(libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1);
    1008             :         }
    1009      281137 :         return b;
    1010             :     }
    1011             : 
    1012             :     /**
    1013             :       Check whether this string ends with a given substring.
    1014             : 
    1015             :       @param str the substring to be compared
    1016             : 
    1017             :       @param rest if non-null, and this function returns true, then assign a
    1018             :       copy of the remainder of this string to *rest. Available since
    1019             :       LibreOffice 4.2
    1020             : 
    1021             :       @return true if and only if the given str appears as a substring at the
    1022             :       end of this string
    1023             : 
    1024             :       @since LibreOffice 3.6
    1025             :     */
    1026       20087 :     bool endsWith(OUString const & str, OUString * rest = 0) const {
    1027       20087 :         bool b = str.getLength() <= getLength()
    1028       20087 :             && match(str, getLength() - str.getLength());
    1029       20087 :         if (b && rest != 0) {
    1030           0 :             *rest = copy(0, getLength() - str.getLength());
    1031             :         }
    1032       20087 :         return b;
    1033             :     }
    1034             : 
    1035             :     /**
    1036             :      @overload
    1037             :      This function accepts an ASCII string literal as its argument.
    1038             :      @since LibreOffice 3.6
    1039             :     */
    1040             :     template< typename T >
    1041             :     typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
    1042      634683 :     endsWith(T & literal, OUString * rest = 0) const
    1043             :     {
    1044             :         assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
    1045             :         bool b = libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 <= pData->length
    1046             :             && rtl_ustr_asciil_reverseEquals_WithLength(
    1047      629447 :                 pData->buffer + pData->length - ( libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 ), literal,
    1048     1264130 :                 libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1);
    1049      634683 :         if (b && rest != 0) {
    1050       10159 :             *rest = copy(
    1051             :                 0,
    1052       10159 :                 (getLength()
    1053             :                  - (libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1)));
    1054             :         }
    1055      634683 :         return b;
    1056             :     }
    1057             : 
    1058             :     /**
    1059             :       Check whether this string ends with a given ASCII string.
    1060             : 
    1061             :       @param asciiStr a sequence of at least asciiStrLength ASCII characters
    1062             :           (bytes in the range 0x00--0x7F)
    1063             :       @param asciiStrLength the length of asciiStr; must be non-negative
    1064             :       @return true if this string ends with asciiStr; otherwise, false is
    1065             :       returned
    1066             : 
    1067             :       @since UDK 3.2.7
    1068             :      */
    1069       56400 :     inline bool endsWithAsciiL(char const * asciiStr, sal_Int32 asciiStrLength)
    1070             :         const
    1071             :     {
    1072       56400 :         return asciiStrLength <= pData->length
    1073      112798 :             && rtl_ustr_asciil_reverseEquals_WithLength(
    1074       56398 :                 pData->buffer + pData->length - asciiStrLength, asciiStr,
    1075      112798 :                 asciiStrLength);
    1076             :     }
    1077             : 
    1078             :     /**
    1079             :       Check whether this string ends with a given string, ignoring the case of
    1080             :       ASCII letters.
    1081             : 
    1082             :       Character values between 65 and 90 (ASCII A-Z) are interpreted as
    1083             :       values between 97 and 122 (ASCII a-z).
    1084             :       This function can't be used for language specific comparison.
    1085             : 
    1086             :       @param str the substring to be compared
    1087             : 
    1088             :       @param rest if non-null, and this function returns true, then assign a
    1089             :       copy of the remainder of this string to *rest. Available since
    1090             :       LibreOffice 4.2
    1091             : 
    1092             :       @return true if and only if the given str appears as a substring at the
    1093             :       end of this string, ignoring the case of ASCII letters ("A"--"Z" and
    1094             :       "a"--"z")
    1095             : 
    1096             :       @since LibreOffice 3.6
    1097             :     */
    1098         274 :     bool endsWithIgnoreAsciiCase(OUString const & str, OUString * rest = 0) const
    1099             :     {
    1100         274 :         bool b =  str.getLength() <= getLength()
    1101         274 :             && matchIgnoreAsciiCase(str, getLength() - str.getLength());
    1102         274 :         if (b && rest != 0) {
    1103           0 :             *rest = copy(0, getLength() - str.getLength());
    1104             :         }
    1105         274 :         return b;
    1106             :     }
    1107             : 
    1108             :     /**
    1109             :      @overload
    1110             :      This function accepts an ASCII string literal as its argument.
    1111             :      @since LibreOffice 3.6
    1112             :     */
    1113             :     template< typename T >
    1114             :     typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
    1115      280154 :     endsWithIgnoreAsciiCase(T & literal, OUString * rest = 0) const
    1116             :     {
    1117             :         assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
    1118             :         bool b = libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 <= pData->length
    1119             :             && (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
    1120      280095 :                     pData->buffer + pData->length - ( libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 ),
    1121             :                     libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1, literal,
    1122      280095 :                     libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1)
    1123      560249 :                 == 0);
    1124      280154 :         if (b && rest != 0) {
    1125           0 :             *rest = copy(
    1126             :                 0,
    1127           0 :                 (getLength()
    1128             :                  - (libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1)));
    1129             :         }
    1130      280154 :         return b;
    1131             :     }
    1132             : 
    1133             :     /**
    1134             :       Check whether this string ends with a given ASCII string, ignoring the
    1135             :       case of ASCII letters.
    1136             : 
    1137             :       @param asciiStr a sequence of at least asciiStrLength ASCII characters
    1138             :           (bytes in the range 0x00--0x7F)
    1139             :       @param asciiStrLength the length of asciiStr; must be non-negative
    1140             :       @return true if this string ends with asciiStr, ignoring the case of ASCII
    1141             :       letters ("A"--"Z" and "a"--"z"); otherwise, false is returned
    1142             :      */
    1143    24973935 :     inline bool endsWithIgnoreAsciiCaseAsciiL(
    1144             :         char const * asciiStr, sal_Int32 asciiStrLength) const
    1145             :     {
    1146    24973935 :         return asciiStrLength <= pData->length
    1147    44612068 :             && (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
    1148    19638133 :                     pData->buffer + pData->length - asciiStrLength,
    1149    19638133 :                     asciiStrLength, asciiStr, asciiStrLength)
    1150    24973935 :                 == 0);
    1151             :     }
    1152             : 
    1153   916684748 :     friend bool     operator == ( const OUString& rStr1,    const OUString& rStr2 )
    1154   916684748 :                         { return rStr1.equals(rStr2); }
    1155       70786 :     friend bool     operator == ( const OUString& rStr1,    const sal_Unicode * pStr2 )
    1156       70786 :                         { return rStr1.compareTo( pStr2 ) == 0; }
    1157           0 :     friend bool     operator == ( const sal_Unicode * pStr1,    const OUString& rStr2 )
    1158           0 :                         { return OUString( pStr1 ).compareTo( rStr2 ) == 0; }
    1159             : 
    1160    45640933 :     friend bool     operator != ( const OUString& rStr1,        const OUString& rStr2 )
    1161    45640933 :                         { return !(operator == ( rStr1, rStr2 )); }
    1162       70766 :     friend bool     operator != ( const OUString& rStr1,    const sal_Unicode * pStr2 )
    1163       70766 :                         { return !(operator == ( rStr1, pStr2 )); }
    1164           0 :     friend bool     operator != ( const sal_Unicode * pStr1,    const OUString& rStr2 )
    1165           0 :                         { return !(operator == ( pStr1, rStr2 )); }
    1166             : 
    1167   265291088 :     friend bool     operator <  ( const OUString& rStr1,    const OUString& rStr2 )
    1168   265291088 :                         { return rStr1.compareTo( rStr2 ) < 0; }
    1169    12093834 :     friend bool     operator >  ( const OUString& rStr1,    const OUString& rStr2 )
    1170    12093834 :                         { return rStr1.compareTo( rStr2 ) > 0; }
    1171           0 :     friend bool     operator <= ( const OUString& rStr1,    const OUString& rStr2 )
    1172           0 :                         { return rStr1.compareTo( rStr2 ) <= 0; }
    1173      855894 :     friend bool     operator >= ( const OUString& rStr1,    const OUString& rStr2 )
    1174      855894 :                         { return rStr1.compareTo( rStr2 ) >= 0; }
    1175             : 
    1176             :     /**
    1177             :      * Compare string to an ASCII string literal.
    1178             :      *
    1179             :      * This operator is equal to calling equalsAsciiL().
    1180             :      *
    1181             :      * @since LibreOffice 3.6
    1182             :      */
    1183             :     template< typename T >
    1184   175920230 :     friend inline typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator==( const OUString& string, T& literal )
    1185             :     {
    1186             :         assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
    1187   175920230 :         return string.equalsAsciiL( literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 );
    1188             :     }
    1189             :     /**
    1190             :      * Compare string to an ASCII string literal.
    1191             :      *
    1192             :      * This operator is equal to calling equalsAsciiL().
    1193             :      *
    1194             :      * @since LibreOffice 3.6
    1195             :      */
    1196             :     template< typename T >
    1197        9254 :     friend inline typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator==( T& literal, const OUString& string )
    1198             :     {
    1199             :         assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
    1200        9254 :         return string.equalsAsciiL( literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 );
    1201             :     }
    1202             :     /**
    1203             :      * Compare string to an ASCII string literal.
    1204             :      *
    1205             :      * This operator is equal to calling !equalsAsciiL().
    1206             :      *
    1207             :      * @since LibreOffice 3.6
    1208             :      */
    1209             :     template< typename T >
    1210     3163235 :     friend inline typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator!=( const OUString& string, T& literal )
    1211             :     {
    1212             :         assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
    1213     3163235 :         return !string.equalsAsciiL( literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 );
    1214             :     }
    1215             :     /**
    1216             :      * Compare string to an ASCII string literal.
    1217             :      *
    1218             :      * This operator is equal to calling !equalsAsciiL().
    1219             :      *
    1220             :      * @since LibreOffice 3.6
    1221             :      */
    1222             :     template< typename T >
    1223           2 :     friend inline typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator!=( T& literal, const OUString& string )
    1224             :     {
    1225             :         assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
    1226           2 :         return !string.equalsAsciiL( literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 );
    1227             :     }
    1228             : 
    1229             :     /**
    1230             :       Returns a hashcode for this string.
    1231             : 
    1232             :       @return   a hash code value for this object.
    1233             : 
    1234             :       @see rtl::OUStringHash for convenient use of boost::unordered_map
    1235             :     */
    1236    94668185 :     sal_Int32 hashCode() const
    1237             :     {
    1238    94668185 :         return rtl_ustr_hashCode_WithLength( pData->buffer, pData->length );
    1239             :     }
    1240             : 
    1241             :     /**
    1242             :       Returns the index within this string of the first occurrence of the
    1243             :       specified character, starting the search at the specified index.
    1244             : 
    1245             :       @param    ch          character to be located.
    1246             :       @param    fromIndex   the index to start the search from.
    1247             :                             The index must be greater than or equal to 0
    1248             :                             and less than or equal to the string length.
    1249             :       @return   the index of the first occurrence of the character in the
    1250             :                 character sequence represented by this string that is
    1251             :                 greater than or equal to fromIndex, or
    1252             :                 -1 if the character does not occur.
    1253             :     */
    1254    26230990 :     sal_Int32 indexOf( sal_Unicode ch, sal_Int32 fromIndex = 0 ) const
    1255             :     {
    1256    26230990 :         sal_Int32 ret = rtl_ustr_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
    1257    26230990 :         return (ret < 0 ? ret : ret+fromIndex);
    1258             :     }
    1259             : 
    1260             :     /**
    1261             :       Returns the index within this string of the last occurrence of the
    1262             :       specified character, searching backward starting at the end.
    1263             : 
    1264             :       @param    ch          character to be located.
    1265             :       @return   the index of the last occurrence of the character in the
    1266             :                 character sequence represented by this string, or
    1267             :                 -1 if the character does not occur.
    1268             :     */
    1269     1882710 :     sal_Int32 lastIndexOf( sal_Unicode ch ) const
    1270             :     {
    1271     1882710 :         return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
    1272             :     }
    1273             : 
    1274             :     /**
    1275             :       Returns the index within this string of the last occurrence of the
    1276             :       specified character, searching backward starting before the specified
    1277             :       index.
    1278             : 
    1279             :       @param    ch          character to be located.
    1280             :       @param    fromIndex   the index before which to start the search.
    1281             :       @return   the index of the last occurrence of the character in the
    1282             :                 character sequence represented by this string that
    1283             :                 is less than fromIndex, or -1
    1284             :                 if the character does not occur before that point.
    1285             :     */
    1286       58208 :     sal_Int32 lastIndexOf( sal_Unicode ch, sal_Int32 fromIndex ) const
    1287             :     {
    1288       58208 :         return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
    1289             :     }
    1290             : 
    1291             :     /**
    1292             :       Returns the index within this string of the first occurrence of the
    1293             :       specified substring, starting at the specified index.
    1294             : 
    1295             :       If str doesn't include any character, always -1 is
    1296             :       returned. This is also the case, if both strings are empty.
    1297             : 
    1298             :       @param    str         the substring to search for.
    1299             :       @param    fromIndex   the index to start the search from.
    1300             :       @return   If the string argument occurs one or more times as a substring
    1301             :                 within this string at the starting index, then the index
    1302             :                 of the first character of the first such substring is
    1303             :                 returned. If it does not occur as a substring starting
    1304             :                 at fromIndex or beyond, -1 is returned.
    1305             :     */
    1306    28111529 :     sal_Int32 indexOf( const OUString & str, sal_Int32 fromIndex = 0 ) const
    1307             :     {
    1308    28111529 :         sal_Int32 ret = rtl_ustr_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
    1309    56223058 :                                                         str.pData->buffer, str.pData->length );
    1310    28111529 :         return (ret < 0 ? ret : ret+fromIndex);
    1311             :     }
    1312             : 
    1313             :     /**
    1314             :      @overload
    1315             :      This function accepts an ASCII string literal as its argument.
    1316             :      @since LibreOffice 3.6
    1317             :     */
    1318             :     template< typename T >
    1319     5637498 :     typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const
    1320             :     {
    1321             :         assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
    1322             :         sal_Int32 ret = rtl_ustr_indexOfAscii_WithLength(
    1323     5637498 :             pData->buffer + fromIndex, pData->length - fromIndex, literal,
    1324    11274996 :             libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1);
    1325     5637498 :         return ret < 0 ? ret : ret + fromIndex;
    1326             :     }
    1327             : 
    1328             :     /**
    1329             :        Returns the index within this string of the first occurrence of the
    1330             :        specified ASCII substring, starting at the specified index.
    1331             : 
    1332             :        @param str
    1333             :        the substring to be searched for.  Need not be null-terminated, but must
    1334             :        be at least as long as the specified len.  Must only contain characters
    1335             :        in the ASCII range 0x00--7F.
    1336             : 
    1337             :        @param len
    1338             :        the length of the substring; must be non-negative.
    1339             : 
    1340             :        @param fromIndex
    1341             :        the index to start the search from.  Must be in the range from zero to
    1342             :        the length of this string, inclusive.
    1343             : 
    1344             :        @return
    1345             :        the index (starting at 0) of the first character of the first occurrence
    1346             :        of the substring within this string starting at the given fromIndex, or
    1347             :        -1 if the substring does not occur.  If len is zero, -1 is returned.
    1348             : 
    1349             :        @since UDK 3.2.7
    1350             :     */
    1351      794846 :     sal_Int32 indexOfAsciiL(
    1352             :         char const * str, sal_Int32 len, sal_Int32 fromIndex = 0) const
    1353             :     {
    1354             :         sal_Int32 ret = rtl_ustr_indexOfAscii_WithLength(
    1355      794846 :             pData->buffer + fromIndex, pData->length - fromIndex, str, len);
    1356      794846 :         return ret < 0 ? ret : ret + fromIndex;
    1357             :     }
    1358             : 
    1359             :     // This overload is left undefined, to detect calls of indexOfAsciiL that
    1360             :     // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
    1361             :     // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
    1362             :     // platforms):
    1363             : #if SAL_TYPES_SIZEOFLONG == 8
    1364             :     void indexOfAsciiL(char const *, sal_Int32 len, rtl_TextEncoding) const;
    1365             : #endif
    1366             : 
    1367             :     /**
    1368             :       Returns the index within this string of the last occurrence of
    1369             :       the specified substring, searching backward starting at the end.
    1370             : 
    1371             :       The returned index indicates the starting index of the substring
    1372             :       in this string.
    1373             :       If str doesn't include any character, always -1 is
    1374             :       returned. This is also the case, if both strings are empty.
    1375             : 
    1376             :       @param    str         the substring to search for.
    1377             :       @return   If the string argument occurs one or more times as a substring
    1378             :                 within this string, then the index of the first character of
    1379             :                 the last such substring is returned. If it does not occur as
    1380             :                 a substring, -1 is returned.
    1381             :     */
    1382      216929 :     sal_Int32 lastIndexOf( const OUString & str ) const
    1383             :     {
    1384             :         return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, pData->length,
    1385      216929 :                                                    str.pData->buffer, str.pData->length );
    1386             :     }
    1387             : 
    1388             :     /**
    1389             :       Returns the index within this string of the last occurrence of
    1390             :       the specified substring, searching backward starting before the specified
    1391             :       index.
    1392             : 
    1393             :       The returned index indicates the starting index of the substring
    1394             :       in this string.
    1395             :       If str doesn't include any character, always -1 is
    1396             :       returned. This is also the case, if both strings are empty.
    1397             : 
    1398             :       @param    str         the substring to search for.
    1399             :       @param    fromIndex   the index before which to start the search.
    1400             :       @return   If the string argument occurs one or more times as a substring
    1401             :                 within this string before the starting index, then the index
    1402             :                 of the first character of the last such substring is
    1403             :                 returned. Otherwise, -1 is returned.
    1404             :     */
    1405          10 :     sal_Int32 lastIndexOf( const OUString & str, sal_Int32 fromIndex ) const
    1406             :     {
    1407             :         return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
    1408          10 :                                                    str.pData->buffer, str.pData->length );
    1409             :     }
    1410             : 
    1411             :     /**
    1412             :      @overload
    1413             :      This function accepts an ASCII string literal as its argument.
    1414             :      @since LibreOffice 3.6
    1415             :     */
    1416             :     template< typename T >
    1417        5593 :     typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type lastIndexOf( T& literal ) const
    1418             :     {
    1419             :         assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
    1420             :         return rtl_ustr_lastIndexOfAscii_WithLength(
    1421        5593 :             pData->buffer, pData->length, literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1);
    1422             :     }
    1423             : 
    1424             :     /**
    1425             :        Returns the index within this string of the last occurrence of the
    1426             :        specified ASCII substring.
    1427             : 
    1428             :        @param str
    1429             :        the substring to be searched for.  Need not be null-terminated, but must
    1430             :        be at least as long as the specified len.  Must only contain characters
    1431             :        in the ASCII range 0x00--7F.
    1432             : 
    1433             :        @param len
    1434             :        the length of the substring; must be non-negative.
    1435             : 
    1436             :        @return
    1437             :        the index (starting at 0) of the first character of the last occurrence
    1438             :        of the substring within this string, or -1 if the substring does not
    1439             :        occur.  If len is zero, -1 is returned.
    1440             : 
    1441             :        @since UDK 3.2.7
    1442             :     */
    1443           6 :     sal_Int32 lastIndexOfAsciiL(char const * str, sal_Int32 len) const
    1444             :     {
    1445             :         return rtl_ustr_lastIndexOfAscii_WithLength(
    1446           6 :             pData->buffer, pData->length, str, len);
    1447             :     }
    1448             : 
    1449             :     /**
    1450             :       Returns a new string that is a substring of this string.
    1451             : 
    1452             :       The substring begins at the specified beginIndex. If
    1453             :       beginIndex is negative or be greater than the length of
    1454             :       this string, behaviour is undefined.
    1455             : 
    1456             :       @param     beginIndex   the beginning index, inclusive.
    1457             :       @return    the specified substring.
    1458             :     */
    1459     4445769 :     SAL_WARN_UNUSED_RESULT OUString copy( sal_Int32 beginIndex ) const
    1460             :     {
    1461     4445769 :         rtl_uString *pNew = 0;
    1462     4445769 :         rtl_uString_newFromSubString( &pNew, pData, beginIndex, getLength() - beginIndex );
    1463     4445769 :         return OUString( pNew, SAL_NO_ACQUIRE );
    1464             :     }
    1465             : 
    1466             :     /**
    1467             :       Returns a new string that is a substring of this string.
    1468             : 
    1469             :       The substring begins at the specified beginIndex and contains count
    1470             :       characters.  If either beginIndex or count are negative,
    1471             :       or beginIndex + count are greater than the length of this string
    1472             :       then behaviour is undefined.
    1473             : 
    1474             :       @param     beginIndex   the beginning index, inclusive.
    1475             :       @param     count        the number of characters.
    1476             :       @return    the specified substring.
    1477             :     */
    1478    16276950 :     SAL_WARN_UNUSED_RESULT OUString copy( sal_Int32 beginIndex, sal_Int32 count ) const
    1479             :     {
    1480    16276950 :         rtl_uString *pNew = 0;
    1481    16276950 :         rtl_uString_newFromSubString( &pNew, pData, beginIndex, count );
    1482    16276949 :         return OUString( pNew, SAL_NO_ACQUIRE );
    1483             :     }
    1484             : 
    1485             :     /**
    1486             :       Concatenates the specified string to the end of this string.
    1487             : 
    1488             :       @param    str   the string that is concatenated to the end
    1489             :                       of this string.
    1490             :       @return   a string that represents the concatenation of this string
    1491             :                 followed by the string argument.
    1492             :     */
    1493         540 :     SAL_WARN_UNUSED_RESULT OUString concat( const OUString & str ) const
    1494             :     {
    1495         540 :         rtl_uString* pNew = 0;
    1496         540 :         rtl_uString_newConcat( &pNew, pData, str.pData );
    1497         540 :         return OUString( pNew, SAL_NO_ACQUIRE );
    1498             :     }
    1499             : 
    1500             : #ifndef RTL_FAST_STRING
    1501             :     friend OUString operator+( const OUString& rStr1, const OUString& rStr2  )
    1502             :     {
    1503             :         return rStr1.concat( rStr2 );
    1504             :     }
    1505             : #endif
    1506             : 
    1507             :     /**
    1508             :       Returns a new string resulting from replacing n = count characters
    1509             :       from position index in this string with newStr.
    1510             : 
    1511             :       @param  index   the replacing index in str.
    1512             :                       The index must be greater than or equal to 0 and
    1513             :                       less than or equal to the length of the string.
    1514             :       @param  count   the count of characters that will be replaced
    1515             :                       The count must be greater than or equal to 0 and
    1516             :                       less than or equal to the length of the string minus index.
    1517             :       @param  newStr  the new substring.
    1518             :       @return the new string.
    1519             :     */
    1520     3587901 :     SAL_WARN_UNUSED_RESULT OUString replaceAt( sal_Int32 index, sal_Int32 count, const OUString& newStr ) const
    1521             :     {
    1522     3587901 :         rtl_uString* pNew = 0;
    1523     3587901 :         rtl_uString_newReplaceStrAt( &pNew, pData, index, count, newStr.pData );
    1524     3587901 :         return OUString( pNew, SAL_NO_ACQUIRE );
    1525             :     }
    1526             : 
    1527             :     /**
    1528             :       Returns a new string resulting from replacing all occurrences of
    1529             :       oldChar in this string with newChar.
    1530             : 
    1531             :       If the character oldChar does not occur in the character sequence
    1532             :       represented by this object, then the string is assigned with
    1533             :       str.
    1534             : 
    1535             :       @param    oldChar     the old character.
    1536             :       @param    newChar     the new character.
    1537             :       @return   a string derived from this string by replacing every
    1538             :                 occurrence of oldChar with newChar.
    1539             :     */
    1540      198458 :     SAL_WARN_UNUSED_RESULT OUString replace( sal_Unicode oldChar, sal_Unicode newChar ) const
    1541             :     {
    1542      198458 :         rtl_uString* pNew = 0;
    1543      198458 :         rtl_uString_newReplace( &pNew, pData, oldChar, newChar );
    1544      198458 :         return OUString( pNew, SAL_NO_ACQUIRE );
    1545             :     }
    1546             : 
    1547             :     /**
    1548             :       Returns a new string resulting from replacing the first occurrence of a
    1549             :       given substring with another substring.
    1550             : 
    1551             :       @param from  the substring to be replaced
    1552             : 
    1553             :       @param to  the replacing substring
    1554             : 
    1555             :       @param[in,out] index  pointer to a start index; if the pointer is
    1556             :       non-null: upon entry to the function, its value is the index into this
    1557             :       string at which to start searching for the \p from substring, the value
    1558             :       must be non-negative and not greater than this string's length; upon exiting
    1559             :       the function its value is the index into this string at which the
    1560             :       replacement took place or -1 if no replacement took place; if the pointer
    1561             :       is null, searching always starts at index 0
    1562             : 
    1563             :       @since LibreOffice 3.6
    1564             :     */
    1565        2968 :     SAL_WARN_UNUSED_RESULT OUString replaceFirst(
    1566             :         OUString const & from, OUString const & to, sal_Int32 * index = 0) const
    1567             :     {
    1568        2968 :         rtl_uString * s = 0;
    1569        2968 :         sal_Int32 i = 0;
    1570             :         rtl_uString_newReplaceFirst(
    1571        2968 :             &s, pData, from.pData, to.pData, index == 0 ? &i : index);
    1572        2968 :         return OUString(s, SAL_NO_ACQUIRE);
    1573             :     }
    1574             : 
    1575             :     /**
    1576             :       Returns a new string resulting from replacing the first occurrence of a
    1577             :       given substring with another substring.
    1578             : 
    1579             :       @param from  ASCII string literal, the substring to be replaced
    1580             : 
    1581             :       @param to  the replacing substring
    1582             : 
    1583             :       @param[in,out] index  pointer to a start index; if the pointer is
    1584             :       non-null: upon entry to the function, its value is the index into the this
    1585             :       string at which to start searching for the \p from substring, the value
    1586             :       must be non-negative and not greater than this string's length; upon exiting
    1587             :       the function its value is the index into this string at which the
    1588             :       replacement took place or -1 if no replacement took place; if the pointer
    1589             :       is null, searching always starts at index 0
    1590             : 
    1591             :       @since LibreOffice 3.6
    1592             :     */
    1593             :     template< typename T >
    1594       27389 :     SAL_WARN_UNUSED_RESULT typename libreoffice_internal::ConstCharArrayDetector< T, OUString >::Type replaceFirst( T& from, OUString const & to,
    1595             :                                                                                                         sal_Int32 * index = 0) const
    1596             :     {
    1597       27389 :         rtl_uString * s = 0;
    1598       27389 :         sal_Int32 i = 0;
    1599             :         assert( strlen( from ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
    1600       27389 :         rtl_uString_newReplaceFirstAsciiL(
    1601       27389 :             &s, pData, from, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1, to.pData, index == 0 ? &i : index);
    1602       27389 :         return OUString(s, SAL_NO_ACQUIRE);
    1603             :     }
    1604             : 
    1605             :     /**
    1606             :       Returns a new string resulting from replacing the first occurrence of a
    1607             :       given substring with another substring.
    1608             : 
    1609             :       @param from  ASCII string literal, the substring to be replaced
    1610             : 
    1611             :       @param to  ASCII string literal, the substring to be replaced
    1612             : 
    1613             :       @param[in,out] index  pointer to a start index; if the pointer is
    1614             :       non-null: upon entry to the function, its value is the index into the this
    1615             :       string at which to start searching for the \p from substring, the value
    1616             :       must be non-negative and not greater than this string's length; upon exiting
    1617             :       the function its value is the index into this string at which the
    1618             :       replacement took place or -1 if no replacement took place; if the pointer
    1619             :       is null, searching always starts at index 0
    1620             : 
    1621             :       @since LibreOffice 3.6
    1622             :     */
    1623             :     template< typename T1, typename T2 >
    1624             :         SAL_WARN_UNUSED_RESULT typename libreoffice_internal::ConstCharArrayDetector< T1, typename libreoffice_internal::ConstCharArrayDetector< T2, OUString >::Type >::Type
    1625        1244 :         replaceFirst( T1& from, T2& to, sal_Int32 * index = 0) const
    1626             :     {
    1627        1244 :         rtl_uString * s = 0;
    1628        1244 :         sal_Int32 i = 0;
    1629             :         assert( strlen( from ) == libreoffice_internal::ConstCharArrayDetector< T1 >::size - 1 );
    1630             :         assert( strlen( to ) == libreoffice_internal::ConstCharArrayDetector< T2 >::size - 1 );
    1631        1244 :         rtl_uString_newReplaceFirstAsciiLAsciiL(
    1632             :             &s, pData, from, libreoffice_internal::ConstCharArrayDetector< T1, void >::size - 1, to,
    1633        1244 :             libreoffice_internal::ConstCharArrayDetector< T2, void >::size - 1, index == 0 ? &i : index);
    1634        1244 :         return OUString(s, SAL_NO_ACQUIRE);
    1635             :     }
    1636             : 
    1637             :     /**
    1638             :       Returns a new string resulting from replacing all occurrences of a given
    1639             :       substring with another substring.
    1640             : 
    1641             :       Replacing subsequent occurrences picks up only after a given replacement.
    1642             :       That is, replacing from "xa" to "xx" in "xaa" results in "xxa", not "xxx".
    1643             : 
    1644             :       @param from  the substring to be replaced
    1645             : 
    1646             :       @param to  the replacing substring
    1647             : 
    1648             :       @param fromIndex  the position in the string where we will begin searching
    1649             : 
    1650             :       @since LibreOffice 4.0
    1651             :     */
    1652      247078 :     SAL_WARN_UNUSED_RESULT OUString replaceAll(
    1653             :         OUString const & from, OUString const & to, sal_Int32 fromIndex = 0) const
    1654             :     {
    1655      247078 :         rtl_uString * s = 0;
    1656      247078 :         rtl_uString_newReplaceAllFromIndex(&s, pData, from.pData, to.pData, fromIndex);
    1657      247078 :         return OUString(s, SAL_NO_ACQUIRE);
    1658             :     }
    1659             : 
    1660             :     /**
    1661             :       Returns a new string resulting from replacing all occurrences of a given
    1662             :       substring with another substring.
    1663             : 
    1664             :       Replacing subsequent occurrences picks up only after a given replacement.
    1665             :       That is, replacing from "xa" to "xx" in "xaa" results in "xxa", not "xxx".
    1666             : 
    1667             :       @param from ASCII string literal, the substring to be replaced
    1668             : 
    1669             :       @param to  the replacing substring
    1670             : 
    1671             :       @since LibreOffice 3.6
    1672             :     */
    1673             :     template< typename T >
    1674       24656 :     SAL_WARN_UNUSED_RESULT typename libreoffice_internal::ConstCharArrayDetector< T, OUString >::Type replaceAll( T& from, OUString const & to) const
    1675             :     {
    1676       24656 :         rtl_uString * s = 0;
    1677             :         assert( strlen( from ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
    1678       24656 :         rtl_uString_newReplaceAllAsciiL(&s, pData, from, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1, to.pData);
    1679       24656 :         return OUString(s, SAL_NO_ACQUIRE);
    1680             :     }
    1681             : 
    1682             :     /**
    1683             :       Returns a new string resulting from replacing all occurrences of a given
    1684             :       substring with another substring.
    1685             : 
    1686             :       Replacing subsequent occurrences picks up only after a given replacement.
    1687             :       That is, replacing from "xa" to "xx" in "xaa" results in "xxa", not "xxx".
    1688             : 
    1689             :       @param from  ASCII string literal, the substring to be replaced
    1690             : 
    1691             :       @param to  ASCII string literal, the substring to be replaced
    1692             : 
    1693             :       @since LibreOffice 3.6
    1694             :     */
    1695             :     template< typename T1, typename T2 >
    1696             :     SAL_WARN_UNUSED_RESULT typename libreoffice_internal::ConstCharArrayDetector< T1, typename libreoffice_internal::ConstCharArrayDetector< T2, OUString >::Type >::Type
    1697       18204 :         replaceAll( T1& from, T2& to ) const
    1698             :     {
    1699       18204 :         rtl_uString * s = 0;
    1700             :         assert( strlen( from ) == libreoffice_internal::ConstCharArrayDetector< T1 >::size - 1 );
    1701             :         assert( strlen( to ) == libreoffice_internal::ConstCharArrayDetector< T2 >::size - 1 );
    1702       18204 :         rtl_uString_newReplaceAllAsciiLAsciiL(
    1703             :             &s, pData, from, libreoffice_internal::ConstCharArrayDetector< T1, void >::size - 1,
    1704       18204 :             to, libreoffice_internal::ConstCharArrayDetector< T2, void >::size - 1);
    1705       18204 :         return OUString(s, SAL_NO_ACQUIRE);
    1706             :     }
    1707             : 
    1708             :     /**
    1709             :       Converts from this string all ASCII uppercase characters (65-90)
    1710             :       to ASCII lowercase characters (97-122).
    1711             : 
    1712             :       This function can't be used for language specific conversion.
    1713             :       If the string doesn't contain characters which must be converted,
    1714             :       then the new string is assigned with str.
    1715             : 
    1716             :       @return   the string, converted to ASCII lowercase.
    1717             :     */
    1718     4318714 :     SAL_WARN_UNUSED_RESULT OUString toAsciiLowerCase() const
    1719             :     {
    1720     4318714 :         rtl_uString* pNew = 0;
    1721     4318714 :         rtl_uString_newToAsciiLowerCase( &pNew, pData );
    1722     4318714 :         return OUString( pNew, SAL_NO_ACQUIRE );
    1723             :     }
    1724             : 
    1725             :     /**
    1726             :       Converts from this string all ASCII lowercase characters (97-122)
    1727             :       to ASCII uppercase characters (65-90).
    1728             : 
    1729             :       This function can't be used for language specific conversion.
    1730             :       If the string doesn't contain characters which must be converted,
    1731             :       then the new string is assigned with str.
    1732             : 
    1733             :       @return   the string, converted to ASCII uppercase.
    1734             :     */
    1735     1043014 :     SAL_WARN_UNUSED_RESULT OUString toAsciiUpperCase() const
    1736             :     {
    1737     1043014 :         rtl_uString* pNew = 0;
    1738     1043014 :         rtl_uString_newToAsciiUpperCase( &pNew, pData );
    1739     1043014 :         return OUString( pNew, SAL_NO_ACQUIRE );
    1740             :     }
    1741             : 
    1742             :     /**
    1743             :       Returns a new string resulting from removing white space from both ends
    1744             :       of the string.
    1745             : 
    1746             :       All characters that have codes less than or equal to
    1747             :       32 (the space character) are considered to be white space.
    1748             :       If the string doesn't contain white spaces at both ends,
    1749             :       then the new string is assigned with str.
    1750             : 
    1751             :       @return   the string, with white space removed from the front and end.
    1752             :     */
    1753      366344 :     SAL_WARN_UNUSED_RESULT OUString trim() const
    1754             :     {
    1755      366344 :         rtl_uString* pNew = 0;
    1756      366344 :         rtl_uString_newTrim( &pNew, pData );
    1757      366344 :         return OUString( pNew, SAL_NO_ACQUIRE );
    1758             :     }
    1759             : 
    1760             :     /**
    1761             :       Returns a token in the string.
    1762             : 
    1763             :       Example:
    1764             :         sal_Int32 nIndex = 0;
    1765             :         do
    1766             :         {
    1767             :             ...
    1768             :             OUString aToken = aStr.getToken( 0, ';', nIndex );
    1769             :             ...
    1770             :         }
    1771             :         while ( nIndex >= 0 );
    1772             : 
    1773             :       @param    token       the number of the token to return
    1774             :       @param    cTok        the character which separate the tokens.
    1775             :       @param    index       the position at which the token is searched in the
    1776             :                             string.
    1777             :                             The index must not be greater than the length of the
    1778             :                             string.
    1779             :                             This param is set to the position of the
    1780             :                             next token or to -1, if it is the last token.
    1781             :       @return   the token; if either token or index is negative, an empty token
    1782             :                 is returned (and index is set to -1)
    1783             :     */
    1784     6096580 :     OUString getToken( sal_Int32 token, sal_Unicode cTok, sal_Int32& index ) const
    1785             :     {
    1786     6096580 :         rtl_uString * pNew = 0;
    1787     6096580 :         index = rtl_uString_getToken( &pNew, pData, token, cTok, index );
    1788     6096580 :         return OUString( pNew, SAL_NO_ACQUIRE );
    1789             :     }
    1790             : 
    1791             :     /**
    1792             :       Returns a token from the string.
    1793             : 
    1794             :       The same as getToken(sal_Int32, sal_Unicode, sal_Int32 &), but always
    1795             :       passing in 0 as the start index in the third argument.
    1796             : 
    1797             :       @param count  the number of the token to return, starting with 0
    1798             :       @param separator  the character which separates the tokens
    1799             : 
    1800             :       @return  the given token, or an empty string
    1801             : 
    1802             :       @since LibreOffice 3.6
    1803             :      */
    1804      210099 :     OUString getToken(sal_Int32 count, sal_Unicode separator) const {
    1805      210099 :         sal_Int32 n = 0;
    1806      210099 :         return getToken(count, separator, n);
    1807             :     }
    1808             : 
    1809             :     /**
    1810             :       Returns the Boolean value from this string.
    1811             : 
    1812             :       This function can't be used for language specific conversion.
    1813             : 
    1814             :       @return   true, if the string is 1 or "True" in any ASCII case.
    1815             :                 false in any other case.
    1816             :     */
    1817       10834 :     bool toBoolean() const
    1818             :     {
    1819       10834 :         return rtl_ustr_toBoolean( pData->buffer );
    1820             :     }
    1821             : 
    1822             :     /**
    1823             :       Returns the first character from this string.
    1824             : 
    1825             :       @return   the first character from this string or 0, if this string
    1826             :                 is emptry.
    1827             :     */
    1828      270614 :     sal_Unicode toChar() const
    1829             :     {
    1830      270614 :         return pData->buffer[0];
    1831             :     }
    1832             : 
    1833             :     /**
    1834             :       Returns the int32 value from this string.
    1835             : 
    1836             :       This function can't be used for language specific conversion.
    1837             : 
    1838             :       @param    radix       the radix (between 2 and 36)
    1839             :       @return   the int32 represented from this string.
    1840             :                 0 if this string represents no number or one of too large
    1841             :                 magnitude.
    1842             :     */
    1843     1094161 :     sal_Int32 toInt32( sal_Int16 radix = 10 ) const
    1844             :     {
    1845     1094161 :         return rtl_ustr_toInt32( pData->buffer, radix );
    1846             :     }
    1847             : 
    1848             :     /**
    1849             :       Returns the uint32 value from this string.
    1850             : 
    1851             :       This function can't be used for language specific conversion.
    1852             : 
    1853             :       @param    radix       the radix (between 2 and 36)
    1854             :       @return   the uint32 represented from this string.
    1855             :                 0 if this string represents no number or one of too large
    1856             :                 magnitude.
    1857             : 
    1858             :       @since LibreOffice 4.2
    1859             :     */
    1860       48408 :     sal_uInt32 toUInt32( sal_Int16 radix = 10 ) const
    1861             :     {
    1862       48408 :         return rtl_ustr_toUInt32( pData->buffer, radix );
    1863             :     }
    1864             : 
    1865             :     /**
    1866             :       Returns the int64 value from this string.
    1867             : 
    1868             :       This function can't be used for language specific conversion.
    1869             : 
    1870             :       @param    radix       the radix (between 2 and 36)
    1871             :       @return   the int64 represented from this string.
    1872             :                 0 if this string represents no number or one of too large
    1873             :                 magnitude.
    1874             :     */
    1875      202431 :     sal_Int64 toInt64( sal_Int16 radix = 10 ) const
    1876             :     {
    1877      202431 :         return rtl_ustr_toInt64( pData->buffer, radix );
    1878             :     }
    1879             : 
    1880             :     /**
    1881             :       Returns the uint64 value from this string.
    1882             : 
    1883             :       This function can't be used for language specific conversion.
    1884             : 
    1885             :       @param    radix       the radix (between 2 and 36)
    1886             :       @return   the uint64 represented from this string.
    1887             :                 0 if this string represents no number or one of too large
    1888             :                 magnitude.
    1889             : 
    1890             :       @since LibreOffice 4.1
    1891             :     */
    1892           6 :     sal_uInt64 toUInt64( sal_Int16 radix = 10 ) const
    1893             :     {
    1894           6 :         return rtl_ustr_toUInt64( pData->buffer, radix );
    1895             :     }
    1896             : 
    1897             :     /**
    1898             :       Returns the float value from this string.
    1899             : 
    1900             :       This function can't be used for language specific conversion.
    1901             : 
    1902             :       @return   the float represented from this string.
    1903             :                 0.0 if this string represents no number.
    1904             :     */
    1905         232 :     float toFloat() const
    1906             :     {
    1907         232 :         return rtl_ustr_toFloat( pData->buffer );
    1908             :     }
    1909             : 
    1910             :     /**
    1911             :       Returns the double value from this string.
    1912             : 
    1913             :       This function can't be used for language specific conversion.
    1914             : 
    1915             :       @return   the double represented from this string.
    1916             :                 0.0 if this string represents no number.
    1917             :     */
    1918       42946 :     double toDouble() const
    1919             :     {
    1920       42946 :         return rtl_ustr_toDouble( pData->buffer );
    1921             :     }
    1922             : 
    1923             : 
    1924             :     /**
    1925             :        Return a canonical representation for a string.
    1926             : 
    1927             :        A pool of strings, initially empty is maintained privately
    1928             :        by the string class. On invocation, if present in the pool
    1929             :        the original string will be returned. Otherwise this string,
    1930             :        or a copy thereof will be added to the pool and returned.
    1931             : 
    1932             :        @return
    1933             :        a version of the string from the pool.
    1934             : 
    1935             :        @exception std::bad_alloc is thrown if an out-of-memory condition occurs
    1936             : 
    1937             :        @since UDK 3.2.7
    1938             :     */
    1939       83203 :     OUString intern() const
    1940             :     {
    1941       83203 :         rtl_uString * pNew = 0;
    1942       83203 :         rtl_uString_intern( &pNew, pData );
    1943       83203 :         if (pNew == 0) {
    1944           0 :             throw std::bad_alloc();
    1945             :         }
    1946       83203 :         return OUString( pNew, SAL_NO_ACQUIRE );
    1947             :     }
    1948             : 
    1949             :     /**
    1950             :        Return a canonical representation for a converted string.
    1951             : 
    1952             :        A pool of strings, initially empty is maintained privately
    1953             :        by the string class. On invocation, if present in the pool
    1954             :        the original string will be returned. Otherwise this string,
    1955             :        or a copy thereof will be added to the pool and returned.
    1956             : 
    1957             :        @param    value           a 8-Bit character array.
    1958             :        @param    length          the number of character which should be converted.
    1959             :                                  The 8-Bit character array length must be
    1960             :                                  greater than or equal to this value.
    1961             :        @param    encoding        the text encoding from which the 8-Bit character
    1962             :                                  sequence should be converted.
    1963             :        @param    convertFlags    flags which controls the conversion.
    1964             :                                  see RTL_TEXTTOUNICODE_FLAGS_...
    1965             :        @param    pInfo           pointer to return conversion status or NULL.
    1966             : 
    1967             :        @return
    1968             :        a version of the converted string from the pool.
    1969             : 
    1970             :        @exception std::bad_alloc is thrown if an out-of-memory condition occurs
    1971             : 
    1972             :        @since UDK 3.2.7
    1973             :     */
    1974     1171567 :     static OUString intern( const sal_Char * value, sal_Int32 length,
    1975             :                             rtl_TextEncoding encoding,
    1976             :                             sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS,
    1977             :                             sal_uInt32 *pInfo = NULL )
    1978             :     {
    1979     1171567 :         rtl_uString * pNew = 0;
    1980             :         rtl_uString_internConvert( &pNew, value, length, encoding,
    1981     1171567 :                                    convertFlags, pInfo );
    1982     1171567 :         if (pNew == 0) {
    1983           0 :             throw std::bad_alloc();
    1984             :         }
    1985     1171567 :         return OUString( pNew, SAL_NO_ACQUIRE );
    1986             :     }
    1987             : 
    1988             :     /**
    1989             :       Converts to an OString, signalling failure.
    1990             : 
    1991             :       @param pTarget
    1992             :       An out parameter receiving the converted OString.  Must not be null; the
    1993             :       contents are not modified if conversion fails (convertToOString returns
    1994             :       false).
    1995             : 
    1996             :       @param nEncoding
    1997             :       The text encoding to convert into.  Must be an octet encoding (i.e.,
    1998             :       rtl_isOctetTextEncoding(nEncoding) must return true).
    1999             : 
    2000             :       @param nFlags
    2001             :       A combination of RTL_UNICODETOTEXT_FLAGS that detail how to do the
    2002             :       conversion (see rtl_convertUnicodeToText).  RTL_UNICODETOTEXT_FLAGS_FLUSH
    2003             :       need not be included, it is implicitly assumed.  Typical uses are either
    2004             :       RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
    2005             :       RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR (fail if a Unicode character cannot
    2006             :       be converted to the target nEncoding) or OUSTRING_TO_OSTRING_CVTFLAGS
    2007             :       (make a best efforts conversion).
    2008             : 
    2009             :       @return
    2010             :       True if the conversion succeeded, false otherwise.
    2011             :      */
    2012      393919 :     inline bool convertToString(OString * pTarget, rtl_TextEncoding nEncoding,
    2013             :                                 sal_uInt32 nFlags) const
    2014             :     {
    2015             :         return rtl_convertUStringToString(&pTarget->pData, pData->buffer,
    2016      393919 :                                             pData->length, nEncoding, nFlags);
    2017             :     }
    2018             : 
    2019             :     /** Iterate through this string based on code points instead of UTF-16 code
    2020             :         units.
    2021             : 
    2022             :         See Chapter 3 of The Unicode Standard 5.0 (Addison--Wesley, 2006) for
    2023             :         definitions of the various terms used in this description.
    2024             : 
    2025             :         This string is interpreted as a sequence of zero or more UTF-16 code
    2026             :         units.  For each index into this sequence (from zero to one less than
    2027             :         the length of the sequence, inclusive), a code point represented
    2028             :         starting at the given index is computed as follows:
    2029             : 
    2030             :         - If the UTF-16 code unit addressed by the index constitutes a
    2031             :         well-formed UTF-16 code unit sequence, the computed code point is the
    2032             :         scalar value encoded by that UTF-16 code unit sequence.
    2033             : 
    2034             :         - Otherwise, if the index is at least two UTF-16 code units away from
    2035             :         the end of the sequence, and the sequence of two UTF-16 code units
    2036             :         addressed by the index constitutes a well-formed UTF-16 code unit
    2037             :         sequence, the computed code point is the scalar value encoded by that
    2038             :         UTF-16 code unit sequence.
    2039             : 
    2040             :         - Otherwise, the computed code point is the UTF-16 code unit addressed
    2041             :         by the index.  (This last case catches unmatched surrogates as well as
    2042             :         indices pointing into the middle of surrogate pairs.)
    2043             : 
    2044             :         @param indexUtf16
    2045             :         pointer to a UTF-16 based index into this string; must not be null.  On
    2046             :         entry, the index must be in the range from zero to the length of this
    2047             :         string (in UTF-16 code units), inclusive.  Upon successful return, the
    2048             :         index will be updated to address the UTF-16 code unit that is the given
    2049             :         incrementCodePoints away from the initial index.
    2050             : 
    2051             :         @param incrementCodePoints
    2052             :         the number of code points to move the given *indexUtf16.  If
    2053             :         non-negative, moving is done after determining the code point at the
    2054             :         index.  If negative, moving is done before determining the code point
    2055             :         at the (then updated) index.  The value must be such that the resulting
    2056             :         UTF-16 based index is in the range from zero to the length of this
    2057             :         string (in UTF-16 code units), inclusive.
    2058             : 
    2059             :         @return
    2060             :         the code point (an integer in the range from 0 to 0x10FFFF, inclusive)
    2061             :         that is represented within this string starting at the index computed as
    2062             :         follows:  If incrementCodePoints is non-negative, the index is the
    2063             :         initial value of *indexUtf16; if incrementCodePoints is negative, the
    2064             :         index is the updated value of *indexUtf16.  In either case, the computed
    2065             :         index must be in the range from zero to one less than the length of this
    2066             :         string (in UTF-16 code units), inclusive.
    2067             : 
    2068             :         @since UDK 3.2.7
    2069             :     */
    2070    26731358 :     inline sal_uInt32 iterateCodePoints(
    2071             :         sal_Int32 * indexUtf16, sal_Int32 incrementCodePoints = 1) const
    2072             :     {
    2073             :         return rtl_uString_iterateCodePoints(
    2074    26731358 :             pData, indexUtf16, incrementCodePoints);
    2075             :     }
    2076             : 
    2077             :     /**
    2078             :       Returns the string representation of the integer argument.
    2079             : 
    2080             :       This function can't be used for language specific conversion.
    2081             : 
    2082             :       @param    i           an integer value
    2083             :       @param    radix       the radix (between 2 and 36)
    2084             :       @return   a string with the string representation of the argument.
    2085             :       @since LibreOffice 4.1
    2086             :     */
    2087     1637691 :     static OUString number( int i, sal_Int16 radix = 10 )
    2088             :     {
    2089             :         sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFINT32];
    2090     1637691 :         rtl_uString* pNewData = 0;
    2091     1637691 :         rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfInt32( aBuf, i, radix ) );
    2092     1637691 :         return OUString( pNewData, SAL_NO_ACQUIRE );
    2093             :     }
    2094             :     /// @overload
    2095             :     /// @since LibreOffice 4.1
    2096       45432 :     static OUString number( unsigned int i, sal_Int16 radix = 10 )
    2097             :     {
    2098       45432 :         return number( static_cast< unsigned long long >( i ), radix );
    2099             :     }
    2100             :     /// @overload
    2101             :     /// @since LibreOffice 4.1
    2102      534398 :     static OUString number( long i, sal_Int16 radix = 10)
    2103             :     {
    2104      534398 :         return number( static_cast< long long >( i ), radix );
    2105             :     }
    2106             :     /// @overload
    2107             :     /// @since LibreOffice 4.1
    2108       19990 :     static OUString number( unsigned long i, sal_Int16 radix = 10 )
    2109             :     {
    2110       19990 :         return number( static_cast< unsigned long long >( i ), radix );
    2111             :     }
    2112             :     /// @overload
    2113             :     /// @since LibreOffice 4.1
    2114      534400 :     static OUString number( long long ll, sal_Int16 radix = 10 )
    2115             :     {
    2116             :         sal_Unicode aBuf[RTL_STR_MAX_VALUEOFINT64];
    2117      534400 :         rtl_uString* pNewData = 0;
    2118      534400 :         rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfInt64( aBuf, ll, radix ) );
    2119      534400 :         return OUString( pNewData, SAL_NO_ACQUIRE );
    2120             :     }
    2121             :     /// @overload
    2122             :     /// @since LibreOffice 4.1
    2123       65424 :     static OUString number( unsigned long long ll, sal_Int16 radix = 10 )
    2124             :     {
    2125             :         sal_Unicode aBuf[RTL_STR_MAX_VALUEOFUINT64];
    2126       65424 :         rtl_uString* pNewData = 0;
    2127       65424 :         rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfUInt64( aBuf, ll, radix ) );
    2128       65424 :         return OUString( pNewData, SAL_NO_ACQUIRE );
    2129             :     }
    2130             : 
    2131             :     /**
    2132             :       Returns the string representation of the float argument.
    2133             : 
    2134             :       This function can't be used for language specific conversion.
    2135             : 
    2136             :       @param    f           a float.
    2137             :       @return   a string with the string representation of the argument.
    2138             :       @since LibreOffice 4.1
    2139             :     */
    2140          82 :     static OUString number( float f )
    2141             :     {
    2142             :         sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFFLOAT];
    2143          82 :         rtl_uString* pNewData = 0;
    2144          82 :         rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfFloat( aBuf, f ) );
    2145          82 :         return OUString( pNewData, SAL_NO_ACQUIRE );
    2146             :     }
    2147             : 
    2148             :     /**
    2149             :       Returns the string representation of the double argument.
    2150             : 
    2151             :       This function can't be used for language specific conversion.
    2152             : 
    2153             :       @param    d           a double.
    2154             :       @return   a string with the string representation of the argument.
    2155             :       @since LibreOffice 4.1
    2156             :     */
    2157      189361 :     static OUString number( double d )
    2158             :     {
    2159             :         sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFDOUBLE];
    2160      189361 :         rtl_uString* pNewData = 0;
    2161      189361 :         rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfDouble( aBuf, d ) );
    2162      189361 :         return OUString( pNewData, SAL_NO_ACQUIRE );
    2163             :     }
    2164             : 
    2165             :     /**
    2166             :       Returns the string representation of the sal_Bool argument.
    2167             : 
    2168             :       If the sal_Bool is true, the string "true" is returned.
    2169             :       If the sal_Bool is false, the string "false" is returned.
    2170             :       This function can't be used for language specific conversion.
    2171             : 
    2172             :       @param    b   a sal_Bool.
    2173             :       @return   a string with the string representation of the argument.
    2174             :       @deprecated use boolean()
    2175             :     */
    2176             :     SAL_DEPRECATED("use boolean()") static OUString valueOf( sal_Bool b )
    2177             :     {
    2178             :         return boolean(b);
    2179             :     }
    2180             : 
    2181             :     /**
    2182             :       Returns the string representation of the boolean argument.
    2183             : 
    2184             :       If the argument is true, the string "true" is returned.
    2185             :       If the argument is false, the string "false" is returned.
    2186             :       This function can't be used for language specific conversion.
    2187             : 
    2188             :       @param    b   a bool.
    2189             :       @return   a string with the string representation of the argument.
    2190             :       @since LibreOffice 4.1
    2191             :     */
    2192          54 :     static OUString boolean( bool b )
    2193             :     {
    2194             :         sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFBOOLEAN];
    2195          54 :         rtl_uString* pNewData = 0;
    2196          54 :         rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfBoolean( aBuf, b ) );
    2197          54 :         return OUString( pNewData, SAL_NO_ACQUIRE );
    2198             :     }
    2199             : 
    2200             :     /**
    2201             :       Returns the string representation of the char argument.
    2202             : 
    2203             :       @param    c   a character.
    2204             :       @return   a string with the string representation of the argument.
    2205             :       @deprecated use operator, function or constructor taking char or sal_Unicode argument
    2206             :     */
    2207             :     SAL_DEPRECATED("convert to OUString or use directly") static OUString valueOf( sal_Unicode c )
    2208             :     {
    2209             :         return OUString( &c, 1 );
    2210             :     }
    2211             : 
    2212             :     /**
    2213             :       Returns the string representation of the int argument.
    2214             : 
    2215             :       This function can't be used for language specific conversion.
    2216             : 
    2217             :       @param    i           a int32.
    2218             :       @param    radix       the radix (between 2 and 36)
    2219             :       @return   a string with the string representation of the argument.
    2220             :       @deprecated use number()
    2221             :     */
    2222             :     SAL_DEPRECATED("use number()") static OUString valueOf( sal_Int32 i, sal_Int16 radix = 10 )
    2223             :     {
    2224             :         return number( i, radix );
    2225             :     }
    2226             : 
    2227             :     /**
    2228             :       Returns the string representation of the long argument.
    2229             : 
    2230             :       This function can't be used for language specific conversion.
    2231             : 
    2232             :       @param    ll          a int64.
    2233             :       @param    radix       the radix (between 2 and 36)
    2234             :       @return   a string with the string representation of the argument.
    2235             :       @deprecated use number()
    2236             :     */
    2237             :     SAL_DEPRECATED("use number()") static OUString valueOf( sal_Int64 ll, sal_Int16 radix = 10 )
    2238             :     {
    2239             :         return number( ll, radix );
    2240             :     }
    2241             : 
    2242             :     /**
    2243             :       Returns the string representation of the float argument.
    2244             : 
    2245             :       This function can't be used for language specific conversion.
    2246             : 
    2247             :       @param    f           a float.
    2248             :       @return   a string with the string representation of the argument.
    2249             :       @deprecated use number()
    2250             :     */
    2251             :     SAL_DEPRECATED("use number()") static OUString valueOf( float f )
    2252             :     {
    2253             :         return number(f);
    2254             :     }
    2255             : 
    2256             :     /**
    2257             :       Returns the string representation of the double argument.
    2258             : 
    2259             :       This function can't be used for language specific conversion.
    2260             : 
    2261             :       @param    d           a double.
    2262             :       @return   a string with the string representation of the argument.
    2263             :       @deprecated use number()
    2264             :     */
    2265             :     SAL_DEPRECATED("use number()") static OUString valueOf( double d )
    2266             :     {
    2267             :         return number(d);
    2268             :     }
    2269             : 
    2270             :     /**
    2271             :       Returns a OUString copied without conversion from an ASCII
    2272             :       character string.
    2273             : 
    2274             :       Since this method is optimized for performance, the ASCII character
    2275             :       values are not converted in any way. The caller has to make sure that
    2276             :       all ASCII characters are in the allowed range between 0 and
    2277             :       127. The ASCII string must be NULL-terminated.
    2278             : 
    2279             :       Note that for string literals it is simpler and more efficient
    2280             :       to directly use the OUString constructor.
    2281             : 
    2282             :       @param    value       the 8-Bit ASCII character string
    2283             :       @return   a string with the string representation of the argument.
    2284             :      */
    2285    21800767 :     static OUString createFromAscii( const sal_Char * value )
    2286             :     {
    2287    21800767 :         rtl_uString* pNew = 0;
    2288    21800767 :         rtl_uString_newFromAscii( &pNew, value );
    2289    21800767 :         return OUString( pNew, SAL_NO_ACQUIRE );
    2290             :     }
    2291             : };
    2292             : 
    2293             : /* ======================================================================= */
    2294             : 
    2295             : #ifdef RTL_FAST_STRING
    2296             : /**
    2297             : A simple wrapper around string literal. It is usually not necessary to use, can
    2298             : be mostly used to force OUString operator+ working with operands that otherwise would
    2299             : not trigger it.
    2300             : 
    2301             : This class is not part of public API and is meant to be used only in LibreOffice code.
    2302             : @since LibreOffice 4.0
    2303             : */
    2304             : struct SAL_WARN_UNUSED OUStringLiteral
    2305             : {
    2306             :     template< int N >
    2307           8 :     OUStringLiteral( const char (&str)[ N ] ) : size( N - 1 ), data( str ) { assert( strlen( str ) == N - 1 ); }
    2308             :     int size;
    2309             :     const char* data;
    2310             : };
    2311             : 
    2312             : /**
    2313             :  @internal
    2314             : */
    2315             : template<>
    2316             : struct ToStringHelper< OUString >
    2317             :     {
    2318    17351979 :     static int length( const OUString& s ) { return s.getLength(); }
    2319    17350685 :     static sal_Unicode* addData( sal_Unicode* buffer, const OUString& s ) { return addDataHelper( buffer, s.getStr(), s.getLength()); }
    2320             :     static const bool allowOStringConcat = false;
    2321             :     static const bool allowOUStringConcat = true;
    2322             :     };
    2323             : 
    2324             : /**
    2325             :  @internal
    2326             : */
    2327             : template<>
    2328             : struct ToStringHelper< OUStringLiteral >
    2329             :     {
    2330           6 :     static int length( const OUStringLiteral& str ) { return str.size; }
    2331           6 :     static sal_Unicode* addData( sal_Unicode* buffer, const OUStringLiteral& str ) { return addDataLiteral( buffer, str.data, str.size ); }
    2332             :     static const bool allowOStringConcat = false;
    2333             :     static const bool allowOUStringConcat = true;
    2334             :     };
    2335             : 
    2336             : /**
    2337             :  @internal
    2338             : */
    2339             : template< typename charT, typename traits, typename T1, typename T2 >
    2340             : inline std::basic_ostream<charT, traits> & operator <<(
    2341             :     std::basic_ostream<charT, traits> & stream, const OUStringConcat< T1, T2 >& concat)
    2342             : {
    2343             :     return stream << OUString( concat );
    2344             : }
    2345             : #else
    2346             : // non-RTL_FAST_STRING needs this to compile
    2347             : /// @cond INTERNAL
    2348             : typedef OUString OUStringLiteral;
    2349             : /// @endcond
    2350             : #endif
    2351             : 
    2352             : /** A helper to use OUStrings with hash maps.
    2353             : 
    2354             :     Instances of this class are unary function objects that can be used as
    2355             :     hash function arguments to boost::unordered_map and similar constructs.
    2356             :  */
    2357             : struct OUStringHash
    2358             : {
    2359             :     /** Compute a hash code for a string.
    2360             : 
    2361             :         @param rString
    2362             :         a string.
    2363             : 
    2364             :         @return
    2365             :         a hash code for the string.  This hash code should not be stored
    2366             :         persistently, as its computation may change in later revisions.
    2367             :      */
    2368    87542394 :     size_t operator()(const OUString& rString) const
    2369    87542394 :         { return (size_t)rString.hashCode(); }
    2370             : };
    2371             : 
    2372             : /* ======================================================================= */
    2373             : 
    2374             : /** Convert an OString to an OUString, using a specific text encoding.
    2375             : 
    2376             :     The lengths of the two strings may differ (e.g., for double-byte
    2377             :     encodings, UTF-7, UTF-8).
    2378             : 
    2379             :     @param rStr
    2380             :     an OString to convert.
    2381             : 
    2382             :     @param encoding
    2383             :     the text encoding to use for conversion.
    2384             : 
    2385             :     @param convertFlags
    2386             :     flags which control the conversion.  Either use
    2387             :     OSTRING_TO_OUSTRING_CVTFLAGS, or see
    2388             :     <http://udk.openoffice.org/cpp/man/spec/textconversion.html> for more
    2389             :     details.
    2390             :  */
    2391     2294714 : inline OUString OStringToOUString( const OString & rStr,
    2392             :                                    rtl_TextEncoding encoding,
    2393             :                                    sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS )
    2394             : {
    2395     2294714 :     return OUString( rStr.getStr(), rStr.getLength(), encoding, convertFlags );
    2396             : }
    2397             : 
    2398             : /** Convert an OUString to an OString, using a specific text encoding.
    2399             : 
    2400             :     The lengths of the two strings may differ (e.g., for double-byte
    2401             :     encodings, UTF-7, UTF-8).
    2402             : 
    2403             :     @param rUnicode
    2404             :     an OUString to convert.
    2405             : 
    2406             :     @param encoding
    2407             :     the text encoding to use for conversion.
    2408             : 
    2409             :     @param convertFlags
    2410             :     flags which control the conversion.  Either use
    2411             :     OUSTRING_TO_OSTRING_CVTFLAGS, or see
    2412             :     <http://udk.openoffice.org/cpp/man/spec/textconversion.html> for more
    2413             :     details.
    2414             :  */
    2415    15460171 : inline OString OUStringToOString( const OUString & rUnicode,
    2416             :                                   rtl_TextEncoding encoding,
    2417             :                                   sal_uInt32 convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS )
    2418             : {
    2419    15460171 :     return OString( rUnicode.getStr(), rUnicode.getLength(), encoding, convertFlags );
    2420             : }
    2421             : 
    2422             : /* ======================================================================= */
    2423             : 
    2424             : /**
    2425             :     Support for rtl::OUString in std::ostream (and thus in
    2426             :     CPPUNIT_ASSERT or SAL_INFO macros, for example).
    2427             : 
    2428             :     The rtl::OUString is converted to UTF-8.
    2429             : 
    2430             :     @since LibreOffice 3.5.
    2431             : */
    2432             : template< typename charT, typename traits >
    2433        1282 : inline std::basic_ostream<charT, traits> & operator <<(
    2434             :     std::basic_ostream<charT, traits> & stream, OUString const & string)
    2435             : {
    2436        2564 :     return stream <<
    2437        2564 :         OUStringToOString(string, RTL_TEXTENCODING_UTF8).getStr();
    2438             :         // best effort; potentially loses data due to conversion failures
    2439             :         // (stray surrogate halves) and embedded null characters
    2440             : }
    2441             : 
    2442             : } // namespace
    2443             : 
    2444             : #ifdef RTL_STRING_UNITTEST
    2445             : namespace rtl
    2446             : {
    2447             : typedef rtlunittest::OUString OUString;
    2448             : }
    2449             : #endif
    2450             : 
    2451             : // RTL_USING is defined by gbuild for all modules except those with stable public API
    2452             : // (as listed in ure/source/README). It allows to use classes like OUString without
    2453             : // having to explicitly refer to the rtl namespace, which is kind of superfluous
    2454             : // given that OUString itself is namespaced by its OU prefix.
    2455             : #ifdef RTL_USING
    2456             : using ::rtl::OUString;
    2457             : using ::rtl::OUStringHash;
    2458             : using ::rtl::OStringToOUString;
    2459             : using ::rtl::OUStringToOString;
    2460             : using ::rtl::OUStringLiteral;
    2461             : #endif
    2462             : 
    2463             : #endif /* _RTL_USTRING_HXX */
    2464             : 
    2465             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10