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 
90 class OUString
91 {
92 public:
94  rtl_uString * pData;
96 
97 private:
98  class DO_NOT_ACQUIRE{};
99 
100  OUString( rtl_uString * value, SAL_UNUSED_PARAMETER DO_NOT_ACQUIRE * )
101  {
102  pData = value;
103  }
104 
105 public:
110  {
111  pData = 0;
112  rtl_uString_new( &pData );
113  }
114 
120  OUString( const OUString & str ) SAL_THROW(())
121  {
122  pData = str.pData;
123  rtl_uString_acquire( pData );
124  }
125 
131  OUString( rtl_uString * str ) SAL_THROW(())
132  {
133  pData = str;
134  rtl_uString_acquire( pData );
135  }
136 
145  inline OUString( rtl_uString * str, __sal_NoAcquire ) SAL_THROW(())
146  { pData = str; }
147 
153  explicit OUString( sal_Unicode value ) SAL_THROW(())
154  : pData (0)
155  {
156  rtl_uString_newFromStr_WithLength( &pData, &value, 1 );
157  }
158 
164  OUString( const sal_Unicode * value ) SAL_THROW(())
165  {
166  pData = 0;
167  rtl_uString_newFromStr( &pData, value );
168  }
169 
178  OUString( const sal_Unicode * value, sal_Int32 length ) SAL_THROW(())
179  {
180  pData = 0;
181  rtl_uString_newFromStr_WithLength( &pData, value, length );
182  }
183 
199 #ifdef HAVE_SFINAE_ANONYMOUS_BROKEN
200  // Old gcc can try to convert anonymous enums to OUString and give compile error.
201  // So instead have a variant for const and non-const char[].
202  template< int N >
203  OUString( const char (&literal)[ N ] )
204  {
205  pData = 0;
206  rtl_uString_newFromLiteral( &pData, literal, N - 1, 0 );
207 #ifdef RTL_STRING_UNITTEST
208  rtl_string_unittest_const_literal = true;
209 #endif
210  }
211 
216  template< int N >
217  OUString( char (&value)[ N ] )
218 #ifndef RTL_STRING_UNITTEST
219  ; // intentionally not implemented
220 #else
221  {
222  (void) value; // unused
223  pData = 0;
224  rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
225  rtl_string_unittest_invalid_conversion = true;
226  }
227 #endif
228 #else // HAVE_SFINAE_ANONYMOUS_BROKEN
229  template< typename T >
231  {
232  pData = 0;
234 #ifdef RTL_STRING_UNITTEST
235  rtl_string_unittest_const_literal = true;
236 #endif
237  }
238 
239 #endif // HAVE_SFINAE_ANONYMOUS_BROKEN
240 
241 
242 #ifdef RTL_STRING_UNITTEST
243 
247  template< typename T >
249  {
250  pData = 0;
251  rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
252  rtl_string_unittest_invalid_conversion = true;
253  }
258  template< typename T >
259  OUString( const T&, typename internal::ExceptCharArrayDetector< T >::Type = internal::Dummy() )
260  {
261  pData = 0;
262  rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
263  rtl_string_unittest_invalid_conversion = true;
264  }
265 #endif
266 
281  OUString( const sal_Char * value, sal_Int32 length,
282  rtl_TextEncoding encoding,
283  sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS )
284  {
285  pData = 0;
286  rtl_string2UString( &pData, value, length, encoding, convertFlags );
287  if (pData == 0) {
288 #if defined EXCEPTIONS_OFF
289  abort();
290 #else
291  throw std::bad_alloc();
292 #endif
293  }
294  }
295 
312  inline explicit OUString(
313  sal_uInt32 const * codePoints, sal_Int32 codePointCount):
314  pData(NULL)
315  {
316  rtl_uString_newFromCodePoints(&pData, codePoints, codePointCount);
317  if (pData == NULL) {
318 #if defined EXCEPTIONS_OFF
319  abort();
320 #else
321  throw std::bad_alloc();
322 #endif
323  }
324  }
325 
330  {
331  rtl_uString_release( pData );
332  }
333 
345  static inline OUString const & unacquired( rtl_uString * const * ppHandle )
346  { return * reinterpret_cast< OUString const * >( ppHandle ); }
347 
353  OUString & operator=( const OUString & str ) SAL_THROW(())
354  {
355  rtl_uString_assign( &pData, str.pData );
356  return *this;
357  }
358 
371  template< typename T >
373  {
375  return *this;
376  }
377 
383  OUString & operator+=( const OUString & str ) SAL_THROW(())
384  {
385  rtl_uString_newConcat( &pData, pData, str.pData );
386  return *this;
387  }
388 
397  sal_Int32 getLength() const SAL_THROW(()) { return pData->length; }
398 
407  bool isEmpty() const SAL_THROW(())
408  {
409  return pData->length == 0;
410  }
411 
419  const sal_Unicode * getStr() const SAL_THROW(()) { return pData->buffer; }
420 
430  sal_Unicode operator [](sal_Int32 index) const { return getStr()[index]; }
431 
444  sal_Int32 compareTo( const OUString & str ) const SAL_THROW(())
445  {
446  return rtl_ustr_compare_WithLength( pData->buffer, pData->length,
447  str.pData->buffer, str.pData->length );
448  }
449 
465  sal_Int32 compareTo( const OUString & str, sal_Int32 maxLength ) const SAL_THROW(())
466  {
467  return rtl_ustr_shortenedCompare_WithLength( pData->buffer, pData->length,
468  str.pData->buffer, str.pData->length, maxLength );
469  }
470 
483  sal_Int32 reverseCompareTo( const OUString & str ) const SAL_THROW(())
484  {
485  return rtl_ustr_reverseCompare_WithLength( pData->buffer, pData->length,
486  str.pData->buffer, str.pData->length );
487  }
488 
500  sal_Bool equals( const OUString & str ) const SAL_THROW(())
501  {
502  if ( pData->length != str.pData->length )
503  return sal_False;
504  if ( pData == str.pData )
505  return sal_True;
506  return rtl_ustr_reverseCompare_WithLength( pData->buffer, pData->length,
507  str.pData->buffer, str.pData->length ) == 0;
508  }
509 
525  {
526  if ( pData->length != str.pData->length )
527  return sal_False;
528  if ( pData == str.pData )
529  return sal_True;
530  return rtl_ustr_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
531  str.pData->buffer, str.pData->length ) == 0;
532  }
533 
539  template< typename T >
541  {
542  if ( pData->length != internal::ConstCharArrayDetector< T, void >::size - 1 )
543  return sal_False;
544 
545  return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, literal ) == 0;
546  }
547 
563  sal_Bool match( const OUString & str, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
564  {
565  return rtl_ustr_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
566  str.pData->buffer, str.pData->length, str.pData->length ) == 0;
567  }
568 
574  template< typename T >
575  typename internal::ConstCharArrayDetector< T, bool >::Type match( T& literal, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
576  {
577  return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
579  }
580 
599  sal_Bool matchIgnoreAsciiCase( const OUString & str, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
600  {
601  return rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
602  str.pData->buffer, str.pData->length,
603  str.pData->length ) == 0;
604  }
605 
611  template< typename T >
612  typename internal::ConstCharArrayDetector< T, bool >::Type matchIgnoreAsciiCase( T& literal, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
613  {
614  return rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
616  }
617 
634  sal_Int32 compareToAscii( const sal_Char* asciiStr ) const SAL_THROW(())
635  {
636  return rtl_ustr_ascii_compare_WithLength( pData->buffer, pData->length, asciiStr );
637  }
638 
656  sal_Int32 compareToAscii( const sal_Char * asciiStr, sal_Int32 maxLength ) const SAL_THROW(())
657  {
658  return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer, pData->length,
659  asciiStr, maxLength );
660  }
661 
681  sal_Int32 reverseCompareToAsciiL( const sal_Char * asciiStr, sal_Int32 asciiStrLength ) const SAL_THROW(())
682  {
683  return rtl_ustr_asciil_reverseCompare_WithLength( pData->buffer, pData->length,
684  asciiStr, asciiStrLength );
685  }
686 
702  sal_Bool equalsAscii( const sal_Char* asciiStr ) const SAL_THROW(())
703  {
704  return rtl_ustr_ascii_compare_WithLength( pData->buffer, pData->length,
705  asciiStr ) == 0;
706  }
707 
725  sal_Bool equalsAsciiL( const sal_Char* asciiStr, sal_Int32 asciiStrLength ) const SAL_THROW(())
726  {
727  if ( pData->length != asciiStrLength )
728  return sal_False;
729 
731  pData->buffer, asciiStr, asciiStrLength );
732  }
733 
753  {
754  return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr ) == 0;
755  }
756 
775  sal_Int32 compareToIgnoreAsciiCaseAscii( const sal_Char * asciiStr ) const SAL_THROW(())
776  {
777  return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr );
778  }
779 
800  sal_Bool equalsIgnoreAsciiCaseAsciiL( const sal_Char * asciiStr, sal_Int32 asciiStrLength ) const SAL_THROW(())
801  {
802  if ( pData->length != asciiStrLength )
803  return sal_False;
804 
805  return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr ) == 0;
806  }
807 
829  sal_Bool matchAsciiL( const sal_Char* asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
830  {
831  return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
832  asciiStr, asciiStrLength ) == 0;
833  }
834 
835  // This overload is left undefined, to detect calls of matchAsciiL that
836  // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
837  // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
838  // platforms):
839 #if SAL_TYPES_SIZEOFLONG == 8
840  void matchAsciiL(char const *, sal_Int32, rtl_TextEncoding) const;
841 #endif
842 
867  sal_Bool matchIgnoreAsciiCaseAsciiL( const sal_Char* asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
868  {
869  return rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
870  asciiStr, asciiStrLength ) == 0;
871  }
872 
873  // This overload is left undefined, to detect calls of
874  // matchIgnoreAsciiCaseAsciiL that erroneously use
875  // RTL_CONSTASCII_USTRINGPARAM instead of RTL_CONSTASCII_STRINGPARAM (but
876  // would lead to ambiguities on 32 bit platforms):
877 #if SAL_TYPES_SIZEOFLONG == 8
878  void matchIgnoreAsciiCaseAsciiL(char const *, sal_Int32, rtl_TextEncoding)
879  const;
880 #endif
881 
892  bool endsWith(OUString const & str) const {
893  return str.getLength() <= getLength()
894  && match(str, getLength() - str.getLength());
895  }
896 
902  template< typename T >
904  {
905  return internal::ConstCharArrayDetector< T, void >::size - 1 <= pData->length
907  pData->buffer + pData->length - ( internal::ConstCharArrayDetector< T, void >::size - 1 ), literal,
909  }
910 
922  inline bool endsWithAsciiL(char const * asciiStr, sal_Int32 asciiStrLength)
923  const
924  {
925  return asciiStrLength <= pData->length
927  pData->buffer + pData->length - asciiStrLength, asciiStr,
928  asciiStrLength);
929  }
930 
945  {
946  return str.getLength() <= getLength()
947  && matchIgnoreAsciiCase(str, getLength() - str.getLength());
948  }
949 
955  template< typename T >
957  {
958  return internal::ConstCharArrayDetector< T, void >::size - 1 <= pData->length
960  pData->buffer + pData->length - ( internal::ConstCharArrayDetector< T, void >::size - 1 ),
963  == 0);
964  }
965 
977  char const * asciiStr, sal_Int32 asciiStrLength) const
978  {
979  return asciiStrLength <= pData->length
981  pData->buffer + pData->length - asciiStrLength,
982  asciiStrLength, asciiStr, asciiStrLength)
983  == 0);
984  }
985 
986  friend sal_Bool operator == ( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
987  { return rStr1.equals(rStr2); }
988  friend sal_Bool operator == ( const OUString& rStr1, const sal_Unicode * pStr2 ) SAL_THROW(())
989  { return rStr1.compareTo( pStr2 ) == 0; }
990  friend sal_Bool operator == ( const sal_Unicode * pStr1, const OUString& rStr2 ) SAL_THROW(())
991  { return OUString( pStr1 ).compareTo( rStr2 ) == 0; }
992 
993  friend sal_Bool operator != ( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
994  { return !(operator == ( rStr1, rStr2 )); }
995  friend sal_Bool operator != ( const OUString& rStr1, const sal_Unicode * pStr2 ) SAL_THROW(())
996  { return !(operator == ( rStr1, pStr2 )); }
997  friend sal_Bool operator != ( const sal_Unicode * pStr1, const OUString& rStr2 ) SAL_THROW(())
998  { return !(operator == ( pStr1, rStr2 )); }
999 
1000  friend sal_Bool operator < ( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
1001  { return rStr1.compareTo( rStr2 ) < 0; }
1002  friend sal_Bool operator > ( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
1003  { return rStr1.compareTo( rStr2 ) > 0; }
1004  friend sal_Bool operator <= ( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
1005  { return rStr1.compareTo( rStr2 ) <= 0; }
1006  friend sal_Bool operator >= ( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
1007  { return rStr1.compareTo( rStr2 ) >= 0; }
1008 
1016  template< typename T >
1017  friend inline typename internal::ConstCharArrayDetector< T, bool >::Type operator==( const OUString& string, T& literal )
1018  {
1019  return string.equalsAsciiL( literal, internal::ConstCharArrayDetector< T, void >::size - 1 );
1020  }
1028  template< typename T >
1029  friend inline typename internal::ConstCharArrayDetector< T, bool >::Type operator==( T& literal, const OUString& string )
1030  {
1031  return string.equalsAsciiL( literal, internal::ConstCharArrayDetector< T, void >::size - 1 );
1032  }
1040  template< typename T >
1041  friend inline typename internal::ConstCharArrayDetector< T, bool >::Type operator!=( const OUString& string, T& literal )
1042  {
1043  return !string.equalsAsciiL( literal, internal::ConstCharArrayDetector< T, void >::size - 1 );
1044  }
1052  template< typename T >
1053  friend inline typename internal::ConstCharArrayDetector< T, bool >::Type operator!=( T& literal, const OUString& string )
1054  {
1055  return !string.equalsAsciiL( literal, internal::ConstCharArrayDetector< T, void >::size - 1 );
1056  }
1057 
1065  sal_Int32 hashCode() const SAL_THROW(())
1066  {
1067  return rtl_ustr_hashCode_WithLength( pData->buffer, pData->length );
1068  }
1069 
1083  sal_Int32 indexOf( sal_Unicode ch, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
1084  {
1085  sal_Int32 ret = rtl_ustr_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
1086  return (ret < 0 ? ret : ret+fromIndex);
1087  }
1088 
1098  sal_Int32 lastIndexOf( sal_Unicode ch ) const SAL_THROW(())
1099  {
1100  return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
1101  }
1102 
1115  sal_Int32 lastIndexOf( sal_Unicode ch, sal_Int32 fromIndex ) const SAL_THROW(())
1116  {
1117  return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
1118  }
1119 
1135  sal_Int32 indexOf( const OUString & str, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
1136  {
1137  sal_Int32 ret = rtl_ustr_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1138  str.pData->buffer, str.pData->length );
1139  return (ret < 0 ? ret : ret+fromIndex);
1140  }
1141 
1147  template< typename T >
1148  typename internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
1149  {
1150  sal_Int32 ret = rtl_ustr_indexOfAscii_WithLength(
1151  pData->buffer + fromIndex, pData->length - fromIndex, literal,
1153  return ret < 0 ? ret : ret + fromIndex;
1154  }
1155 
1179  sal_Int32 indexOfAsciiL(
1180  char const * str, sal_Int32 len, sal_Int32 fromIndex = 0) const
1181  SAL_THROW(())
1182  {
1183  sal_Int32 ret = rtl_ustr_indexOfAscii_WithLength(
1184  pData->buffer + fromIndex, pData->length - fromIndex, str, len);
1185  return ret < 0 ? ret : ret + fromIndex;
1186  }
1187 
1188  // This overload is left undefined, to detect calls of indexOfAsciiL that
1189  // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
1190  // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
1191  // platforms):
1192 #if SAL_TYPES_SIZEOFLONG == 8
1193  void indexOfAsciiL(char const *, sal_Int32 len, rtl_TextEncoding) const;
1194 #endif
1195 
1211  sal_Int32 lastIndexOf( const OUString & str ) const SAL_THROW(())
1212  {
1213  return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, pData->length,
1214  str.pData->buffer, str.pData->length );
1215  }
1216 
1234  sal_Int32 lastIndexOf( const OUString & str, sal_Int32 fromIndex ) const SAL_THROW(())
1235  {
1236  return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
1237  str.pData->buffer, str.pData->length );
1238  }
1239 
1245  template< typename T >
1247  {
1249  pData->buffer, pData->length, literal, internal::ConstCharArrayDetector< T, void >::size - 1);
1250  }
1251 
1271  sal_Int32 lastIndexOfAsciiL(char const * str, sal_Int32 len) const
1272  SAL_THROW(())
1273  {
1275  pData->buffer, pData->length, str, len);
1276  }
1277 
1287  OUString copy( sal_Int32 beginIndex ) const SAL_THROW(())
1288  {
1289  assert(beginIndex >= 0 && beginIndex <= getLength());
1290  if ( beginIndex == 0 )
1291  return *this;
1292  else
1293  {
1294  rtl_uString* pNew = 0;
1295  rtl_uString_newFromStr_WithLength( &pNew, pData->buffer+beginIndex, getLength()-beginIndex );
1296  return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1297  }
1298  }
1299 
1311  OUString copy( sal_Int32 beginIndex, sal_Int32 count ) const SAL_THROW(())
1312  {
1313  assert(beginIndex >= 0 && beginIndex <= getLength() && count >= 0);
1314  if ( (beginIndex == 0) && (count == getLength()) )
1315  return *this;
1316  else
1317  {
1318  rtl_uString* pNew = 0;
1319  rtl_uString_newFromStr_WithLength( &pNew, pData->buffer+beginIndex, count );
1320  return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1321  }
1322  }
1323 
1332  OUString concat( const OUString & str ) const SAL_THROW(())
1333  {
1334  rtl_uString* pNew = 0;
1335  rtl_uString_newConcat( &pNew, pData, str.pData );
1336  return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1337  }
1338 
1339  friend OUString operator+( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
1340  {
1341  return rStr1.concat( rStr2 );
1342  }
1343 
1357  OUString replaceAt( sal_Int32 index, sal_Int32 count, const OUString& newStr ) const SAL_THROW(())
1358  {
1359  rtl_uString* pNew = 0;
1360  rtl_uString_newReplaceStrAt( &pNew, pData, index, count, newStr.pData );
1361  return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1362  }
1363 
1377  OUString replace( sal_Unicode oldChar, sal_Unicode newChar ) const SAL_THROW(())
1378  {
1379  rtl_uString* pNew = 0;
1380  rtl_uString_newReplace( &pNew, pData, oldChar, newChar );
1381  return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1382  }
1383 
1403  OUString const & from, OUString const & to, sal_Int32 * index = 0) const
1404  {
1405  rtl_uString * s = 0;
1406  sal_Int32 i = 0;
1408  &s, pData, from.pData, to.pData, index == 0 ? &i : index);
1409  return OUString(s, SAL_NO_ACQUIRE);
1410  }
1411 
1430  template< typename T >
1432  sal_Int32 * index = 0) const
1433  {
1434  rtl_uString * s = 0;
1435  sal_Int32 i = 0;
1437  &s, pData, from, internal::ConstCharArrayDetector< T, void >::size - 1, to.pData, index == 0 ? &i : index);
1438  return OUString(s, SAL_NO_ACQUIRE);
1439  }
1440 
1459  template< typename T1, typename T2 >
1461  replaceFirst( T1& from, T2& to, sal_Int32 * index = 0) const
1462  {
1463  rtl_uString * s = 0;
1464  sal_Int32 i = 0;
1466  &s, pData, from, internal::ConstCharArrayDetector< T1, void >::size - 1, to,
1467  internal::ConstCharArrayDetector< T2, void >::size - 1, index == 0 ? &i : index);
1468  return OUString(s, SAL_NO_ACQUIRE);
1469  }
1470 
1484  OUString replaceAll(OUString const & from, OUString const & to) const {
1485  rtl_uString * s = 0;
1486  rtl_uString_newReplaceAll(&s, pData, from.pData, to.pData);
1487  return OUString(s, SAL_NO_ACQUIRE);
1488  }
1489 
1503  template< typename T >
1505  {
1506  rtl_uString * s = 0;
1508  return OUString(s, SAL_NO_ACQUIRE);
1509  }
1510 
1524  template< typename T1, typename T2 >
1526  replaceAll( T1& from, T2& to ) const
1527  {
1528  rtl_uString * s = 0;
1532  return OUString(s, SAL_NO_ACQUIRE);
1533  }
1534 
1546  {
1547  rtl_uString* pNew = 0;
1548  rtl_uString_newToAsciiLowerCase( &pNew, pData );
1549  return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1550  }
1551 
1563  {
1564  rtl_uString* pNew = 0;
1565  rtl_uString_newToAsciiUpperCase( &pNew, pData );
1566  return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1567  }
1568 
1581  {
1582  rtl_uString* pNew = 0;
1583  rtl_uString_newTrim( &pNew, pData );
1584  return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1585  }
1586 
1611  OUString getToken( sal_Int32 token, sal_Unicode cTok, sal_Int32& index ) const SAL_THROW(())
1612  {
1613  rtl_uString * pNew = 0;
1614  index = rtl_uString_getToken( &pNew, pData, token, cTok, index );
1615  return OUString( pNew, (DO_NOT_ACQUIRE *)0 );
1616  }
1617 
1631  OUString getToken(sal_Int32 count, sal_Unicode separator) const {
1632  sal_Int32 n = 0;
1633  return getToken(count, separator, n);
1634  }
1635 
1645  {
1646  return rtl_ustr_toBoolean( pData->buffer );
1647  }
1648 
1656  {
1657  return pData->buffer[0];
1658  }
1659 
1669  sal_Int32 toInt32( sal_Int16 radix = 10 ) const SAL_THROW(())
1670  {
1671  return rtl_ustr_toInt32( pData->buffer, radix );
1672  }
1673 
1683  sal_Int64 toInt64( sal_Int16 radix = 10 ) const SAL_THROW(())
1684  {
1685  return rtl_ustr_toInt64( pData->buffer, radix );
1686  }
1687 
1696  float toFloat() const SAL_THROW(())
1697  {
1698  return rtl_ustr_toFloat( pData->buffer );
1699  }
1700 
1709  double toDouble() const SAL_THROW(())
1710  {
1711  return rtl_ustr_toDouble( pData->buffer );
1712  }
1713 
1714 
1731  {
1732  rtl_uString * pNew = 0;
1733  rtl_uString_intern( &pNew, pData );
1734  if (pNew == 0) {
1735 #if defined EXCEPTIONS_OFF
1736  abort();
1737 #else
1738  throw std::bad_alloc();
1739 #endif
1740  }
1741  return OUString( pNew, (DO_NOT_ACQUIRE *)0 );
1742  }
1743 
1769  static OUString intern( const sal_Char * value, sal_Int32 length,
1770  rtl_TextEncoding encoding,
1771  sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS,
1772  sal_uInt32 *pInfo = NULL )
1773  {
1774  rtl_uString * pNew = 0;
1775  rtl_uString_internConvert( &pNew, value, length, encoding,
1776  convertFlags, pInfo );
1777  if (pNew == 0) {
1778 #if defined EXCEPTIONS_OFF
1779  abort();
1780 #else
1781  throw std::bad_alloc();
1782 #endif
1783  }
1784  return OUString( pNew, (DO_NOT_ACQUIRE *)0 );
1785  }
1786 
1811  inline bool convertToString(OString * pTarget, rtl_TextEncoding nEncoding,
1812  sal_uInt32 nFlags) const
1813  {
1814  return rtl_convertUStringToString(&pTarget->pData, pData->buffer,
1815  pData->length, nEncoding, nFlags);
1816  }
1817 
1869  inline sal_uInt32 iterateCodePoints(
1870  sal_Int32 * indexUtf16, sal_Int32 incrementCodePoints = 1) const
1871  {
1873  pData, indexUtf16, incrementCodePoints);
1874  }
1875 
1887  {
1889  rtl_uString* pNewData = 0;
1890  rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfBoolean( aBuf, b ) );
1891  return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
1892  }
1893 
1901  {
1902  return OUString( &c, 1 );
1903  }
1904 
1914  static OUString valueOf( sal_Int32 i, sal_Int16 radix = 10 ) SAL_THROW(())
1915  {
1917  rtl_uString* pNewData = 0;
1918  rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfInt32( aBuf, i, radix ) );
1919  return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
1920  }
1921 
1931  static OUString valueOf( sal_Int64 ll, sal_Int16 radix = 10 ) SAL_THROW(())
1932  {
1934  rtl_uString* pNewData = 0;
1935  rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfInt64( aBuf, ll, radix ) );
1936  return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
1937  }
1938 
1947  static OUString valueOf( float f ) SAL_THROW(())
1948  {
1950  rtl_uString* pNewData = 0;
1951  rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfFloat( aBuf, f ) );
1952  return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
1953  }
1954 
1963  static OUString valueOf( double d ) SAL_THROW(())
1964  {
1966  rtl_uString* pNewData = 0;
1967  rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfDouble( aBuf, d ) );
1968  return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
1969  }
1970 
1986  static OUString createFromAscii( const sal_Char * value ) SAL_THROW(())
1987  {
1988  rtl_uString* pNew = 0;
1989  rtl_uString_newFromAscii( &pNew, value );
1990  return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1991  }
1992 };
1993 
1994 /* ======================================================================= */
1995 
1996 } /* Namespace */
1997 
1998 #ifdef RTL_STRING_UNITTEST
1999 namespace rtl
2000 {
2001 typedef rtlunittest::OUString OUString;
2002 }
2003 #endif
2004 
2005 namespace rtl
2006 {
2007 
2014 {
2024  size_t operator()(const OUString& rString) const
2025  { return (size_t)rString.hashCode(); }
2026 };
2027 
2028 /* ======================================================================= */
2029 
2047 inline OUString OStringToOUString( const OString & rStr,
2048  rtl_TextEncoding encoding,
2049  sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS )
2050 {
2051  return OUString( rStr.getStr(), rStr.getLength(), encoding, convertFlags );
2052 }
2053 
2071 inline OString OUStringToOString( const OUString & rUnicode,
2072  rtl_TextEncoding encoding,
2073  sal_uInt32 convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS )
2074 {
2075  return OString( rUnicode.getStr(), rUnicode.getLength(), encoding, convertFlags );
2076 }
2077 
2078 /* ======================================================================= */
2079 
2080 } /* Namespace */
2081 
2082 #endif /* _RTL_USTRING_HXX */
2083 
2084 // Include the ostream << operator directly here, so that it's always available
2085 // for SAL_INFO etc. Make sure it's outside of #ifdef _RTL_USTRING_HXX, because
2086 // includes ustring.hxx back.
2088 
2089 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */