My Project
UDK 3.2.7 C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ustring.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * Copyright 2000, 2010 Oracle and/or its affiliates.
7  *
8  * OpenOffice.org - a multi-platform office productivity suite
9  *
10  * This file is part of OpenOffice.org.
11  *
12  * OpenOffice.org is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License version 3
14  * only, as published by the Free Software Foundation.
15  *
16  * OpenOffice.org is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser General Public License version 3 for more details
20  * (a copy is included in the LICENSE file that accompanied this code).
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * version 3 along with OpenOffice.org. If not, see
24  * <http://www.openoffice.org/license.html>
25  * for a copy of the LGPLv3 License.
26  *
27  ************************************************************************/
28 
29 #ifndef _RTL_USTRING_HXX_
30 #define _RTL_USTRING_HXX_
31 
32 #include "sal/config.h"
33 
34 #include <cassert>
35 
36 #include "osl/diagnose.h"
37 #include <rtl/ustring.h>
38 #include <rtl/string.hxx>
39 #include <rtl/stringutils.hxx>
40 #include <rtl/memory.h>
41 #include "sal/log.hxx"
42 
43 #if defined EXCEPTIONS_OFF
44 #include <stdlib.h>
45 #else
46 #include <new>
47 #endif
48 
49 // The unittest uses slightly different code to help check that the proper
50 // calls are made. The class is put into a different namespace to make
51 // sure the compiler generates a different (if generating also non-inline)
52 // copy of the function and does not merge them together. The class
53 // is "brought" into the proper rtl namespace by a typedef below.
54 #ifdef RTL_STRING_UNITTEST
55 #define rtl rtlunittest
56 #endif
57 
58 namespace rtl
59 {
60 
61 #ifdef RTL_STRING_UNITTEST
62 #undef rtl
63 #endif
64 
65 /* ======================================================================= */
66 
91 class OUString
92 {
93 public:
95  rtl_uString * pData;
97 
98 private:
99  class DO_NOT_ACQUIRE{};
100 
101  OUString( rtl_uString * value, SAL_UNUSED_PARAMETER DO_NOT_ACQUIRE * )
102  {
103  pData = value;
104  }
105 
106 public:
111  {
112  pData = 0;
113  rtl_uString_new( &pData );
114  }
115 
121  OUString( const OUString & str ) SAL_THROW(())
122  {
123  pData = str.pData;
124  rtl_uString_acquire( pData );
125  }
126 
132  OUString( rtl_uString * str ) SAL_THROW(())
133  {
134  pData = str;
135  rtl_uString_acquire( pData );
136  }
137 
146  inline OUString( rtl_uString * str, __sal_NoAcquire ) SAL_THROW(())
147  { pData = str; }
148 
154  explicit OUString( sal_Unicode value ) SAL_THROW(())
155  : pData (0)
156  {
157  rtl_uString_newFromStr_WithLength( &pData, &value, 1 );
158  }
159 
165  OUString( const sal_Unicode * value ) SAL_THROW(())
166  {
167  pData = 0;
168  rtl_uString_newFromStr( &pData, value );
169  }
170 
179  OUString( const sal_Unicode * value, sal_Int32 length ) SAL_THROW(())
180  {
181  pData = 0;
182  rtl_uString_newFromStr_WithLength( &pData, value, length );
183  }
184 
200 #ifdef HAVE_SFINAE_ANONYMOUS_BROKEN
201  // Old gcc can try to convert anonymous enums to OUString and give compile error.
202  // So instead have a variant for const and non-const char[].
203  template< int N >
204  OUString( const char (&literal)[ N ] )
205  {
206  pData = 0;
207  rtl_uString_newFromLiteral( &pData, literal, N - 1, 0 );
208 #ifdef RTL_STRING_UNITTEST
209  rtl_string_unittest_const_literal = true;
210 #endif
211  }
212 
217  template< int N >
218  OUString( char (&value)[ N ] )
219 #ifndef RTL_STRING_UNITTEST
220  ; // intentionally not implemented
221 #else
222  {
223  (void) value; // unused
224  pData = 0;
225  rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
226  rtl_string_unittest_invalid_conversion = true;
227  }
228 #endif
229 #else // HAVE_SFINAE_ANONYMOUS_BROKEN
230  template< typename T >
232  {
233  pData = 0;
235 #ifdef RTL_STRING_UNITTEST
236  rtl_string_unittest_const_literal = true;
237 #endif
238  }
239 
240 #endif // HAVE_SFINAE_ANONYMOUS_BROKEN
241 
242 
243 #ifdef RTL_STRING_UNITTEST
244 
248  template< typename T >
250  {
251  pData = 0;
252  rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
253  rtl_string_unittest_invalid_conversion = true;
254  }
259  template< typename T >
260  OUString( const T&, typename internal::ExceptCharArrayDetector< T >::Type = internal::Dummy() )
261  {
262  pData = 0;
263  rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
264  rtl_string_unittest_invalid_conversion = true;
265  }
266 #endif
267 
282  OUString( const sal_Char * value, sal_Int32 length,
283  rtl_TextEncoding encoding,
284  sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS )
285  {
286  pData = 0;
287  rtl_string2UString( &pData, value, length, encoding, convertFlags );
288  if (pData == 0) {
289 #if defined EXCEPTIONS_OFF
290  abort();
291 #else
292  throw std::bad_alloc();
293 #endif
294  }
295  }
296 
313  inline explicit OUString(
314  sal_uInt32 const * codePoints, sal_Int32 codePointCount):
315  pData(NULL)
316  {
317  rtl_uString_newFromCodePoints(&pData, codePoints, codePointCount);
318  if (pData == NULL) {
319 #if defined EXCEPTIONS_OFF
320  abort();
321 #else
322  throw std::bad_alloc();
323 #endif
324  }
325  }
326 
331  {
332  rtl_uString_release( pData );
333  }
334 
346  static inline OUString const & unacquired( rtl_uString * const * ppHandle )
347  { return * reinterpret_cast< OUString const * >( ppHandle ); }
348 
354  OUString & operator=( const OUString & str ) SAL_THROW(())
355  {
356  rtl_uString_assign( &pData, str.pData );
357  return *this;
358  }
359 
372  template< typename T >
374  {
376  return *this;
377  }
378 
384  OUString & operator+=( const OUString & str ) SAL_THROW(())
385  {
386  rtl_uString_newConcat( &pData, pData, str.pData );
387  return *this;
388  }
389 
398  sal_Int32 getLength() const SAL_THROW(()) { return pData->length; }
399 
408  bool isEmpty() const SAL_THROW(())
409  {
410  return pData->length == 0;
411  }
412 
420  const sal_Unicode * getStr() const SAL_THROW(()) { return pData->buffer; }
421 
431  sal_Unicode operator [](sal_Int32 index) const { return getStr()[index]; }
432 
445  sal_Int32 compareTo( const OUString & str ) const SAL_THROW(())
446  {
447  return rtl_ustr_compare_WithLength( pData->buffer, pData->length,
448  str.pData->buffer, str.pData->length );
449  }
450 
466  sal_Int32 compareTo( const OUString & str, sal_Int32 maxLength ) const SAL_THROW(())
467  {
468  return rtl_ustr_shortenedCompare_WithLength( pData->buffer, pData->length,
469  str.pData->buffer, str.pData->length, maxLength );
470  }
471 
484  sal_Int32 reverseCompareTo( const OUString & str ) const SAL_THROW(())
485  {
486  return rtl_ustr_reverseCompare_WithLength( pData->buffer, pData->length,
487  str.pData->buffer, str.pData->length );
488  }
489 
501  sal_Bool equals( const OUString & str ) const SAL_THROW(())
502  {
503  if ( pData->length != str.pData->length )
504  return sal_False;
505  if ( pData == str.pData )
506  return sal_True;
507  return rtl_ustr_reverseCompare_WithLength( pData->buffer, pData->length,
508  str.pData->buffer, str.pData->length ) == 0;
509  }
510 
526  {
527  if ( pData->length != str.pData->length )
528  return sal_False;
529  if ( pData == str.pData )
530  return sal_True;
531  return rtl_ustr_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
532  str.pData->buffer, str.pData->length ) == 0;
533  }
534 
540  template< typename T >
542  {
543  if ( pData->length != internal::ConstCharArrayDetector< T, void >::size - 1 )
544  return sal_False;
545 
546  return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, literal ) == 0;
547  }
548 
564  sal_Bool match( const OUString & str, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
565  {
566  return rtl_ustr_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
567  str.pData->buffer, str.pData->length, str.pData->length ) == 0;
568  }
569 
575  template< typename T >
576  typename internal::ConstCharArrayDetector< T, bool >::Type match( T& literal, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
577  {
578  return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
580  }
581 
600  sal_Bool matchIgnoreAsciiCase( const OUString & str, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
601  {
602  return rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
603  str.pData->buffer, str.pData->length,
604  str.pData->length ) == 0;
605  }
606 
612  template< typename T >
613  typename internal::ConstCharArrayDetector< T, bool >::Type matchIgnoreAsciiCase( T& literal, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
614  {
615  return rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
617  }
618 
635  sal_Int32 compareToAscii( const sal_Char* asciiStr ) const SAL_THROW(())
636  {
637  return rtl_ustr_ascii_compare_WithLength( pData->buffer, pData->length, asciiStr );
638  }
639 
657  sal_Int32 compareToAscii( const sal_Char * asciiStr, sal_Int32 maxLength ) const SAL_THROW(())
658  {
659  return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer, pData->length,
660  asciiStr, maxLength );
661  }
662 
682  sal_Int32 reverseCompareToAsciiL( const sal_Char * asciiStr, sal_Int32 asciiStrLength ) const SAL_THROW(())
683  {
684  return rtl_ustr_asciil_reverseCompare_WithLength( pData->buffer, pData->length,
685  asciiStr, asciiStrLength );
686  }
687 
703  sal_Bool equalsAscii( const sal_Char* asciiStr ) const SAL_THROW(())
704  {
705  return rtl_ustr_ascii_compare_WithLength( pData->buffer, pData->length,
706  asciiStr ) == 0;
707  }
708 
726  sal_Bool equalsAsciiL( const sal_Char* asciiStr, sal_Int32 asciiStrLength ) const SAL_THROW(())
727  {
728  if ( pData->length != asciiStrLength )
729  return sal_False;
730 
732  pData->buffer, asciiStr, asciiStrLength );
733  }
734 
754  {
755  return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr ) == 0;
756  }
757 
776  sal_Int32 compareToIgnoreAsciiCaseAscii( const sal_Char * asciiStr ) const SAL_THROW(())
777  {
778  return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr );
779  }
780 
801  sal_Bool equalsIgnoreAsciiCaseAsciiL( const sal_Char * asciiStr, sal_Int32 asciiStrLength ) const SAL_THROW(())
802  {
803  if ( pData->length != asciiStrLength )
804  return sal_False;
805 
806  return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr ) == 0;
807  }
808 
830  sal_Bool matchAsciiL( const sal_Char* asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
831  {
832  return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
833  asciiStr, asciiStrLength ) == 0;
834  }
835 
836  // This overload is left undefined, to detect calls of matchAsciiL that
837  // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
838  // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
839  // platforms):
840 #if SAL_TYPES_SIZEOFLONG == 8
841  void matchAsciiL(char const *, sal_Int32, rtl_TextEncoding) const;
842 #endif
843 
868  sal_Bool matchIgnoreAsciiCaseAsciiL( const sal_Char* asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
869  {
870  return rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
871  asciiStr, asciiStrLength ) == 0;
872  }
873 
874  // This overload is left undefined, to detect calls of
875  // matchIgnoreAsciiCaseAsciiL that erroneously use
876  // RTL_CONSTASCII_USTRINGPARAM instead of RTL_CONSTASCII_STRINGPARAM (but
877  // would lead to ambiguities on 32 bit platforms):
878 #if SAL_TYPES_SIZEOFLONG == 8
879  void matchIgnoreAsciiCaseAsciiL(char const *, sal_Int32, rtl_TextEncoding)
880  const;
881 #endif
882 
893  bool endsWith(OUString const & str) const {
894  return str.getLength() <= getLength()
895  && match(str, getLength() - str.getLength());
896  }
897 
903  template< typename T >
905  {
906  return internal::ConstCharArrayDetector< T, void >::size - 1 <= pData->length
908  pData->buffer + pData->length - ( internal::ConstCharArrayDetector< T, void >::size - 1 ), literal,
910  }
911 
923  inline bool endsWithAsciiL(char const * asciiStr, sal_Int32 asciiStrLength)
924  const
925  {
926  return asciiStrLength <= pData->length
928  pData->buffer + pData->length - asciiStrLength, asciiStr,
929  asciiStrLength);
930  }
931 
946  {
947  return str.getLength() <= getLength()
948  && matchIgnoreAsciiCase(str, getLength() - str.getLength());
949  }
950 
956  template< typename T >
958  {
959  return internal::ConstCharArrayDetector< T, void >::size - 1 <= pData->length
961  pData->buffer + pData->length - ( internal::ConstCharArrayDetector< T, void >::size - 1 ),
964  == 0);
965  }
966 
978  char const * asciiStr, sal_Int32 asciiStrLength) const
979  {
980  return asciiStrLength <= pData->length
982  pData->buffer + pData->length - asciiStrLength,
983  asciiStrLength, asciiStr, asciiStrLength)
984  == 0);
985  }
986 
987  friend sal_Bool operator == ( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
988  { return rStr1.equals(rStr2); }
989  friend sal_Bool operator == ( const OUString& rStr1, const sal_Unicode * pStr2 ) SAL_THROW(())
990  { return rStr1.compareTo( pStr2 ) == 0; }
991  friend sal_Bool operator == ( const sal_Unicode * pStr1, const OUString& rStr2 ) SAL_THROW(())
992  { return OUString( pStr1 ).compareTo( rStr2 ) == 0; }
993 
994  friend sal_Bool operator != ( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
995  { return !(operator == ( rStr1, rStr2 )); }
996  friend sal_Bool operator != ( const OUString& rStr1, const sal_Unicode * pStr2 ) SAL_THROW(())
997  { return !(operator == ( rStr1, pStr2 )); }
998  friend sal_Bool operator != ( const sal_Unicode * pStr1, const OUString& rStr2 ) SAL_THROW(())
999  { return !(operator == ( pStr1, rStr2 )); }
1000 
1001  friend sal_Bool operator < ( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
1002  { return rStr1.compareTo( rStr2 ) < 0; }
1003  friend sal_Bool operator > ( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
1004  { return rStr1.compareTo( rStr2 ) > 0; }
1005  friend sal_Bool operator <= ( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
1006  { return rStr1.compareTo( rStr2 ) <= 0; }
1007  friend sal_Bool operator >= ( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
1008  { return rStr1.compareTo( rStr2 ) >= 0; }
1009 
1017  template< typename T >
1018  friend inline typename internal::ConstCharArrayDetector< T, bool >::Type operator==( const OUString& string, T& literal )
1019  {
1020  return string.equalsAsciiL( literal, internal::ConstCharArrayDetector< T, void >::size - 1 );
1021  }
1029  template< typename T >
1030  friend inline typename internal::ConstCharArrayDetector< T, bool >::Type operator==( T& literal, const OUString& string )
1031  {
1032  return string.equalsAsciiL( literal, internal::ConstCharArrayDetector< T, void >::size - 1 );
1033  }
1041  template< typename T >
1042  friend inline typename internal::ConstCharArrayDetector< T, bool >::Type operator!=( const OUString& string, T& literal )
1043  {
1044  return !string.equalsAsciiL( literal, internal::ConstCharArrayDetector< T, void >::size - 1 );
1045  }
1053  template< typename T >
1054  friend inline typename internal::ConstCharArrayDetector< T, bool >::Type operator!=( T& literal, const OUString& string )
1055  {
1056  return !string.equalsAsciiL( literal, internal::ConstCharArrayDetector< T, void >::size - 1 );
1057  }
1058 
1066  sal_Int32 hashCode() const SAL_THROW(())
1067  {
1068  return rtl_ustr_hashCode_WithLength( pData->buffer, pData->length );
1069  }
1070 
1084  sal_Int32 indexOf( sal_Unicode ch, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
1085  {
1086  sal_Int32 ret = rtl_ustr_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
1087  return (ret < 0 ? ret : ret+fromIndex);
1088  }
1089 
1099  sal_Int32 lastIndexOf( sal_Unicode ch ) const SAL_THROW(())
1100  {
1101  return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
1102  }
1103 
1116  sal_Int32 lastIndexOf( sal_Unicode ch, sal_Int32 fromIndex ) const SAL_THROW(())
1117  {
1118  return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
1119  }
1120 
1136  sal_Int32 indexOf( const OUString & str, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
1137  {
1138  sal_Int32 ret = rtl_ustr_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1139  str.pData->buffer, str.pData->length );
1140  return (ret < 0 ? ret : ret+fromIndex);
1141  }
1142 
1148  template< typename T >
1149  typename internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
1150  {
1151  sal_Int32 ret = rtl_ustr_indexOfAscii_WithLength(
1152  pData->buffer + fromIndex, pData->length - fromIndex, literal,
1154  return ret < 0 ? ret : ret + fromIndex;
1155  }
1156 
1180  sal_Int32 indexOfAsciiL(
1181  char const * str, sal_Int32 len, sal_Int32 fromIndex = 0) const
1182  SAL_THROW(())
1183  {
1184  sal_Int32 ret = rtl_ustr_indexOfAscii_WithLength(
1185  pData->buffer + fromIndex, pData->length - fromIndex, str, len);
1186  return ret < 0 ? ret : ret + fromIndex;
1187  }
1188 
1189  // This overload is left undefined, to detect calls of indexOfAsciiL that
1190  // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
1191  // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
1192  // platforms):
1193 #if SAL_TYPES_SIZEOFLONG == 8
1194  void indexOfAsciiL(char const *, sal_Int32 len, rtl_TextEncoding) const;
1195 #endif
1196 
1212  sal_Int32 lastIndexOf( const OUString & str ) const SAL_THROW(())
1213  {
1214  return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, pData->length,
1215  str.pData->buffer, str.pData->length );
1216  }
1217 
1235  sal_Int32 lastIndexOf( const OUString & str, sal_Int32 fromIndex ) const SAL_THROW(())
1236  {
1237  return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
1238  str.pData->buffer, str.pData->length );
1239  }
1240 
1246  template< typename T >
1248  {
1250  pData->buffer, pData->length, literal, internal::ConstCharArrayDetector< T, void >::size - 1);
1251  }
1252 
1272  sal_Int32 lastIndexOfAsciiL(char const * str, sal_Int32 len) const
1273  SAL_THROW(())
1274  {
1276  pData->buffer, pData->length, str, len);
1277  }
1278 
1288  OUString copy( sal_Int32 beginIndex ) const SAL_THROW(())
1289  {
1290  assert(beginIndex >= 0 && beginIndex <= getLength());
1291  if ( beginIndex == 0 )
1292  return *this;
1293  else
1294  {
1295  rtl_uString* pNew = 0;
1296  rtl_uString_newFromStr_WithLength( &pNew, pData->buffer+beginIndex, getLength()-beginIndex );
1297  return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1298  }
1299  }
1300 
1312  OUString copy( sal_Int32 beginIndex, sal_Int32 count ) const SAL_THROW(())
1313  {
1314  assert(beginIndex >= 0 && beginIndex <= getLength() && count >= 0);
1315  if ( (beginIndex == 0) && (count == getLength()) )
1316  return *this;
1317  else
1318  {
1319  rtl_uString* pNew = 0;
1320  rtl_uString_newFromStr_WithLength( &pNew, pData->buffer+beginIndex, count );
1321  return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1322  }
1323  }
1324 
1333  OUString concat( const OUString & str ) const SAL_THROW(())
1334  {
1335  rtl_uString* pNew = 0;
1336  rtl_uString_newConcat( &pNew, pData, str.pData );
1337  return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1338  }
1339 
1340  friend OUString operator+( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
1341  {
1342  return rStr1.concat( rStr2 );
1343  }
1344 
1358  OUString replaceAt( sal_Int32 index, sal_Int32 count, const OUString& newStr ) const SAL_THROW(())
1359  {
1360  rtl_uString* pNew = 0;
1361  rtl_uString_newReplaceStrAt( &pNew, pData, index, count, newStr.pData );
1362  return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1363  }
1364 
1378  OUString replace( sal_Unicode oldChar, sal_Unicode newChar ) const SAL_THROW(())
1379  {
1380  rtl_uString* pNew = 0;
1381  rtl_uString_newReplace( &pNew, pData, oldChar, newChar );
1382  return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1383  }
1384 
1404  OUString const & from, OUString const & to, sal_Int32 * index = 0) const
1405  {
1406  rtl_uString * s = 0;
1407  sal_Int32 i = 0;
1409  &s, pData, from.pData, to.pData, index == 0 ? &i : index);
1410  return OUString(s, SAL_NO_ACQUIRE);
1411  }
1412 
1431  template< typename T >
1433  sal_Int32 * index = 0) const
1434  {
1435  rtl_uString * s = 0;
1436  sal_Int32 i = 0;
1438  &s, pData, from, internal::ConstCharArrayDetector< T, void >::size - 1, to.pData, index == 0 ? &i : index);
1439  return OUString(s, SAL_NO_ACQUIRE);
1440  }
1441 
1460  template< typename T1, typename T2 >
1462  replaceFirst( T1& from, T2& to, sal_Int32 * index = 0) const
1463  {
1464  rtl_uString * s = 0;
1465  sal_Int32 i = 0;
1467  &s, pData, from, internal::ConstCharArrayDetector< T1, void >::size - 1, to,
1468  internal::ConstCharArrayDetector< T2, void >::size - 1, index == 0 ? &i : index);
1469  return OUString(s, SAL_NO_ACQUIRE);
1470  }
1471 
1485  OUString replaceAll(OUString const & from, OUString const & to) const {
1486  rtl_uString * s = 0;
1487  rtl_uString_newReplaceAll(&s, pData, from.pData, to.pData);
1488  return OUString(s, SAL_NO_ACQUIRE);
1489  }
1490 
1504  template< typename T >
1506  {
1507  rtl_uString * s = 0;
1509  return OUString(s, SAL_NO_ACQUIRE);
1510  }
1511 
1525  template< typename T1, typename T2 >
1527  replaceAll( T1& from, T2& to ) const
1528  {
1529  rtl_uString * s = 0;
1533  return OUString(s, SAL_NO_ACQUIRE);
1534  }
1535 
1547  {
1548  rtl_uString* pNew = 0;
1549  rtl_uString_newToAsciiLowerCase( &pNew, pData );
1550  return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1551  }
1552 
1564  {
1565  rtl_uString* pNew = 0;
1566  rtl_uString_newToAsciiUpperCase( &pNew, pData );
1567  return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1568  }
1569 
1582  {
1583  rtl_uString* pNew = 0;
1584  rtl_uString_newTrim( &pNew, pData );
1585  return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1586  }
1587 
1612  OUString getToken( sal_Int32 token, sal_Unicode cTok, sal_Int32& index ) const SAL_THROW(())
1613  {
1614  rtl_uString * pNew = 0;
1615  index = rtl_uString_getToken( &pNew, pData, token, cTok, index );
1616  return OUString( pNew, (DO_NOT_ACQUIRE *)0 );
1617  }
1618 
1632  OUString getToken(sal_Int32 count, sal_Unicode separator) const {
1633  sal_Int32 n = 0;
1634  return getToken(count, separator, n);
1635  }
1636 
1646  {
1647  return rtl_ustr_toBoolean( pData->buffer );
1648  }
1649 
1657  {
1658  return pData->buffer[0];
1659  }
1660 
1670  sal_Int32 toInt32( sal_Int16 radix = 10 ) const SAL_THROW(())
1671  {
1672  return rtl_ustr_toInt32( pData->buffer, radix );
1673  }
1674 
1684  sal_Int64 toInt64( sal_Int16 radix = 10 ) const SAL_THROW(())
1685  {
1686  return rtl_ustr_toInt64( pData->buffer, radix );
1687  }
1688 
1697  float toFloat() const SAL_THROW(())
1698  {
1699  return rtl_ustr_toFloat( pData->buffer );
1700  }
1701 
1710  double toDouble() const SAL_THROW(())
1711  {
1712  return rtl_ustr_toDouble( pData->buffer );
1713  }
1714 
1715 
1732  {
1733  rtl_uString * pNew = 0;
1734  rtl_uString_intern( &pNew, pData );
1735  if (pNew == 0) {
1736 #if defined EXCEPTIONS_OFF
1737  abort();
1738 #else
1739  throw std::bad_alloc();
1740 #endif
1741  }
1742  return OUString( pNew, (DO_NOT_ACQUIRE *)0 );
1743  }
1744 
1770  static OUString intern( const sal_Char * value, sal_Int32 length,
1771  rtl_TextEncoding encoding,
1772  sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS,
1773  sal_uInt32 *pInfo = NULL )
1774  {
1775  rtl_uString * pNew = 0;
1776  rtl_uString_internConvert( &pNew, value, length, encoding,
1777  convertFlags, pInfo );
1778  if (pNew == 0) {
1779 #if defined EXCEPTIONS_OFF
1780  abort();
1781 #else
1782  throw std::bad_alloc();
1783 #endif
1784  }
1785  return OUString( pNew, (DO_NOT_ACQUIRE *)0 );
1786  }
1787 
1812  inline bool convertToString(OString * pTarget, rtl_TextEncoding nEncoding,
1813  sal_uInt32 nFlags) const
1814  {
1815  return rtl_convertUStringToString(&pTarget->pData, pData->buffer,
1816  pData->length, nEncoding, nFlags);
1817  }
1818 
1870  inline sal_uInt32 iterateCodePoints(
1871  sal_Int32 * indexUtf16, sal_Int32 incrementCodePoints = 1) const
1872  {
1874  pData, indexUtf16, incrementCodePoints);
1875  }
1876 
1888  {
1890  rtl_uString* pNewData = 0;
1891  rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfBoolean( aBuf, b ) );
1892  return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
1893  }
1894 
1902  {
1903  return OUString( &c, 1 );
1904  }
1905 
1915  static OUString valueOf( sal_Int32 i, sal_Int16 radix = 10 ) SAL_THROW(())
1916  {
1918  rtl_uString* pNewData = 0;
1919  rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfInt32( aBuf, i, radix ) );
1920  return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
1921  }
1922 
1932  static OUString valueOf( sal_Int64 ll, sal_Int16 radix = 10 ) SAL_THROW(())
1933  {
1935  rtl_uString* pNewData = 0;
1936  rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfInt64( aBuf, ll, radix ) );
1937  return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
1938  }
1939 
1948  static OUString valueOf( float f ) SAL_THROW(())
1949  {
1951  rtl_uString* pNewData = 0;
1952  rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfFloat( aBuf, f ) );
1953  return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
1954  }
1955 
1964  static OUString valueOf( double d ) SAL_THROW(())
1965  {
1967  rtl_uString* pNewData = 0;
1968  rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfDouble( aBuf, d ) );
1969  return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
1970  }
1971 
1987  static OUString createFromAscii( const sal_Char * value ) SAL_THROW(())
1988  {
1989  rtl_uString* pNew = 0;
1990  rtl_uString_newFromAscii( &pNew, value );
1991  return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1992  }
1993 };
1994 
1995 /* ======================================================================= */
1996 
1997 } /* Namespace */
1998 
1999 #ifdef RTL_STRING_UNITTEST
2000 namespace rtl
2001 {
2002 typedef rtlunittest::OUString OUString;
2003 }
2004 #endif
2005 
2006 namespace rtl
2007 {
2008 
2015 {
2025  size_t operator()(const OUString& rString) const
2026  { return (size_t)rString.hashCode(); }
2027 };
2028 
2029 /* ======================================================================= */
2030 
2048 inline OUString OStringToOUString( const OString & rStr,
2049  rtl_TextEncoding encoding,
2050  sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS )
2051 {
2052  return OUString( rStr.getStr(), rStr.getLength(), encoding, convertFlags );
2053 }
2054 
2072 inline OString OUStringToOString( const OUString & rUnicode,
2073  rtl_TextEncoding encoding,
2074  sal_uInt32 convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS )
2075 {
2076  return OString( rUnicode.getStr(), rUnicode.getLength(), encoding, convertFlags );
2077 }
2078 
2079 /* ======================================================================= */
2080 
2081 } /* Namespace */
2082 
2083 #endif /* _RTL_USTRING_HXX */
2084 
2085 // Include the ostream << operator directly here, so that it's always available
2086 // for SAL_INFO etc. Make sure it's outside of #ifdef _RTL_USTRING_HXX, because
2087 // includes ustring.hxx back.
2089 
2090 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */