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 
409  {
410  if ( pData->length )
411  return sal_False;
412  else
413  return sal_True;
414  }
415 
423  const sal_Unicode * getStr() const SAL_THROW(()) { return pData->buffer; }
424 
434  sal_Unicode operator [](sal_Int32 index) const { return getStr()[index]; }
435 
448  sal_Int32 compareTo( const OUString & str ) const SAL_THROW(())
449  {
450  return rtl_ustr_compare_WithLength( pData->buffer, pData->length,
451  str.pData->buffer, str.pData->length );
452  }
453 
469  sal_Int32 compareTo( const OUString & str, sal_Int32 maxLength ) const SAL_THROW(())
470  {
471  return rtl_ustr_shortenedCompare_WithLength( pData->buffer, pData->length,
472  str.pData->buffer, str.pData->length, maxLength );
473  }
474 
487  sal_Int32 reverseCompareTo( const OUString & str ) const SAL_THROW(())
488  {
489  return rtl_ustr_reverseCompare_WithLength( pData->buffer, pData->length,
490  str.pData->buffer, str.pData->length );
491  }
492 
504  sal_Bool equals( const OUString & str ) const SAL_THROW(())
505  {
506  if ( pData->length != str.pData->length )
507  return sal_False;
508  if ( pData == str.pData )
509  return sal_True;
510  return rtl_ustr_reverseCompare_WithLength( pData->buffer, pData->length,
511  str.pData->buffer, str.pData->length ) == 0;
512  }
513 
529  {
530  if ( pData->length != str.pData->length )
531  return sal_False;
532  if ( pData == str.pData )
533  return sal_True;
534  return rtl_ustr_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
535  str.pData->buffer, str.pData->length ) == 0;
536  }
537 
543  template< typename T >
545  {
546  if ( pData->length != internal::ConstCharArrayDetector< T, void >::size - 1 )
547  return sal_False;
548 
549  return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, literal ) == 0;
550  }
551 
567  sal_Bool match( const OUString & str, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
568  {
569  return rtl_ustr_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
570  str.pData->buffer, str.pData->length, str.pData->length ) == 0;
571  }
572 
578  template< typename T >
579  typename internal::ConstCharArrayDetector< T, bool >::Type match( T& literal, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
580  {
581  return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
583  }
584 
603  sal_Bool matchIgnoreAsciiCase( const OUString & str, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
604  {
605  return rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
606  str.pData->buffer, str.pData->length,
607  str.pData->length ) == 0;
608  }
609 
615  template< typename T >
616  typename internal::ConstCharArrayDetector< T, bool >::Type matchIgnoreAsciiCase( T& literal, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
617  {
618  return rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
620  }
621 
638  sal_Int32 compareToAscii( const sal_Char* asciiStr ) const SAL_THROW(())
639  {
640  return rtl_ustr_ascii_compare_WithLength( pData->buffer, pData->length, asciiStr );
641  }
642 
660  sal_Int32 compareToAscii( const sal_Char * asciiStr, sal_Int32 maxLength ) const SAL_THROW(())
661  {
662  return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer, pData->length,
663  asciiStr, maxLength );
664  }
665 
685  sal_Int32 reverseCompareToAsciiL( const sal_Char * asciiStr, sal_Int32 asciiStrLength ) const SAL_THROW(())
686  {
687  return rtl_ustr_asciil_reverseCompare_WithLength( pData->buffer, pData->length,
688  asciiStr, asciiStrLength );
689  }
690 
706  sal_Bool equalsAscii( const sal_Char* asciiStr ) const SAL_THROW(())
707  {
708  return rtl_ustr_ascii_compare_WithLength( pData->buffer, pData->length,
709  asciiStr ) == 0;
710  }
711 
729  sal_Bool equalsAsciiL( const sal_Char* asciiStr, sal_Int32 asciiStrLength ) const SAL_THROW(())
730  {
731  if ( pData->length != asciiStrLength )
732  return sal_False;
733 
735  pData->buffer, asciiStr, asciiStrLength );
736  }
737 
757  {
758  return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr ) == 0;
759  }
760 
779  sal_Int32 compareToIgnoreAsciiCaseAscii( const sal_Char * asciiStr ) const SAL_THROW(())
780  {
781  return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr );
782  }
783 
804  sal_Bool equalsIgnoreAsciiCaseAsciiL( const sal_Char * asciiStr, sal_Int32 asciiStrLength ) const SAL_THROW(())
805  {
806  if ( pData->length != asciiStrLength )
807  return sal_False;
808 
809  return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr ) == 0;
810  }
811 
833  sal_Bool matchAsciiL( const sal_Char* asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
834  {
835  return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
836  asciiStr, asciiStrLength ) == 0;
837  }
838 
839  // This overload is left undefined, to detect calls of matchAsciiL that
840  // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
841  // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
842  // platforms):
843 #if SAL_TYPES_SIZEOFLONG == 8
844  void matchAsciiL(char const *, sal_Int32, rtl_TextEncoding) const;
845 #endif
846 
871  sal_Bool matchIgnoreAsciiCaseAsciiL( const sal_Char* asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
872  {
873  return rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
874  asciiStr, asciiStrLength ) == 0;
875  }
876 
877  // This overload is left undefined, to detect calls of
878  // matchIgnoreAsciiCaseAsciiL that erroneously use
879  // RTL_CONSTASCII_USTRINGPARAM instead of RTL_CONSTASCII_STRINGPARAM (but
880  // would lead to ambiguities on 32 bit platforms):
881 #if SAL_TYPES_SIZEOFLONG == 8
882  void matchIgnoreAsciiCaseAsciiL(char const *, sal_Int32, rtl_TextEncoding)
883  const;
884 #endif
885 
896  bool endsWith(OUString const & str) const {
897  return str.getLength() <= getLength()
898  && match(str, getLength() - str.getLength());
899  }
900 
906  template< typename T >
908  {
909  return internal::ConstCharArrayDetector< T, void >::size - 1 <= pData->length
911  pData->buffer + pData->length - ( internal::ConstCharArrayDetector< T, void >::size - 1 ), literal,
913  }
914 
926  inline bool endsWithAsciiL(char const * asciiStr, sal_Int32 asciiStrLength)
927  const
928  {
929  return asciiStrLength <= pData->length
931  pData->buffer + pData->length - asciiStrLength, asciiStr,
932  asciiStrLength);
933  }
934 
949  {
950  return str.getLength() <= getLength()
951  && matchIgnoreAsciiCase(str, getLength() - str.getLength());
952  }
953 
959  template< typename T >
961  {
962  return internal::ConstCharArrayDetector< T, void >::size - 1 <= pData->length
964  pData->buffer + pData->length - ( internal::ConstCharArrayDetector< T, void >::size - 1 ),
967  == 0);
968  }
969 
981  char const * asciiStr, sal_Int32 asciiStrLength) const
982  {
983  return asciiStrLength <= pData->length
985  pData->buffer + pData->length - asciiStrLength,
986  asciiStrLength, asciiStr, asciiStrLength)
987  == 0);
988  }
989 
990  friend sal_Bool operator == ( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
991  { return rStr1.equals(rStr2); }
992  friend sal_Bool operator == ( const OUString& rStr1, const sal_Unicode * pStr2 ) SAL_THROW(())
993  { return rStr1.compareTo( pStr2 ) == 0; }
994  friend sal_Bool operator == ( const sal_Unicode * pStr1, const OUString& rStr2 ) SAL_THROW(())
995  { return OUString( pStr1 ).compareTo( rStr2 ) == 0; }
996 
997  friend sal_Bool operator != ( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
998  { return !(operator == ( rStr1, rStr2 )); }
999  friend sal_Bool operator != ( const OUString& rStr1, const sal_Unicode * pStr2 ) SAL_THROW(())
1000  { return !(operator == ( rStr1, pStr2 )); }
1001  friend sal_Bool operator != ( const sal_Unicode * pStr1, const OUString& rStr2 ) SAL_THROW(())
1002  { return !(operator == ( pStr1, rStr2 )); }
1003 
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  friend sal_Bool operator <= ( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
1009  { return rStr1.compareTo( rStr2 ) <= 0; }
1010  friend sal_Bool operator >= ( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
1011  { return rStr1.compareTo( rStr2 ) >= 0; }
1012 
1020  template< typename T >
1021  friend inline typename internal::ConstCharArrayDetector< T, bool >::Type operator==( const OUString& string, T& literal )
1022  {
1023  return string.equalsAsciiL( literal, internal::ConstCharArrayDetector< T, void >::size - 1 );
1024  }
1032  template< typename T >
1033  friend inline typename internal::ConstCharArrayDetector< T, bool >::Type operator==( T& literal, const OUString& string )
1034  {
1035  return string.equalsAsciiL( literal, internal::ConstCharArrayDetector< T, void >::size - 1 );
1036  }
1044  template< typename T >
1045  friend inline typename internal::ConstCharArrayDetector< T, bool >::Type operator!=( const OUString& string, T& literal )
1046  {
1047  return !string.equalsAsciiL( literal, internal::ConstCharArrayDetector< T, void >::size - 1 );
1048  }
1056  template< typename T >
1057  friend inline typename internal::ConstCharArrayDetector< T, bool >::Type operator!=( T& literal, const OUString& string )
1058  {
1059  return !string.equalsAsciiL( literal, internal::ConstCharArrayDetector< T, void >::size - 1 );
1060  }
1061 
1069  sal_Int32 hashCode() const SAL_THROW(())
1070  {
1071  return rtl_ustr_hashCode_WithLength( pData->buffer, pData->length );
1072  }
1073 
1087  sal_Int32 indexOf( sal_Unicode ch, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
1088  {
1089  sal_Int32 ret = rtl_ustr_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
1090  return (ret < 0 ? ret : ret+fromIndex);
1091  }
1092 
1102  sal_Int32 lastIndexOf( sal_Unicode ch ) const SAL_THROW(())
1103  {
1104  return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
1105  }
1106 
1119  sal_Int32 lastIndexOf( sal_Unicode ch, sal_Int32 fromIndex ) const SAL_THROW(())
1120  {
1121  return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
1122  }
1123 
1139  sal_Int32 indexOf( const OUString & str, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
1140  {
1141  sal_Int32 ret = rtl_ustr_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1142  str.pData->buffer, str.pData->length );
1143  return (ret < 0 ? ret : ret+fromIndex);
1144  }
1145 
1151  template< typename T >
1152  typename internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const SAL_THROW(())
1153  {
1154  sal_Int32 ret = rtl_ustr_indexOfAscii_WithLength(
1155  pData->buffer + fromIndex, pData->length - fromIndex, literal,
1157  return ret < 0 ? ret : ret + fromIndex;
1158  }
1159 
1183  sal_Int32 indexOfAsciiL(
1184  char const * str, sal_Int32 len, sal_Int32 fromIndex = 0) const
1185  SAL_THROW(())
1186  {
1187  sal_Int32 ret = rtl_ustr_indexOfAscii_WithLength(
1188  pData->buffer + fromIndex, pData->length - fromIndex, str, len);
1189  return ret < 0 ? ret : ret + fromIndex;
1190  }
1191 
1192  // This overload is left undefined, to detect calls of indexOfAsciiL that
1193  // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
1194  // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
1195  // platforms):
1196 #if SAL_TYPES_SIZEOFLONG == 8
1197  void indexOfAsciiL(char const *, sal_Int32 len, rtl_TextEncoding) const;
1198 #endif
1199 
1215  sal_Int32 lastIndexOf( const OUString & str ) const SAL_THROW(())
1216  {
1217  return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, pData->length,
1218  str.pData->buffer, str.pData->length );
1219  }
1220 
1238  sal_Int32 lastIndexOf( const OUString & str, sal_Int32 fromIndex ) const SAL_THROW(())
1239  {
1240  return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
1241  str.pData->buffer, str.pData->length );
1242  }
1243 
1249  template< typename T >
1251  {
1253  pData->buffer, pData->length, literal, internal::ConstCharArrayDetector< T, void >::size - 1);
1254  }
1255 
1275  sal_Int32 lastIndexOfAsciiL(char const * str, sal_Int32 len) const
1276  SAL_THROW(())
1277  {
1279  pData->buffer, pData->length, str, len);
1280  }
1281 
1291  OUString copy( sal_Int32 beginIndex ) const SAL_THROW(())
1292  {
1293  assert(beginIndex >= 0 && beginIndex <= getLength());
1294  if ( beginIndex == 0 )
1295  return *this;
1296  else
1297  {
1298  rtl_uString* pNew = 0;
1299  rtl_uString_newFromStr_WithLength( &pNew, pData->buffer+beginIndex, getLength()-beginIndex );
1300  return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1301  }
1302  }
1303 
1315  OUString copy( sal_Int32 beginIndex, sal_Int32 count ) const SAL_THROW(())
1316  {
1317  assert(beginIndex >= 0 && beginIndex <= getLength() && count >= 0);
1318  if ( (beginIndex == 0) && (count == getLength()) )
1319  return *this;
1320  else
1321  {
1322  rtl_uString* pNew = 0;
1323  rtl_uString_newFromStr_WithLength( &pNew, pData->buffer+beginIndex, count );
1324  return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1325  }
1326  }
1327 
1336  OUString concat( const OUString & str ) const SAL_THROW(())
1337  {
1338  rtl_uString* pNew = 0;
1339  rtl_uString_newConcat( &pNew, pData, str.pData );
1340  return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1341  }
1342 
1343  friend OUString operator+( const OUString& rStr1, const OUString& rStr2 ) SAL_THROW(())
1344  {
1345  return rStr1.concat( rStr2 );
1346  }
1347 
1361  OUString replaceAt( sal_Int32 index, sal_Int32 count, const OUString& newStr ) const SAL_THROW(())
1362  {
1363  rtl_uString* pNew = 0;
1364  rtl_uString_newReplaceStrAt( &pNew, pData, index, count, newStr.pData );
1365  return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1366  }
1367 
1381  OUString replace( sal_Unicode oldChar, sal_Unicode newChar ) const SAL_THROW(())
1382  {
1383  rtl_uString* pNew = 0;
1384  rtl_uString_newReplace( &pNew, pData, oldChar, newChar );
1385  return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1386  }
1387 
1407  OUString const & from, OUString const & to, sal_Int32 * index = 0) const
1408  {
1409  rtl_uString * s = 0;
1410  sal_Int32 i = 0;
1412  &s, pData, from.pData, to.pData, index == 0 ? &i : index);
1413  return OUString(s, SAL_NO_ACQUIRE);
1414  }
1415 
1434  template< typename T >
1436  sal_Int32 * index = 0) const
1437  {
1438  rtl_uString * s = 0;
1439  sal_Int32 i = 0;
1441  &s, pData, from, internal::ConstCharArrayDetector< T, void >::size - 1, to.pData, index == 0 ? &i : index);
1442  return OUString(s, SAL_NO_ACQUIRE);
1443  }
1444 
1463  template< typename T1, typename T2 >
1465  replaceFirst( T1& from, T2& to, sal_Int32 * index = 0) const
1466  {
1467  rtl_uString * s = 0;
1468  sal_Int32 i = 0;
1470  &s, pData, from, internal::ConstCharArrayDetector< T1, void >::size - 1, to,
1471  internal::ConstCharArrayDetector< T2, void >::size - 1, index == 0 ? &i : index);
1472  return OUString(s, SAL_NO_ACQUIRE);
1473  }
1474 
1488  OUString replaceAll(OUString const & from, OUString const & to) const {
1489  rtl_uString * s = 0;
1490  rtl_uString_newReplaceAll(&s, pData, from.pData, to.pData);
1491  return OUString(s, SAL_NO_ACQUIRE);
1492  }
1493 
1507  template< typename T >
1509  {
1510  rtl_uString * s = 0;
1512  return OUString(s, SAL_NO_ACQUIRE);
1513  }
1514 
1528  template< typename T1, typename T2 >
1530  replaceAll( T1& from, T2& to ) const
1531  {
1532  rtl_uString * s = 0;
1536  return OUString(s, SAL_NO_ACQUIRE);
1537  }
1538 
1550  {
1551  rtl_uString* pNew = 0;
1552  rtl_uString_newToAsciiLowerCase( &pNew, pData );
1553  return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1554  }
1555 
1567  {
1568  rtl_uString* pNew = 0;
1569  rtl_uString_newToAsciiUpperCase( &pNew, pData );
1570  return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1571  }
1572 
1585  {
1586  rtl_uString* pNew = 0;
1587  rtl_uString_newTrim( &pNew, pData );
1588  return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1589  }
1590 
1615  OUString getToken( sal_Int32 token, sal_Unicode cTok, sal_Int32& index ) const SAL_THROW(())
1616  {
1617  rtl_uString * pNew = 0;
1618  index = rtl_uString_getToken( &pNew, pData, token, cTok, index );
1619  return OUString( pNew, (DO_NOT_ACQUIRE *)0 );
1620  }
1621 
1635  OUString getToken(sal_Int32 count, sal_Unicode separator) const {
1636  sal_Int32 n = 0;
1637  return getToken(count, separator, n);
1638  }
1639 
1649  {
1650  return rtl_ustr_toBoolean( pData->buffer );
1651  }
1652 
1660  {
1661  return pData->buffer[0];
1662  }
1663 
1673  sal_Int32 toInt32( sal_Int16 radix = 10 ) const SAL_THROW(())
1674  {
1675  return rtl_ustr_toInt32( pData->buffer, radix );
1676  }
1677 
1687  sal_Int64 toInt64( sal_Int16 radix = 10 ) const SAL_THROW(())
1688  {
1689  return rtl_ustr_toInt64( pData->buffer, radix );
1690  }
1691 
1700  float toFloat() const SAL_THROW(())
1701  {
1702  return rtl_ustr_toFloat( pData->buffer );
1703  }
1704 
1713  double toDouble() const SAL_THROW(())
1714  {
1715  return rtl_ustr_toDouble( pData->buffer );
1716  }
1717 
1718 
1735  {
1736  rtl_uString * pNew = 0;
1737  rtl_uString_intern( &pNew, pData );
1738  if (pNew == 0) {
1739 #if defined EXCEPTIONS_OFF
1740  abort();
1741 #else
1742  throw std::bad_alloc();
1743 #endif
1744  }
1745  return OUString( pNew, (DO_NOT_ACQUIRE *)0 );
1746  }
1747 
1773  static OUString intern( const sal_Char * value, sal_Int32 length,
1774  rtl_TextEncoding encoding,
1775  sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS,
1776  sal_uInt32 *pInfo = NULL )
1777  {
1778  rtl_uString * pNew = 0;
1779  rtl_uString_internConvert( &pNew, value, length, encoding,
1780  convertFlags, pInfo );
1781  if (pNew == 0) {
1782 #if defined EXCEPTIONS_OFF
1783  abort();
1784 #else
1785  throw std::bad_alloc();
1786 #endif
1787  }
1788  return OUString( pNew, (DO_NOT_ACQUIRE *)0 );
1789  }
1790 
1815  inline bool convertToString(OString * pTarget, rtl_TextEncoding nEncoding,
1816  sal_uInt32 nFlags) const
1817  {
1818  return rtl_convertUStringToString(&pTarget->pData, pData->buffer,
1819  pData->length, nEncoding, nFlags);
1820  }
1821 
1873  inline sal_uInt32 iterateCodePoints(
1874  sal_Int32 * indexUtf16, sal_Int32 incrementCodePoints = 1) const
1875  {
1877  pData, indexUtf16, incrementCodePoints);
1878  }
1879 
1891  {
1893  rtl_uString* pNewData = 0;
1894  rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfBoolean( aBuf, b ) );
1895  return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
1896  }
1897 
1905  {
1906  return OUString( &c, 1 );
1907  }
1908 
1918  static OUString valueOf( sal_Int32 i, sal_Int16 radix = 10 ) SAL_THROW(())
1919  {
1921  rtl_uString* pNewData = 0;
1922  rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfInt32( aBuf, i, radix ) );
1923  return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
1924  }
1925 
1935  static OUString valueOf( sal_Int64 ll, sal_Int16 radix = 10 ) SAL_THROW(())
1936  {
1938  rtl_uString* pNewData = 0;
1939  rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfInt64( aBuf, ll, radix ) );
1940  return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
1941  }
1942 
1951  static OUString valueOf( float f ) SAL_THROW(())
1952  {
1954  rtl_uString* pNewData = 0;
1955  rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfFloat( aBuf, f ) );
1956  return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
1957  }
1958 
1967  static OUString valueOf( double d ) SAL_THROW(())
1968  {
1970  rtl_uString* pNewData = 0;
1971  rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfDouble( aBuf, d ) );
1972  return OUString( pNewData, (DO_NOT_ACQUIRE*)0 );
1973  }
1974 
1990  static OUString createFromAscii( const sal_Char * value ) SAL_THROW(())
1991  {
1992  rtl_uString* pNew = 0;
1993  rtl_uString_newFromAscii( &pNew, value );
1994  return OUString( pNew, (DO_NOT_ACQUIRE*)0 );
1995  }
1996 };
1997 
1998 /* ======================================================================= */
1999 
2000 } /* Namespace */
2001 
2002 #ifdef RTL_STRING_UNITTEST
2003 namespace rtl
2004 {
2005 typedef rtlunittest::OUString OUString;
2006 }
2007 #endif
2008 
2009 namespace rtl
2010 {
2011 
2018 {
2028  size_t operator()(const OUString& rString) const
2029  { return (size_t)rString.hashCode(); }
2030 };
2031 
2032 /* ======================================================================= */
2033 
2051 inline OUString OStringToOUString( const OString & rStr,
2052  rtl_TextEncoding encoding,
2053  sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS )
2054 {
2055  return OUString( rStr.getStr(), rStr.getLength(), encoding, convertFlags );
2056 }
2057 
2075 inline OString OUStringToOString( const OUString & rUnicode,
2076  rtl_TextEncoding encoding,
2077  sal_uInt32 convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS )
2078 {
2079  return OString( rUnicode.getStr(), rUnicode.getLength(), encoding, convertFlags );
2080 }
2081 
2082 /* ======================================================================= */
2083 
2084 } /* Namespace */
2085 
2086 #endif /* _RTL_USTRING_HXX */
2087 
2088 // Include the ostream << operator directly here, so that it's always available
2089 // for SAL_INFO etc. Make sure it's outside of #ifdef _RTL_USTRING_HXX, because
2090 // includes ustring.hxx back.
2092 
2093 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */