UDK 3.2.7 C/C++ API Reference
rtl/string.hxx
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /*************************************************************************
00003  *
00004  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
00005  *
00006  * Copyright 2000, 2010 Oracle and/or its affiliates.
00007  *
00008  * OpenOffice.org - a multi-platform office productivity suite
00009  *
00010  * This file is part of OpenOffice.org.
00011  *
00012  * OpenOffice.org is free software: you can redistribute it and/or modify
00013  * it under the terms of the GNU Lesser General Public License version 3
00014  * only, as published by the Free Software Foundation.
00015  *
00016  * OpenOffice.org is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU Lesser General Public License version 3 for more details
00020  * (a copy is included in the LICENSE file that accompanied this code).
00021  *
00022  * You should have received a copy of the GNU Lesser General Public License
00023  * version 3 along with OpenOffice.org.  If not, see
00024  * <http://www.openoffice.org/license.html>
00025  * for a copy of the LGPLv3 License.
00026  *
00027  ************************************************************************/
00028 
00029 #ifndef _RTL_STRING_HXX_
00030 #define _RTL_STRING_HXX_
00031 
00032 #include "sal/config.h"
00033 
00034 #include <cassert>
00035 
00036 #include <osl/diagnose.h>
00037 #include <rtl/memory.h>
00038 #include <rtl/textenc.h>
00039 #include <rtl/string.h>
00040 #include <rtl/stringutils.hxx>
00041 
00042 #include "sal/log.hxx"
00043 
00044 #if !defined EXCEPTIONS_OFF
00045 #include <new>
00046 #endif
00047 
00048 // The unittest uses slightly different code to help check that the proper
00049 // calls are made. The class is put into a different namespace to make
00050 // sure the compiler generates a different (if generating also non-inline)
00051 // copy of the function and does not merge them together. The class
00052 // is "brought" into the proper rtl namespace by a typedef below.
00053 #ifdef RTL_STRING_UNITTEST
00054 #define rtl rtlunittest
00055 #endif
00056 
00057 namespace rtl
00058 {
00059 
00060 #ifdef RTL_STRING_UNITTEST
00061 #undef rtl
00062 // helper macro to make functions appear more readable
00063 #define RTL_STRING_CONST_FUNCTION rtl_string_unittest_const_literal_function = true;
00064 #else
00065 #define RTL_STRING_CONST_FUNCTION
00066 #endif
00067 
00068 /* ======================================================================= */
00069 
00094 class OString
00095 {
00096 public:
00098     rtl_String * pData;
00100 
00101 private:
00102     class DO_NOT_ACQUIRE;
00103 
00104     OString( rtl_String * value, SAL_UNUSED_PARAMETER DO_NOT_ACQUIRE * )
00105     {
00106         pData = value;
00107     }
00108 
00109 public:
00113     OString() SAL_THROW(())
00114     {
00115         pData = 0;
00116         rtl_string_new( &pData );
00117     }
00118 
00124     OString( const OString & str ) SAL_THROW(())
00125     {
00126         pData = str.pData;
00127         rtl_string_acquire( pData );
00128     }
00129 
00135     OString( rtl_String * str ) SAL_THROW(())
00136     {
00137         pData = str;
00138         rtl_string_acquire( pData );
00139     }
00140 
00148     inline OString( rtl_String * str, __sal_NoAcquire ) SAL_THROW(())
00149     {
00150         pData = str;
00151     }
00152 
00158     explicit OString( sal_Char value ) SAL_THROW(())
00159         : pData (0)
00160     {
00161         rtl_string_newFromStr_WithLength( &pData, &value, 1 );
00162     }
00163 
00172 #ifdef HAVE_SFINAE_ANONYMOUS_BROKEN
00173     // Old gcc can try to convert anonymous enums to OString and give compile error.
00174     // So there's no special-cased handling of string literals.
00175     // These are inline functions and technically both variants should work
00176     // the same in practice, so there should be no compatibility problem.
00177     OString( const sal_Char * value ) SAL_THROW(())
00178      {
00179          pData = 0;
00180          rtl_string_newFromStr( &pData, value );
00181      }
00182 #else
00183     template< typename T >
00184     OString( const T& value, typename internal::CharPtrDetector< T, internal::Dummy >::Type = internal::Dummy() ) SAL_THROW(())
00185     {
00186         pData = 0;
00187         rtl_string_newFromStr( &pData, value );
00188     }
00189 
00190     template< typename T >
00191     OString( T& value, typename internal::NonConstCharArrayDetector< T, internal::Dummy >::Type = internal::Dummy() ) SAL_THROW(())
00192     {
00193         pData = 0;
00194         rtl_string_newFromStr( &pData, value );
00195     }
00196 
00207     template< typename T >
00208     OString( T& literal, typename internal::ConstCharArrayDetector< T, internal::Dummy >::Type = internal::Dummy() ) SAL_THROW(())
00209     {
00210         pData = 0;
00211         rtl_string_newFromLiteral( &pData, literal, internal::ConstCharArrayDetector< T, void >::size - 1, 0 );
00212 #ifdef RTL_STRING_UNITTEST
00213         rtl_string_unittest_const_literal = true;
00214 #endif
00215     }
00216 
00217 #endif // HAVE_SFINAE_ANONYMOUS_BROKEN
00218 
00227     OString( const sal_Char * value, sal_Int32 length ) SAL_THROW(())
00228     {
00229         pData = 0;
00230         rtl_string_newFromStr_WithLength( &pData, value, length );
00231     }
00232 
00247     OString( const sal_Unicode * value, sal_Int32 length,
00248              rtl_TextEncoding encoding,
00249              sal_uInt32 convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS )
00250     {
00251         pData = 0;
00252         rtl_uString2String( &pData, value, length, encoding, convertFlags );
00253         if (pData == 0) {
00254 #if defined EXCEPTIONS_OFF
00255             abort();
00256 #else
00257             throw std::bad_alloc();
00258 #endif
00259         }
00260     }
00261 
00265     ~OString() SAL_THROW(())
00266     {
00267         rtl_string_release( pData );
00268     }
00269 
00275     OString & operator=( const OString & str ) SAL_THROW(())
00276     {
00277         rtl_string_assign( &pData, str.pData );
00278         return *this;
00279     }
00280 
00286     template< typename T >
00287     typename internal::ConstCharArrayDetector< T, OString& >::Type operator=( T& literal ) SAL_THROW(())
00288     {
00289         RTL_STRING_CONST_FUNCTION
00290         rtl_string_newFromLiteral( &pData, literal, internal::ConstCharArrayDetector< T, void >::size - 1, 0 );
00291         return *this;
00292     }
00293 
00299     OString & operator+=( const OString & str ) SAL_THROW(())
00300     {
00301         rtl_string_newConcat( &pData, pData, str.pData );
00302         return *this;
00303     }
00304 
00313     sal_Int32 getLength() const SAL_THROW(()) { return pData->length; }
00314 
00323     bool isEmpty() const SAL_THROW(())
00324     {
00325         return pData->length == 0;
00326     }
00327 
00339     const sal_Char * getStr() const SAL_THROW(()) { return pData->buffer; }
00340 
00350     sal_Char operator [](sal_Int32 index) const { return getStr()[index]; }
00351 
00364     sal_Int32 compareTo( const OString & str ) const SAL_THROW(())
00365     {
00366         return rtl_str_compare_WithLength( pData->buffer, pData->length,
00367                                            str.pData->buffer, str.pData->length );
00368     }
00369 
00383     sal_Int32 compareTo( const OString & rObj, sal_Int32 maxLength ) const SAL_THROW(())
00384     {
00385         return rtl_str_shortenedCompare_WithLength( pData->buffer, pData->length,
00386                                                     rObj.pData->buffer, rObj.pData->length, maxLength );
00387     }
00388 
00401     sal_Int32 reverseCompareTo( const OString & str ) const SAL_THROW(())
00402     {
00403         return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
00404                                                   str.pData->buffer, str.pData->length );
00405     }
00406 
00418     sal_Bool equals( const OString & str ) const SAL_THROW(())
00419     {
00420         if ( pData->length != str.pData->length )
00421             return sal_False;
00422         if ( pData == str.pData )
00423             return sal_True;
00424         return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
00425                                                   str.pData->buffer, str.pData->length ) == 0;
00426     }
00427 
00443     sal_Bool equalsL( const sal_Char* value, sal_Int32 length ) const SAL_THROW(())
00444     {
00445         if ( pData->length != length )
00446             return sal_False;
00447 
00448         return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
00449                                                   value, length ) == 0;
00450     }
00451 
00466     sal_Bool equalsIgnoreAsciiCase( const OString & str ) const SAL_THROW(())
00467     {
00468         if ( pData->length != str.pData->length )
00469             return sal_False;
00470         if ( pData == str.pData )
00471             return sal_True;
00472         return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
00473                                                           str.pData->buffer, str.pData->length ) == 0;
00474     }
00475 
00497 #ifdef HAVE_SFINAE_ANONYMOUS_BROKEN
00498     sal_Bool equalsIgnoreAsciiCase( const sal_Char * asciiStr ) const SAL_THROW(())
00499     {
00500         return rtl_str_compareIgnoreAsciiCase( pData->buffer, asciiStr ) == 0;
00501     }
00502 #else
00503     template< typename T >
00504     typename internal::CharPtrDetector< T, bool >::Type equalsIgnoreAsciiCase( const T& asciiStr ) const SAL_THROW(())
00505     {
00506         return rtl_str_compareIgnoreAsciiCase( pData->buffer, asciiStr ) == 0;
00507     }
00508 
00509     template< typename T >
00510     typename internal::NonConstCharArrayDetector< T, bool >::Type equalsIgnoreAsciiCase( T& asciiStr ) const SAL_THROW(())
00511     {
00512         return rtl_str_compareIgnoreAsciiCase( pData->buffer, asciiStr ) == 0;
00513     }
00514 
00520     template< typename T >
00521     typename internal::ConstCharArrayDetector< T, bool >::Type  equalsIgnoreAsciiCase( T& literal ) const SAL_THROW(())
00522     {
00523         RTL_STRING_CONST_FUNCTION
00524         if ( pData->length != internal::ConstCharArrayDetector< T, void >::size - 1 )
00525             return false;
00526         return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
00527                                                           literal, internal::ConstCharArrayDetector< T, void >::size - 1 ) == 0;
00528     }
00529 #endif
00530 
00550     sal_Bool equalsIgnoreAsciiCaseL( const sal_Char * asciiStr, sal_Int32 asciiStrLength ) const SAL_THROW(())
00551     {
00552         if ( pData->length != asciiStrLength )
00553             return sal_False;
00554 
00555         return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
00556                                                           asciiStr, asciiStrLength ) == 0;
00557     }
00558 
00574     sal_Bool match( const OString & str, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
00575     {
00576         return rtl_str_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
00577                                                     str.pData->buffer, str.pData->length, str.pData->length ) == 0;
00578     }
00579 
00585     template< typename T >
00586     typename internal::ConstCharArrayDetector< T, bool >::Type  match( T& literal, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
00587     {
00588         RTL_STRING_CONST_FUNCTION
00589         return rtl_str_shortenedCompare_WithLength(
00590             pData->buffer + fromIndex, pData->length - fromIndex,
00591             literal, internal::ConstCharArrayDetector< T, void >::size - 1, internal::ConstCharArrayDetector< T, void >::size - 1) == 0;
00592     }
00593 
00610     bool matchL(
00611         char const * str, sal_Int32 strLength, sal_Int32 fromIndex = 0)
00612         const
00613     {
00614         return rtl_str_shortenedCompare_WithLength(
00615             pData->buffer + fromIndex, pData->length - fromIndex,
00616             str, strLength, strLength) == 0;
00617     }
00618 
00619     // This overload is left undefined, to detect calls of matchL that
00620     // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
00621     // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
00622     // platforms):
00623 #if SAL_TYPES_SIZEOFLONG == 8
00624     void matchL(char const *, sal_Int32, rtl_TextEncoding) const;
00625 #endif
00626 
00645     sal_Bool matchIgnoreAsciiCase( const OString & str, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
00646     {
00647         return rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
00648                                                                    str.pData->buffer, str.pData->length,
00649                                                                    str.pData->length ) == 0;
00650     }
00651 
00657     template< typename T >
00658     typename internal::ConstCharArrayDetector< T, bool >::Type matchIgnoreAsciiCase( T& literal, sal_Int32 fromIndex = 0 ) const
00659     {
00660         RTL_STRING_CONST_FUNCTION
00661         return rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
00662             literal, internal::ConstCharArrayDetector< T, void >::size - 1, internal::ConstCharArrayDetector< T, void >::size - 1 ) == 0;
00663     }
00664 
00675     bool endsWith(OString const & str) const {
00676         return str.getLength() <= getLength()
00677             && match(str, getLength() - str.getLength());
00678     }
00679 
00685     template< typename T >
00686     typename internal::ConstCharArrayDetector< T, bool >::Type endsWith( T& literal ) const
00687     {
00688         RTL_STRING_CONST_FUNCTION
00689         return internal::ConstCharArrayDetector< T, void >::size - 1 <= getLength()
00690             && match(literal, getLength() - ( internal::ConstCharArrayDetector< T, void >::size - 1 ));
00691     }
00692 
00706     bool endsWithL(char const * str, sal_Int32 strLength) const {
00707         return strLength <= getLength()
00708             && matchL(str, strLength, getLength() - strLength);
00709     }
00710 
00711     friend sal_Bool     operator == ( const OString& rStr1, const OString& rStr2 ) SAL_THROW(())
00712                         { return rStr1.equals(rStr2); }
00713     friend sal_Bool     operator != ( const OString& rStr1,     const OString& rStr2 ) SAL_THROW(())
00714                         { return !(operator == ( rStr1, rStr2 )); }
00715     friend sal_Bool     operator <  ( const OString& rStr1,    const OString& rStr2 ) SAL_THROW(())
00716                         { return rStr1.compareTo( rStr2 ) < 0; }
00717     friend sal_Bool     operator >  ( const OString& rStr1,    const OString& rStr2 ) SAL_THROW(())
00718                         { return rStr1.compareTo( rStr2 ) > 0; }
00719     friend sal_Bool     operator <= ( const OString& rStr1,    const OString& rStr2 ) SAL_THROW(())
00720                         { return rStr1.compareTo( rStr2 ) <= 0; }
00721     friend sal_Bool     operator >= ( const OString& rStr1,    const OString& rStr2 ) SAL_THROW(())
00722                         { return rStr1.compareTo( rStr2 ) >= 0; }
00723 
00724     template< typename T >
00725     friend typename internal::CharPtrDetector< T, bool >::Type operator==( const OString& rStr1, const T& value ) SAL_THROW(())
00726     {
00727         return rStr1.compareTo( value ) == 0;
00728     }
00729 
00730     template< typename T >
00731     friend typename internal::NonConstCharArrayDetector< T, bool >::Type operator==( const OString& rStr1, T& value ) SAL_THROW(())
00732     {
00733         return rStr1.compareTo( value ) == 0;
00734     }
00735 
00736     template< typename T >
00737     friend typename internal::CharPtrDetector< T, bool >::Type operator==( const T& value, const OString& rStr2 ) SAL_THROW(())
00738     {
00739         return rStr2.compareTo( value ) == 0;
00740     }
00741 
00742     template< typename T >
00743     friend typename internal::NonConstCharArrayDetector< T, bool >::Type operator==( T& value, const OString& rStr2 ) SAL_THROW(())
00744     {
00745         return rStr2.compareTo( value ) == 0;
00746     }
00747 
00753     template< typename T >
00754     friend typename internal::ConstCharArrayDetector< T, bool >::Type operator==( const OString& rStr, T& literal ) SAL_THROW(())
00755     {
00756         RTL_STRING_CONST_FUNCTION
00757         return rStr.getLength() == internal::ConstCharArrayDetector< T, void >::size - 1
00758             && rtl_str_compare_WithLength( rStr.pData->buffer, rStr.pData->length, literal,
00759                 internal::ConstCharArrayDetector< T, void >::size - 1 ) == 0;
00760     }
00761 
00767     template< typename T >
00768     friend typename internal::ConstCharArrayDetector< T, bool >::Type operator==( T& literal, const OString& rStr ) SAL_THROW(())
00769     {
00770         RTL_STRING_CONST_FUNCTION
00771         return rStr.getLength() == internal::ConstCharArrayDetector< T, void >::size - 1
00772             && rtl_str_compare_WithLength( rStr.pData->buffer, rStr.pData->length, literal,
00773                 internal::ConstCharArrayDetector< T, void >::size - 1 ) == 0;
00774     }
00775 
00776     template< typename T >
00777     friend typename internal::CharPtrDetector< T, bool >::Type operator!=( const OString& rStr1, const T& value ) SAL_THROW(())
00778     {
00779         return !(operator == ( rStr1, value ));
00780     }
00781 
00782     template< typename T >
00783     friend typename internal::NonConstCharArrayDetector< T, bool >::Type operator!=( const OString& rStr1, T& value ) SAL_THROW(())
00784     {
00785         return !(operator == ( rStr1, value ));
00786     }
00787 
00788     template< typename T >
00789     friend typename internal::CharPtrDetector< T, bool >::Type operator!=( const T& value,   const OString& rStr2 ) SAL_THROW(())
00790     {
00791         return !(operator == ( value, rStr2 ));
00792     }
00793 
00794     template< typename T >
00795     friend typename internal::NonConstCharArrayDetector< T, bool >::Type operator!=( T& value,   const OString& rStr2 ) SAL_THROW(())
00796     {
00797         return !(operator == ( value, rStr2 ));
00798     }
00799 
00805     template< typename T >
00806     friend typename internal::ConstCharArrayDetector< T, bool >::Type operator!=( const OString& rStr, T& literal ) SAL_THROW(())
00807     {
00808         return !( rStr == literal );
00809     }
00810 
00816     template< typename T >
00817     friend typename internal::ConstCharArrayDetector< T, bool >::Type operator!=( T& literal, const OString& rStr ) SAL_THROW(())
00818     {
00819         return !( literal == rStr );
00820     }
00821 
00829     sal_Int32 hashCode() const SAL_THROW(())
00830     {
00831         return rtl_str_hashCode_WithLength( pData->buffer, pData->length );
00832     }
00833 
00847     sal_Int32 indexOf( sal_Char ch, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
00848     {
00849         sal_Int32 ret = rtl_str_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
00850         return (ret < 0 ? ret : ret+fromIndex);
00851     }
00852 
00862     sal_Int32 lastIndexOf( sal_Char ch ) const SAL_THROW(())
00863     {
00864         return rtl_str_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
00865     }
00866 
00879     sal_Int32 lastIndexOf( sal_Char ch, sal_Int32 fromIndex ) const SAL_THROW(())
00880     {
00881         return rtl_str_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
00882     }
00883 
00899     sal_Int32 indexOf( const OString & str, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
00900     {
00901         sal_Int32 ret = rtl_str_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
00902                                                        str.pData->buffer, str.pData->length );
00903         return (ret < 0 ? ret : ret+fromIndex);
00904     }
00905 
00911     template< typename T >
00912     typename internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
00913     {
00914         RTL_STRING_CONST_FUNCTION
00915         sal_Int32 n = rtl_str_indexOfStr_WithLength(
00916             pData->buffer + fromIndex, pData->length - fromIndex, literal, internal::ConstCharArrayDetector< T, void >::size - 1);
00917         return n < 0 ? n : n + fromIndex;
00918     }
00919 
00938     sal_Int32 indexOfL(char const * str, sal_Int32 len, sal_Int32 fromIndex = 0)
00939         const SAL_THROW(())
00940     {
00941         sal_Int32 n = rtl_str_indexOfStr_WithLength(
00942             pData->buffer + fromIndex, pData->length - fromIndex, str, len);
00943         return n < 0 ? n : n + fromIndex;
00944     }
00945 
00946     // This overload is left undefined, to detect calls of indexOfL that
00947     // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
00948     // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
00949     // platforms):
00950 #if SAL_TYPES_SIZEOFLONG == 8
00951     void indexOfL(char const *, sal_Int32, rtl_TextEncoding) const;
00952 #endif
00953 
00969     sal_Int32 lastIndexOf( const OString & str ) const SAL_THROW(())
00970     {
00971         return rtl_str_lastIndexOfStr_WithLength( pData->buffer, pData->length,
00972                                                   str.pData->buffer, str.pData->length );
00973     }
00974 
00992     sal_Int32 lastIndexOf( const OString & str, sal_Int32 fromIndex ) const SAL_THROW(())
00993     {
00994         return rtl_str_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
00995                                                   str.pData->buffer, str.pData->length );
00996     }
00997 
01007     OString copy( sal_Int32 beginIndex ) const SAL_THROW(())
01008     {
01009         assert(beginIndex >= 0 && beginIndex <= getLength());
01010         if ( beginIndex == 0 )
01011             return *this;
01012         else
01013         {
01014             rtl_String* pNew = 0;
01015             rtl_string_newFromStr_WithLength( &pNew, pData->buffer+beginIndex, getLength()-beginIndex );
01016             return OString( pNew, (DO_NOT_ACQUIRE*)0 );
01017         }
01018     }
01019 
01031     OString copy( sal_Int32 beginIndex, sal_Int32 count ) const SAL_THROW(())
01032     {
01033         assert(beginIndex >= 0 && beginIndex <= getLength() && count >= 0
01034                 && sal::static_int_cast<sal_uInt32>(count) <=
01035                    sal::static_int_cast<sal_uInt32>(getLength() - beginIndex));
01036         if ( (beginIndex == 0) && (count == getLength()) )
01037             return *this;
01038         else
01039         {
01040             rtl_String* pNew = 0;
01041             rtl_string_newFromStr_WithLength( &pNew, pData->buffer+beginIndex, count );
01042             return OString( pNew, (DO_NOT_ACQUIRE*)0 );
01043         }
01044     }
01045 
01054     OString concat( const OString & str ) const SAL_THROW(())
01055     {
01056         rtl_String* pNew = 0;
01057         rtl_string_newConcat( &pNew, pData, str.pData );
01058         return OString( pNew, (DO_NOT_ACQUIRE*)0 );
01059     }
01060 
01061     friend OString operator+( const OString & str1, const OString & str2  ) SAL_THROW(())
01062     {
01063         return str1.concat( str2 );
01064     }
01065 
01079     OString replaceAt( sal_Int32 index, sal_Int32 count, const OString& newStr ) const SAL_THROW(())
01080     {
01081         rtl_String* pNew = 0;
01082         rtl_string_newReplaceStrAt( &pNew, pData, index, count, newStr.pData );
01083         return OString( pNew, (DO_NOT_ACQUIRE*)0 );
01084     }
01085 
01099     OString replace( sal_Char oldChar, sal_Char newChar ) const SAL_THROW(())
01100     {
01101         rtl_String* pNew = 0;
01102         rtl_string_newReplace( &pNew, pData, oldChar, newChar );
01103         return OString( pNew, (DO_NOT_ACQUIRE*)0 );
01104     }
01105 
01124     OString replaceFirst(
01125         OString const & from, OString const & to, sal_Int32 * index = 0) const
01126     {
01127         rtl_String * s = 0;
01128         sal_Int32 i = 0;
01129         rtl_string_newReplaceFirst(
01130             &s, pData, from.pData->buffer, from.pData->length,
01131             to.pData->buffer, to.pData->length, index == 0 ? &i : index);
01132         return OString(s, SAL_NO_ACQUIRE);
01133     }
01134 
01148     OString replaceAll(OString const & from, OString const & to) const {
01149         rtl_String * s = 0;
01150         rtl_string_newReplaceAll(
01151             &s, pData, from.pData->buffer, from.pData->length,
01152             to.pData->buffer, to.pData->length);
01153         return OString(s, SAL_NO_ACQUIRE);
01154     }
01155 
01166     OString toAsciiLowerCase() const SAL_THROW(())
01167     {
01168         rtl_String* pNew = 0;
01169         rtl_string_newToAsciiLowerCase( &pNew, pData );
01170         return OString( pNew, (DO_NOT_ACQUIRE*)0 );
01171     }
01172 
01183     OString toAsciiUpperCase() const SAL_THROW(())
01184     {
01185         rtl_String* pNew = 0;
01186         rtl_string_newToAsciiUpperCase( &pNew, pData );
01187         return OString( pNew, (DO_NOT_ACQUIRE*)0 );
01188     }
01189 
01201     OString trim() const SAL_THROW(())
01202     {
01203         rtl_String* pNew = 0;
01204         rtl_string_newTrim( &pNew, pData );
01205         return OString( pNew, (DO_NOT_ACQUIRE*)0 );
01206     }
01207 
01232     OString getToken( sal_Int32 token, sal_Char cTok, sal_Int32& index ) const SAL_THROW(())
01233     {
01234         rtl_String * pNew = 0;
01235         index = rtl_string_getToken( &pNew, pData, token, cTok, index );
01236         return OString( pNew, (DO_NOT_ACQUIRE *)0 );
01237     }
01238 
01252     OString getToken(sal_Int32 count, char separator) const {
01253         sal_Int32 n = 0;
01254         return getToken(count, separator, n);
01255     }
01256 
01265     sal_Bool toBoolean() const SAL_THROW(())
01266     {
01267         return rtl_str_toBoolean( pData->buffer );
01268     }
01269 
01276     sal_Char toChar() const SAL_THROW(())
01277     {
01278         return pData->buffer[0];
01279     }
01280 
01290     sal_Int32 toInt32( sal_Int16 radix = 10 ) const SAL_THROW(())
01291     {
01292         return rtl_str_toInt32( pData->buffer, radix );
01293     }
01294 
01304     sal_Int64 toInt64( sal_Int16 radix = 10 ) const SAL_THROW(())
01305     {
01306         return rtl_str_toInt64( pData->buffer, radix );
01307     }
01308 
01317     float toFloat() const SAL_THROW(())
01318     {
01319         return rtl_str_toFloat( pData->buffer );
01320     }
01321 
01330     double toDouble() const SAL_THROW(())
01331     {
01332         return rtl_str_toDouble( pData->buffer );
01333     }
01334 
01345     static OString valueOf( sal_Bool b ) SAL_THROW(())
01346     {
01347         sal_Char aBuf[RTL_STR_MAX_VALUEOFBOOLEAN];
01348         rtl_String* pNewData = 0;
01349         rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfBoolean( aBuf, b ) );
01350         return OString( pNewData, (DO_NOT_ACQUIRE*)0 );
01351     }
01352 
01359     static OString valueOf( sal_Char c ) SAL_THROW(())
01360     {
01361         return OString( &c, 1 );
01362     }
01363 
01373     static OString valueOf( sal_Int32 i, sal_Int16 radix = 10 ) SAL_THROW(())
01374     {
01375         sal_Char aBuf[RTL_STR_MAX_VALUEOFINT32];
01376         rtl_String* pNewData = 0;
01377         rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfInt32( aBuf, i, radix ) );
01378         return OString( pNewData, (DO_NOT_ACQUIRE*)0 );
01379     }
01380 
01390     static OString valueOf( sal_Int64 ll, sal_Int16 radix = 10 ) SAL_THROW(())
01391     {
01392         sal_Char aBuf[RTL_STR_MAX_VALUEOFINT64];
01393         rtl_String* pNewData = 0;
01394         rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfInt64( aBuf, ll, radix ) );
01395         return OString( pNewData, (DO_NOT_ACQUIRE*)0 );
01396     }
01397 
01406     static OString valueOf( float f ) SAL_THROW(())
01407     {
01408         sal_Char aBuf[RTL_STR_MAX_VALUEOFFLOAT];
01409         rtl_String* pNewData = 0;
01410         rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfFloat( aBuf, f ) );
01411         return OString( pNewData, (DO_NOT_ACQUIRE*)0 );
01412     }
01413 
01422     static OString valueOf( double d ) SAL_THROW(())
01423     {
01424         sal_Char aBuf[RTL_STR_MAX_VALUEOFDOUBLE];
01425         rtl_String* pNewData = 0;
01426         rtl_string_newFromStr_WithLength( &pNewData, aBuf, rtl_str_valueOfDouble( aBuf, d ) );
01427         return OString( pNewData, (DO_NOT_ACQUIRE*)0 );
01428     }
01429 };
01430 
01431 /* ======================================================================= */
01432 
01433 } /* Namespace */
01434 
01435 #ifdef RTL_STRING_UNITTEST
01436 namespace rtl
01437 {
01438 typedef rtlunittest::OString OString;
01439 }
01440 #undef RTL_STRING_CONST_FUNCTION
01441 #endif
01442 
01443 namespace rtl
01444 {
01445 
01451 struct OStringHash
01452 {
01462     size_t operator()( const OString& rString ) const
01463         { return (size_t)rString.hashCode(); }
01464 };
01465 
01466 /* ======================================================================= */
01467 
01468 } /* Namespace */
01469 
01470 #endif /* _RTL_STRING_HXX_ */
01471 
01472 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines