LibreOffice
LibreOffice 6.4 SDK C/C++ API Reference
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  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #ifndef INCLUDED_RTL_USTRING_HXX
21 #define INCLUDED_RTL_USTRING_HXX
22 
23 #include "sal/config.h"
24 
25 #include <cassert>
26 #include <cstddef>
27 #include <limits>
28 #include <new>
29 #include <ostream>
30 #include <utility>
31 
32 #if defined LIBO_INTERNAL_ONLY
33 #include <string_view>
34 #endif
35 
36 #include "rtl/ustring.h"
37 #include "rtl/string.hxx"
38 #include "rtl/stringutils.hxx"
39 #include "rtl/textenc.h"
40 
41 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
42 #include "rtl/stringconcat.hxx"
43 #endif
44 
45 #ifdef RTL_STRING_UNITTEST
46 extern bool rtl_string_unittest_invalid_conversion;
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 class OUStringBuffer;
62 
63 #ifdef RTL_STRING_UNITTEST
64 #undef rtl
65 #endif
66 
67 #if defined LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
68 
76 struct SAL_WARN_UNUSED OUStringLiteral
77 {
78  template<typename T> constexpr OUStringLiteral(
79  T & literal,
80  typename libreoffice_internal::ConstCharArrayDetector<
81  T, libreoffice_internal::Dummy>::Type
82  = libreoffice_internal::Dummy()):
83  size(libreoffice_internal::ConstCharArrayDetector<T>::length),
84  data(
85  libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal))
86  {
87  assert(
88  libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
89  }
90 
91  int size;
92  const char* data;
93 
94  // So we can use this struct in some places interchangeably with OUString
95  constexpr sal_Int32 getLength() const { return size; }
96 };
97 
99 #endif
100 
101 /* ======================================================================= */
102 
126 class SAL_WARN_UNUSED SAL_DLLPUBLIC_RTTI OUString
127 {
128 public:
130  rtl_uString * pData;
132 
137  {
138  pData = NULL;
139  rtl_uString_new( &pData );
140  }
141 
147  OUString( const OUString & str )
148  {
149  pData = str.pData;
150  rtl_uString_acquire( pData );
151  }
152 
153 #ifndef _MSC_VER // TODO?
154 #if defined LIBO_INTERNAL_ONLY
155 
161  OUString( OUString && str ) noexcept
162  {
163  pData = str.pData;
164  str.pData = nullptr;
165  rtl_uString_new( &str.pData );
166  }
167 #endif
168 #endif
169 
175  OUString( rtl_uString * str )
176  {
177  pData = str;
178  rtl_uString_acquire( pData );
179  }
180 
189  OUString( rtl_uString * str, __sal_NoAcquire )
190  { pData = str; }
191 
197  explicit OUString( sal_Unicode value )
198  : pData (NULL)
199  {
200  rtl_uString_newFromStr_WithLength( &pData, &value, 1 );
201  }
202 
203 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST_CONCAT
204  // Catch inadvertent conversions to the above ctor (but still allow
206  // construction from char literals):
207  OUString(int) = delete;
208  explicit OUString(char c):
209  OUString(sal_Unicode(static_cast<unsigned char>(c)))
210  {}
212 #endif
213 
219  OUString( const sal_Unicode * value )
220  {
221  pData = NULL;
222  rtl_uString_newFromStr( &pData, value );
223  }
224 
233  OUString( const sal_Unicode * value, sal_Int32 length )
234  {
235  pData = NULL;
236  rtl_uString_newFromStr_WithLength( &pData, value, length );
237  }
238 
254  template< typename T >
256  {
257  assert(
259  pData = NULL;
261  rtl_uString_new(&pData);
262  } else {
264  &pData,
266  literal),
268  }
269 #ifdef RTL_STRING_UNITTEST
270  rtl_string_unittest_const_literal = true;
271 #endif
272  }
273 
274 #if defined LIBO_INTERNAL_ONLY
275 
276  template<typename T> OUString(
277  T & literal,
279  T, libreoffice_internal::Dummy>::TypeUtf16
281  pData(nullptr)
282  {
284  rtl_uString_new(&pData);
285  } else {
287  &pData,
288  libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
289  literal),
290  libreoffice_internal::ConstCharArrayDetector<T>::length);
291  }
292  }
293 #endif
294 
295 #ifdef RTL_STRING_UNITTEST
296 
300  template< typename T >
301  OUString( T&, typename libreoffice_internal::ExceptConstCharArrayDetector< T >::Type = libreoffice_internal::Dummy() )
302  {
303  pData = NULL;
304  rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
305  rtl_string_unittest_invalid_conversion = true;
306  }
311  template< typename T >
312  OUString( const T&, typename libreoffice_internal::ExceptCharArrayDetector< T >::Type = libreoffice_internal::Dummy() )
313  {
314  pData = NULL;
315  rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
316  rtl_string_unittest_invalid_conversion = true;
317  }
318 #endif
319 
320 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
321 
337  OUString(OUStringLiteral literal): pData(NULL) {
338  rtl_uString_newFromLiteral(&pData, literal.data, literal.size, 0);
339  }
341 #endif
342 
357  OUString( const sal_Char * value, sal_Int32 length,
358  rtl_TextEncoding encoding,
359  sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS )
360  {
361  pData = NULL;
362  rtl_string2UString( &pData, value, length, encoding, convertFlags );
363  if (pData == NULL) {
364  throw std::bad_alloc();
365  }
366  }
367 
384  explicit OUString(
385  sal_uInt32 const * codePoints, sal_Int32 codePointCount):
386  pData(NULL)
387  {
388  rtl_uString_newFromCodePoints(&pData, codePoints, codePointCount);
389  if (pData == NULL) {
390  throw std::bad_alloc();
391  }
392  }
393 
394 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
395 
399  template< typename T1, typename T2 >
400  OUString( OUStringConcat< T1, T2 >&& c )
401  {
402  const sal_Int32 l = c.length();
403  pData = rtl_uString_alloc( l );
404  if (l != 0)
405  {
406  sal_Unicode* end = c.addData( pData->buffer );
407  pData->length = l;
408  *end = '\0';
409  // TODO realloc in case pData->length is noticeably smaller than l?
410  }
411  }
412 
417  template< typename T >
418  OUString( OUStringNumber< T >&& n )
419  : OUString( n.buf, n.length )
420  {}
421 #endif
422 
423 #if defined LIBO_INTERNAL_ONLY
424  OUString(std::u16string_view sv) {
425  if (sv.size() > sal_uInt32(std::numeric_limits<sal_Int32>::max())) {
426  throw std::bad_alloc();
427  }
428  pData = nullptr;
429  rtl_uString_newFromStr_WithLength(&pData, sv.data(), sv.size());
430  }
431 #endif
432 
437  {
438  rtl_uString_release( pData );
439  }
440 
452  static OUString const & unacquired( rtl_uString * const * ppHandle )
453  { return * reinterpret_cast< OUString const * >( ppHandle ); }
454 
460  OUString & operator=( const OUString & str )
461  {
462  rtl_uString_assign( &pData, str.pData );
463  return *this;
464  }
465 
466 #ifndef _MSC_VER // TODO?
467 #if defined LIBO_INTERNAL_ONLY
468 
474  OUString & operator=( OUString && str ) noexcept
475  {
476  rtl_uString_release( pData );
477  pData = str.pData;
478  str.pData = nullptr;
479  rtl_uString_new( &str.pData );
480  return *this;
481  }
482 #endif
483 #endif
484 
497  template< typename T >
499  {
500  assert(
503  rtl_uString_new(&pData);
504  } else {
506  &pData,
508  literal),
510  }
511  return *this;
512  }
513 
514 #if defined LIBO_INTERNAL_ONLY
515 
516  template<typename T>
517  typename
519  operator =(T & literal) {
521  rtl_uString_new(&pData);
522  } else {
524  &pData,
525  libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
526  literal),
527  libreoffice_internal::ConstCharArrayDetector<T>::length);
528  }
529  return *this;
530  }
531 
533  OUString & operator =(OUStringLiteral const & literal) {
534  if (literal.size == 0) {
535  rtl_uString_new(&pData);
536  } else {
537  rtl_uString_newFromLiteral(&pData, literal.data, literal.size, 0);
538  }
539  return *this;
540  }
541 #endif
542 
543 #if defined LIBO_INTERNAL_ONLY
544 
552  inline OUString & operator+=( const OUStringBuffer & str ) &;
553 #endif
554 
562  OUString & operator+=( const OUString & str )
563 #if defined LIBO_INTERNAL_ONLY
564  &
565 #endif
566  {
567  return internalAppend(str.pData);
568  }
569 #if defined LIBO_INTERNAL_ONLY
570  void operator+=(OUString const &) && = delete;
571 #endif
572 
579  template<typename T>
581  operator +=(T & literal)
582 #if defined LIBO_INTERNAL_ONLY
583  &
584 #endif
585  {
586  assert(
589  &pData, pData,
592  return *this;
593  }
594 #if defined LIBO_INTERNAL_ONLY
595  template<typename T>
597  operator +=(T &) && = delete;
598 #endif
599 
600 #if defined LIBO_INTERNAL_ONLY
601 
602  template<typename T>
603  typename
605  operator +=(T & literal) & {
607  &pData, pData,
610  return *this;
611  }
612  template<typename T>
613  typename
614  libreoffice_internal::ConstCharArrayDetector<T, OUString &>::TypeUtf16
615  operator +=(T &) && = delete;
616 
618  OUString & operator +=(OUStringLiteral const & literal) & {
619  rtl_uString_newConcatAsciiL(&pData, pData, literal.data, literal.size);
620  return *this;
621  }
622  void operator +=(OUStringLiteral const &) && = delete;
623 #endif
624 
625 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
626 
630  template< typename T1, typename T2 >
631  OUString& operator+=( OUStringConcat< T1, T2 >&& c ) & {
632  sal_Int32 l = c.length();
633  if( l == 0 )
634  return *this;
635  l += pData->length;
636  rtl_uString_ensureCapacity( &pData, l );
637  sal_Unicode* end = c.addData( pData->buffer + pData->length );
638  *end = '\0';
639  pData->length = l;
640  return *this;
641  }
642  template<typename T1, typename T2> void operator +=(
643  OUStringConcat<T1, T2> &&) && = delete;
644 
649  template< typename T >
650  OUString& operator+=( OUStringNumber< T >&& n ) & {
651  sal_Int32 l = n.length;
652  if( l == 0 )
653  return *this;
654  l += pData->length;
655  rtl_uString_ensureCapacity( &pData, l );
656  sal_Unicode* end = addDataHelper( pData->buffer + pData->length, n.buf, n.length );
657  *end = '\0';
658  pData->length = l;
659  return *this;
660  }
661  template<typename T> void operator +=(
662  OUStringNumber<T> &&) && = delete;
663 #endif
664 
669  void clear()
670  {
671  rtl_uString_new( &pData );
672  }
673 
682  sal_Int32 getLength() const { return pData->length; }
683 
692  bool isEmpty() const
693  {
694  return pData->length == 0;
695  }
696 
704  const sal_Unicode * getStr() const SAL_RETURNS_NONNULL { return pData->buffer; }
705 
715  sal_Unicode operator [](sal_Int32 index) const {
716  // silence spurious -Werror=strict-overflow warnings from GCC 4.8.2
717  assert(index >= 0 && static_cast<sal_uInt32>(index) < static_cast<sal_uInt32>(getLength()));
718  return getStr()[index];
719  }
720 
733  sal_Int32 compareTo( const OUString & str ) const
734  {
735  return rtl_ustr_compare_WithLength( pData->buffer, pData->length,
736  str.pData->buffer, str.pData->length );
737  }
738 
754  sal_Int32 compareTo( const OUString & str, sal_Int32 maxLength ) const
755  {
756  return rtl_ustr_shortenedCompare_WithLength( pData->buffer, pData->length,
757  str.pData->buffer, str.pData->length, maxLength );
758  }
759 
772  sal_Int32 reverseCompareTo( const OUString & str ) const
773  {
774  return rtl_ustr_reverseCompare_WithLength( pData->buffer, pData->length,
775  str.pData->buffer, str.pData->length );
776  }
777 
783  template< typename T >
785  {
786  assert(
789  pData->buffer, pData->length,
792  }
793 
794 #if defined LIBO_INTERNAL_ONLY
795 
796  template<typename T>
797  typename
799  reverseCompareTo(T & literal) const {
801  pData->buffer, pData->length,
804  }
805 
807  sal_Int32 reverseCompareTo(OUStringLiteral const & literal) const {
809  pData->buffer, pData->length, literal.data, literal.size);
810  }
811 #endif
812 
824  bool equals( const OUString & str ) const
825  {
826  if ( pData->length != str.pData->length )
827  return false;
828  if ( pData == str.pData )
829  return true;
830  return rtl_ustr_reverseCompare_WithLength( pData->buffer, pData->length,
831  str.pData->buffer, str.pData->length ) == 0;
832  }
833 
848  bool equalsIgnoreAsciiCase( const OUString & str ) const
849  {
850  if ( pData->length != str.pData->length )
851  return false;
852  if ( pData == str.pData )
853  return true;
854  return rtl_ustr_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
855  str.pData->buffer, str.pData->length ) == 0;
856  }
857 
873  sal_Int32 compareToIgnoreAsciiCase( const OUString & str ) const
874  {
875  return rtl_ustr_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
876  str.pData->buffer, str.pData->length );
877  }
878 
879 
885  template< typename T >
887  {
888  assert(
890  return
891  (pData->length
894  pData->buffer, pData->length,
896  literal))
897  == 0);
898  }
899 
900 #if defined LIBO_INTERNAL_ONLY
901 
902  template<typename T>
904  equalsIgnoreAsciiCase(T & literal) const {
905  return
907  pData->buffer, pData->length,
909  literal),
911  == 0;
912  }
913 
915  bool equalsIgnoreAsciiCase(OUStringLiteral const & literal) const {
916  return pData->length == literal.size
918  pData->buffer, pData->length, literal.data)
919  == 0);
920  }
921 #endif
922 
938  bool match( const OUString & str, sal_Int32 fromIndex = 0 ) const
939  {
940  return rtl_ustr_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
941  str.pData->buffer, str.pData->length, str.pData->length ) == 0;
942  }
943 
949  template< typename T >
950  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type match( T& literal, sal_Int32 fromIndex = 0 ) const
951  {
952  assert(
954  return
956  pData->buffer+fromIndex, pData->length-fromIndex,
958  literal),
960  == 0;
961  }
962 
963 #if defined LIBO_INTERNAL_ONLY
964 
965  template<typename T>
967  match(T & literal, sal_Int32 fromIndex = 0) const {
968  assert(fromIndex >= 0);
969  return
971  pData->buffer + fromIndex, pData->length - fromIndex,
973  literal),
976  == 0;
977  }
978 
980  bool match(OUStringLiteral const & literal, sal_Int32 fromIndex = 0) const {
981  return
983  pData->buffer + fromIndex, pData->length - fromIndex,
984  literal.data, literal.size)
985  == 0;
986  }
987 #endif
988 
1007  bool matchIgnoreAsciiCase( const OUString & str, sal_Int32 fromIndex = 0 ) const
1008  {
1009  return rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1010  str.pData->buffer, str.pData->length,
1011  str.pData->length ) == 0;
1012  }
1013 
1019  template< typename T >
1020  typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type matchIgnoreAsciiCase( T& literal, sal_Int32 fromIndex = 0 ) const
1021  {
1022  assert(
1024  return
1026  pData->buffer+fromIndex, pData->length-fromIndex,
1028  literal),
1030  == 0;
1031  }
1032 
1033 #if defined LIBO_INTERNAL_ONLY
1034 
1035  template<typename T>
1037  matchIgnoreAsciiCase(T & literal, sal_Int32 fromIndex = 0) const {
1038  assert(fromIndex >= 0);
1039  return
1041  pData->buffer + fromIndex, pData->length - fromIndex,
1043  literal),
1046  == 0;
1047  }
1048 
1050  bool matchIgnoreAsciiCase(
1051  OUStringLiteral const & literal, sal_Int32 fromIndex = 0) const
1052  {
1053  return
1055  pData->buffer+fromIndex, pData->length-fromIndex, literal.data,
1056  literal.size)
1057  == 0;
1058  }
1059 #endif
1060 
1077  sal_Int32 compareToAscii( const sal_Char* asciiStr ) const
1078  {
1079  return rtl_ustr_ascii_compare_WithLength( pData->buffer, pData->length, asciiStr );
1080  }
1081 
1105  "replace s1.compareToAscii(s2, strlen(s2)) == 0 with s1.startsWith(s2)")
1106  sal_Int32 compareToAscii( const sal_Char * asciiStr, sal_Int32 maxLength ) const
1107  {
1108  return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer, pData->length,
1109  asciiStr, maxLength );
1110  }
1111 
1131  sal_Int32 reverseCompareToAsciiL( const sal_Char * asciiStr, sal_Int32 asciiStrLength ) const
1132  {
1133  return rtl_ustr_asciil_reverseCompare_WithLength( pData->buffer, pData->length,
1134  asciiStr, asciiStrLength );
1135  }
1136 
1152  bool equalsAscii( const sal_Char* asciiStr ) const
1153  {
1154  return rtl_ustr_ascii_compare_WithLength( pData->buffer, pData->length,
1155  asciiStr ) == 0;
1156  }
1157 
1175  bool equalsAsciiL( const sal_Char* asciiStr, sal_Int32 asciiStrLength ) const
1176  {
1177  if ( pData->length != asciiStrLength )
1178  return false;
1179 
1181  pData->buffer, asciiStr, asciiStrLength );
1182  }
1183 
1202  bool equalsIgnoreAsciiCaseAscii( const sal_Char * asciiStr ) const
1203  {
1204  return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr ) == 0;
1205  }
1206 
1225  sal_Int32 compareToIgnoreAsciiCaseAscii( const sal_Char * asciiStr ) const
1226  {
1227  return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr );
1228  }
1229 
1250  bool equalsIgnoreAsciiCaseAsciiL( const sal_Char * asciiStr, sal_Int32 asciiStrLength ) const
1251  {
1252  if ( pData->length != asciiStrLength )
1253  return false;
1254 
1255  return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr ) == 0;
1256  }
1257 
1279  bool matchAsciiL( const sal_Char* asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex = 0 ) const
1280  {
1281  return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1282  asciiStr, asciiStrLength ) == 0;
1283  }
1284 
1285  // This overload is left undefined, to detect calls of matchAsciiL that
1286  // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
1287  // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
1288  // platforms):
1289 #if SAL_TYPES_SIZEOFLONG == 8
1290  void matchAsciiL(char const *, sal_Int32, rtl_TextEncoding) const;
1291 #endif
1292 
1317  bool matchIgnoreAsciiCaseAsciiL( const sal_Char* asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex = 0 ) const
1318  {
1319  return rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1320  asciiStr, asciiStrLength ) == 0;
1321  }
1322 
1323  // This overload is left undefined, to detect calls of
1324  // matchIgnoreAsciiCaseAsciiL that erroneously use
1325  // RTL_CONSTASCII_USTRINGPARAM instead of RTL_CONSTASCII_STRINGPARAM (but
1326  // would lead to ambiguities on 32 bit platforms):
1327 #if SAL_TYPES_SIZEOFLONG == 8
1328  void matchIgnoreAsciiCaseAsciiL(char const *, sal_Int32, rtl_TextEncoding)
1329  const;
1330 #endif
1331 
1346  bool startsWith(OUString const & str, OUString * rest = NULL) const {
1347  bool b = match(str);
1348  if (b && rest != NULL) {
1349  *rest = copy(str.getLength());
1350  }
1351  return b;
1352  }
1353 
1359  template< typename T >
1361  T & literal, OUString * rest = NULL) const
1362  {
1363  assert(
1365  bool b
1367  <= sal_uInt32(pData->length))
1369  pData->buffer,
1371  literal),
1373  if (b && rest != NULL) {
1374  *rest = copy(
1376  }
1377  return b;
1378  }
1379 
1380 #if defined LIBO_INTERNAL_ONLY
1381 
1382  template<typename T>
1384  startsWith(T & literal, OUString * rest = nullptr) const {
1385  bool b
1387  <= sal_uInt32(pData->length))
1389  pData->buffer,
1392  literal),
1394  == 0);
1395  if (b && rest != nullptr) {
1396  *rest = copy(
1398  }
1399  return b;
1400  }
1401 
1403  bool startsWith(OUStringLiteral const & literal, OUString * rest = nullptr)
1404  const
1405  {
1406  bool b = literal.size <= pData->length
1408  pData->buffer, literal.data, literal.size);
1409  if (b && rest != nullptr) {
1410  *rest = copy(literal.size);
1411  }
1412  return b;
1413  }
1414 #endif
1415 
1436  bool startsWithIgnoreAsciiCase(OUString const & str, OUString * rest = NULL)
1437  const
1438  {
1439  bool b = matchIgnoreAsciiCase(str);
1440  if (b && rest != NULL) {
1441  *rest = copy(str.getLength());
1442  }
1443  return b;
1444  }
1445 
1451  template< typename T >
1453  startsWithIgnoreAsciiCase(T & literal, OUString * rest = NULL) const
1454  {
1455  assert(
1457  bool b
1459  pData->buffer,
1462  literal),
1464  == 0);
1465  if (b && rest != NULL) {
1466  *rest = copy(
1468  }
1469  return b;
1470  }
1471 
1472 #if defined LIBO_INTERNAL_ONLY
1473 
1474  template<typename T>
1476  startsWithIgnoreAsciiCase(T & literal, OUString * rest = nullptr) const {
1477  bool b
1479  <= sal_uInt32(pData->length))
1481  pData->buffer,
1484  literal),
1486  == 0);
1487  if (b && rest != nullptr) {
1488  *rest = copy(
1490  }
1491  return b;
1492  }
1493 
1495  bool startsWithIgnoreAsciiCase(
1496  OUStringLiteral const & literal, OUString * rest = nullptr) const
1497  {
1498  bool b
1500  pData->buffer, literal.size, literal.data, literal.size)
1501  == 0);
1502  if (b && rest != nullptr) {
1503  *rest = copy(literal.size);
1504  }
1505  return b;
1506  }
1507 #endif
1508 
1523  bool endsWith(OUString const & str, OUString * rest = NULL) const {
1524  bool b = str.getLength() <= getLength()
1525  && match(str, getLength() - str.getLength());
1526  if (b && rest != NULL) {
1527  *rest = copy(0, getLength() - str.getLength());
1528  }
1529  return b;
1530  }
1531 
1537  template< typename T >
1539  endsWith(T & literal, OUString * rest = NULL) const
1540  {
1541  assert(
1543  bool b
1545  <= sal_uInt32(pData->length))
1547  (pData->buffer + pData->length
1550  literal),
1552  if (b && rest != NULL) {
1553  *rest = copy(
1554  0,
1555  (getLength()
1557  }
1558  return b;
1559  }
1560 
1561 #if defined LIBO_INTERNAL_ONLY
1562 
1563  template<typename T>
1565  endsWith(T & literal, OUString * rest = nullptr) const {
1566  bool b
1568  <= sal_uInt32(pData->length))
1570  (pData->buffer + pData->length
1574  literal),
1576  == 0);
1577  if (b && rest != nullptr) {
1578  *rest = copy(
1579  0,
1580  (getLength()
1582  }
1583  return b;
1584  }
1585 
1587  bool endsWith(OUStringLiteral const & literal, OUString * rest = nullptr)
1588  const
1589  {
1590  bool b = literal.size <= pData->length
1592  pData->buffer + pData->length - literal.size,
1593  literal.data, literal.size);
1594  if (b && rest != nullptr) {
1595  *rest = copy(0, (getLength() - literal.size));
1596  }
1597  return b;
1598  }
1599 #endif
1600 
1612  bool endsWithAsciiL(char const * asciiStr, sal_Int32 asciiStrLength)
1613  const
1614  {
1615  return asciiStrLength <= pData->length
1617  pData->buffer + pData->length - asciiStrLength, asciiStr,
1618  asciiStrLength);
1619  }
1620 
1641  bool endsWithIgnoreAsciiCase(OUString const & str, OUString * rest = NULL) const
1642  {
1643  bool b = str.getLength() <= getLength()
1644  && matchIgnoreAsciiCase(str, getLength() - str.getLength());
1645  if (b && rest != NULL) {
1646  *rest = copy(0, getLength() - str.getLength());
1647  }
1648  return b;
1649  }
1650 
1656  template< typename T >
1658  endsWithIgnoreAsciiCase(T & literal, OUString * rest = NULL) const
1659  {
1660  assert(
1662  bool b
1664  <= sal_uInt32(pData->length))
1666  (pData->buffer + pData->length
1670  literal),
1672  == 0);
1673  if (b && rest != NULL) {
1674  *rest = copy(
1675  0,
1676  (getLength()
1678  }
1679  return b;
1680  }
1681 
1682 #if defined LIBO_INTERNAL_ONLY
1683 
1684  template<typename T>
1686  endsWithIgnoreAsciiCase(T & literal, OUString * rest = nullptr) const {
1687  bool b
1689  <= sal_uInt32(pData->length))
1691  (pData->buffer + pData->length
1695  literal),
1697  == 0);
1698  if (b && rest != nullptr) {
1699  *rest = copy(
1700  0,
1701  (getLength()
1703  }
1704  return b;
1705  }
1706 
1708  bool endsWithIgnoreAsciiCase(
1709  OUStringLiteral const & literal, OUString * rest = nullptr) const
1710  {
1711  bool b = literal.size <= pData->length
1713  pData->buffer + pData->length - literal.size,
1714  literal.size, literal.data, literal.size)
1715  == 0);
1716  if (b && rest != nullptr) {
1717  *rest = copy(0, getLength() - literal.size);
1718  }
1719  return b;
1720  }
1721 #endif
1722 
1734  char const * asciiStr, sal_Int32 asciiStrLength) const
1735  {
1736  return asciiStrLength <= pData->length
1738  pData->buffer + pData->length - asciiStrLength,
1739  asciiStrLength, asciiStr, asciiStrLength)
1740  == 0);
1741  }
1742 
1743  friend bool operator == ( const OUString& rStr1, const OUString& rStr2 )
1744  { return rStr1.equals(rStr2); }
1745  friend bool operator == ( const OUString& rStr1, const sal_Unicode * pStr2 )
1746  { return rStr1.compareTo( pStr2 ) == 0; }
1747  friend bool operator == ( const sal_Unicode * pStr1, const OUString& rStr2 )
1748  { return OUString( pStr1 ).compareTo( rStr2 ) == 0; }
1749 
1750  friend bool operator != ( const OUString& rStr1, const OUString& rStr2 )
1751  { return !(operator == ( rStr1, rStr2 )); }
1752  friend bool operator != ( const OUString& rStr1, const sal_Unicode * pStr2 )
1753  { return !(operator == ( rStr1, pStr2 )); }
1754  friend bool operator != ( const sal_Unicode * pStr1, const OUString& rStr2 )
1755  { return !(operator == ( pStr1, rStr2 )); }
1756 
1757  friend bool operator < ( const OUString& rStr1, const OUString& rStr2 )
1758  { return rStr1.compareTo( rStr2 ) < 0; }
1759  friend bool operator > ( const OUString& rStr1, const OUString& rStr2 )
1760  { return rStr1.compareTo( rStr2 ) > 0; }
1761  friend bool operator <= ( const OUString& rStr1, const OUString& rStr2 )
1762  { return rStr1.compareTo( rStr2 ) <= 0; }
1763  friend bool operator >= ( const OUString& rStr1, const OUString& rStr2 )
1764  { return rStr1.compareTo( rStr2 ) >= 0; }
1765 
1773  template< typename T >
1775  {
1776  assert(
1778  return rString.equalsAsciiL(
1781  }
1789  template< typename T >
1791  {
1792  assert(
1794  return rString.equalsAsciiL(
1797  }
1805  template< typename T >
1807  {
1808  assert(
1810  return !rString.equalsAsciiL(
1813  }
1821  template< typename T >
1823  {
1824  assert(
1826  return !rString.equalsAsciiL(
1829  }
1830 
1831 #if defined LIBO_INTERNAL_ONLY
1832 
1833  template<typename T> friend typename libreoffice_internal::ConstCharArrayDetector<T, bool>::TypeUtf16
1834  operator ==(OUString & string, T & literal) {
1835  return
1837  string.pData->buffer, string.pData->length,
1839  literal),
1841  == 0;
1842  }
1844  template<typename T> friend typename libreoffice_internal::ConstCharArrayDetector<T, bool>::TypeUtf16
1845  operator ==(T & literal, OUString & string) {
1846  return
1848  libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
1849  literal),
1850  libreoffice_internal::ConstCharArrayDetector<T>::length,
1851  string.pData->buffer, string.pData->length)
1852  == 0;
1853  }
1855  template<typename T> friend typename libreoffice_internal::ConstCharArrayDetector<T, bool>::TypeUtf16
1856  operator !=(OUString & string, T & literal) {
1857  return
1859  string.pData->buffer, string.pData->length,
1860  libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
1861  literal),
1862  libreoffice_internal::ConstCharArrayDetector<T>::length)
1863  != 0;
1864  }
1866  template<typename T> friend typename libreoffice_internal::ConstCharArrayDetector<T, bool>::TypeUtf16
1867  operator !=(T & literal, OUString & string) {
1868  return
1870  libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
1871  literal),
1872  libreoffice_internal::ConstCharArrayDetector<T>::length,
1873  string.pData->buffer, string.pData->length)
1874  != 0;
1875  }
1876 #endif
1877 
1878 #if defined LIBO_INTERNAL_ONLY
1879 
1881  /* Comparison between OUString and OUStringLiteral.
1882 
1883  @since LibreOffice 5.0
1884  */
1885 
1886  friend bool operator ==(OUString const & lhs, OUStringLiteral const & rhs) {
1887  return lhs.equalsAsciiL(rhs.data, rhs.size);
1888  }
1889 
1890  friend bool operator !=(OUString const & lhs, OUStringLiteral const & rhs) {
1891  return !lhs.equalsAsciiL(rhs.data, rhs.size);
1892  }
1893 
1894  friend bool operator <(OUString const & lhs, OUStringLiteral const & rhs) {
1895  return
1897  lhs.pData->buffer, lhs.pData->length, rhs.data))
1898  < 0;
1899  }
1900 
1901  friend bool operator <=(OUString const & lhs, OUStringLiteral const & rhs) {
1902  return
1904  lhs.pData->buffer, lhs.pData->length, rhs.data))
1905  <= 0;
1906  }
1907 
1908  friend bool operator >(OUString const & lhs, OUStringLiteral const & rhs) {
1909  return
1911  lhs.pData->buffer, lhs.pData->length, rhs.data))
1912  > 0;
1913  }
1914 
1915  friend bool operator >=(OUString const & lhs, OUStringLiteral const & rhs) {
1916  return
1918  lhs.pData->buffer, lhs.pData->length, rhs.data))
1919  >= 0;
1920  }
1921 
1922  friend bool operator ==(OUStringLiteral const & lhs, OUString const & rhs) {
1923  return rhs.equalsAsciiL(lhs.data, lhs.size);
1924  }
1925 
1926  friend bool operator !=(OUStringLiteral const & lhs, OUString const & rhs) {
1927  return !rhs.equalsAsciiL(lhs.data, lhs.size);
1928  }
1929 
1930  friend bool operator <(OUStringLiteral const & lhs, OUString const & rhs) {
1931  return
1933  rhs.pData->buffer, rhs.pData->length, lhs.data))
1934  >= 0;
1935  }
1936 
1937  friend bool operator <=(OUStringLiteral const & lhs, OUString const & rhs) {
1938  return
1940  rhs.pData->buffer, rhs.pData->length, lhs.data))
1941  > 0;
1942  }
1943 
1944  friend bool operator >(OUStringLiteral const & lhs, OUString const & rhs) {
1945  return
1947  rhs.pData->buffer, rhs.pData->length, lhs.data))
1948  <= 0;
1949  }
1950 
1951  friend bool operator >=(OUStringLiteral const & lhs, OUString const & rhs) {
1952  return
1954  rhs.pData->buffer, rhs.pData->length, lhs.data))
1955  < 0;
1956  }
1957 
1959 #endif
1960 
1968  sal_Int32 hashCode() const
1969  {
1970  return rtl_ustr_hashCode_WithLength( pData->buffer, pData->length );
1971  }
1972 
1986  sal_Int32 indexOf( sal_Unicode ch, sal_Int32 fromIndex = 0 ) const
1987  {
1988  sal_Int32 ret = rtl_ustr_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
1989  return (ret < 0 ? ret : ret+fromIndex);
1990  }
1991 
2001  sal_Int32 lastIndexOf( sal_Unicode ch ) const
2002  {
2003  return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
2004  }
2005 
2018  sal_Int32 lastIndexOf( sal_Unicode ch, sal_Int32 fromIndex ) const
2019  {
2020  return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
2021  }
2022 
2038  sal_Int32 indexOf( const OUString & str, sal_Int32 fromIndex = 0 ) const
2039  {
2040  sal_Int32 ret = rtl_ustr_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
2041  str.pData->buffer, str.pData->length );
2042  return (ret < 0 ? ret : ret+fromIndex);
2043  }
2044 
2050  template< typename T >
2051  typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const
2052  {
2053  assert(
2055  sal_Int32 n = rtl_ustr_indexOfAscii_WithLength(
2056  pData->buffer + fromIndex, pData->length - fromIndex,
2059  return n < 0 ? n : n + fromIndex;
2060  }
2061 
2062 #if defined LIBO_INTERNAL_ONLY
2063 
2064  template<typename T>
2065  typename
2067  indexOf(T & literal, sal_Int32 fromIndex = 0) const {
2068  assert(fromIndex >= 0);
2070  pData->buffer + fromIndex, pData->length - fromIndex,
2073  return n < 0 ? n : n + fromIndex;
2074  }
2075 
2077  sal_Int32 indexOf(OUStringLiteral const & literal, sal_Int32 fromIndex = 0)
2078  const
2079  {
2080  sal_Int32 n = rtl_ustr_indexOfAscii_WithLength(
2081  pData->buffer + fromIndex, pData->length - fromIndex, literal.data,
2082  literal.size);
2083  return n < 0 ? n : n + fromIndex;
2084  }
2085 #endif
2086 
2110  sal_Int32 indexOfAsciiL(
2111  char const * str, sal_Int32 len, sal_Int32 fromIndex = 0) const
2112  {
2113  sal_Int32 ret = rtl_ustr_indexOfAscii_WithLength(
2114  pData->buffer + fromIndex, pData->length - fromIndex, str, len);
2115  return ret < 0 ? ret : ret + fromIndex;
2116  }
2117 
2118  // This overload is left undefined, to detect calls of indexOfAsciiL that
2119  // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
2120  // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
2121  // platforms):
2122 #if SAL_TYPES_SIZEOFLONG == 8
2123  void indexOfAsciiL(char const *, sal_Int32 len, rtl_TextEncoding) const;
2124 #endif
2125 
2141  sal_Int32 lastIndexOf( const OUString & str ) const
2142  {
2143  return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, pData->length,
2144  str.pData->buffer, str.pData->length );
2145  }
2146 
2164  sal_Int32 lastIndexOf( const OUString & str, sal_Int32 fromIndex ) const
2165  {
2166  return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
2167  str.pData->buffer, str.pData->length );
2168  }
2169 
2175  template< typename T >
2177  {
2178  assert(
2181  pData->buffer, pData->length,
2184  }
2185 
2186 #if defined LIBO_INTERNAL_ONLY
2187 
2188  template<typename T>
2189  typename
2191  lastIndexOf(T & literal) const {
2193  pData->buffer, pData->length,
2196  }
2197 
2199  sal_Int32 lastIndexOf(OUStringLiteral const & literal) const {
2201  pData->buffer, pData->length, literal.data, literal.size);
2202  }
2203 #endif
2204 
2224  sal_Int32 lastIndexOfAsciiL(char const * str, sal_Int32 len) const
2225  {
2227  pData->buffer, pData->length, str, len);
2228  }
2229 
2240  SAL_WARN_UNUSED_RESULT OUString copy( sal_Int32 beginIndex ) const
2241  {
2242  return copy(beginIndex, getLength() - beginIndex);
2243  }
2244 
2257  SAL_WARN_UNUSED_RESULT OUString copy( sal_Int32 beginIndex, sal_Int32 count ) const
2258  {
2259  rtl_uString *pNew = NULL;
2260  rtl_uString_newFromSubString( &pNew, pData, beginIndex, count );
2261  return OUString( pNew, SAL_NO_ACQUIRE );
2262  }
2263 
2273  {
2274  rtl_uString* pNew = NULL;
2275  rtl_uString_newConcat( &pNew, pData, str.pData );
2276  return OUString( pNew, SAL_NO_ACQUIRE );
2277  }
2278 
2279 #ifndef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2280  friend OUString operator+( const OUString& rStr1, const OUString& rStr2 )
2281  {
2282  return rStr1.concat( rStr2 );
2283  }
2284 #endif
2285 
2299  SAL_WARN_UNUSED_RESULT OUString replaceAt( sal_Int32 index, sal_Int32 count, const OUString& newStr ) const
2300  {
2301  rtl_uString* pNew = NULL;
2302  rtl_uString_newReplaceStrAt( &pNew, pData, index, count, newStr.pData );
2303  return OUString( pNew, SAL_NO_ACQUIRE );
2304  }
2305 
2320  {
2321  rtl_uString* pNew = NULL;
2322  rtl_uString_newReplace( &pNew, pData, oldChar, newChar );
2323  return OUString( pNew, SAL_NO_ACQUIRE );
2324  }
2325 
2345  OUString const & from, OUString const & to, sal_Int32 * index = NULL) const
2346  {
2347  rtl_uString * s = NULL;
2348  sal_Int32 i = 0;
2350  &s, pData, from.pData, to.pData, index == NULL ? &i : index);
2351  return OUString(s, SAL_NO_ACQUIRE);
2352  }
2353 
2372  template< typename T >
2374  sal_Int32 * index = NULL) const
2375  {
2377  rtl_uString * s = NULL;
2378  sal_Int32 i = 0;
2380  &s, pData,
2383  index == NULL ? &i : index);
2384  return OUString(s, SAL_NO_ACQUIRE);
2385  }
2386 
2405  template< typename T >
2407  sal_Int32 * index = NULL) const
2408  {
2410  rtl_uString * s = NULL;
2411  sal_Int32 i = 0;
2413  &s, pData, from.pData,
2416  index == NULL ? &i : index);
2417  return OUString(s, SAL_NO_ACQUIRE);
2418  }
2419 
2438  template< typename T1, typename T2 >
2440  replaceFirst( T1& from, T2& to, sal_Int32 * index = NULL) const
2441  {
2444  rtl_uString * s = NULL;
2445  sal_Int32 i = 0;
2447  &s, pData,
2452  index == NULL ? &i : index);
2453  return OUString(s, SAL_NO_ACQUIRE);
2454  }
2455 
2456 #if defined LIBO_INTERNAL_ONLY
2457 
2458  template<typename T> [[nodiscard]]
2459  typename
2461  replaceFirst(T & from, OUString const & to, sal_Int32 * index = nullptr)
2462  const
2463  {
2464  rtl_uString * s = nullptr;
2465  sal_Int32 i = 0;
2467  &s, pData,
2470  to.pData->buffer, to.pData->length, index == nullptr ? &i : index);
2471  if (s == nullptr) {
2472  throw std::bad_alloc();
2473  // should be std::length_error if resulting would be too large
2474  }
2475  return OUString(s, SAL_NO_ACQUIRE);
2476  }
2478  template<typename T> [[nodiscard]]
2479  typename
2480  libreoffice_internal::ConstCharArrayDetector<T, OUString>::TypeUtf16
2481  replaceFirst(OUString const & from, T & to, sal_Int32 * index = nullptr)
2482  const
2483  {
2484  rtl_uString * s = nullptr;
2485  sal_Int32 i = 0;
2487  &s, pData, from.pData->buffer, from.pData->length,
2488  libreoffice_internal::ConstCharArrayDetector<T>::toPointer(to),
2489  libreoffice_internal::ConstCharArrayDetector<T>::length,
2490  index == nullptr ? &i : index);
2491  if (s == nullptr) {
2492  throw std::bad_alloc();
2493  // should be std::length_error if resulting would be too large
2494  }
2495  return OUString(s, SAL_NO_ACQUIRE);
2496  }
2498  template<typename T1, typename T2> [[nodiscard]]
2499  typename
2500  libreoffice_internal::ConstCharArrayDetector<
2501  T1,
2502  typename libreoffice_internal::ConstCharArrayDetector<
2503  T2, OUString>::TypeUtf16
2504  >::TypeUtf16
2505  replaceFirst(T1 & from, T2 & to, sal_Int32 * index = nullptr) const {
2506  rtl_uString * s = nullptr;
2507  sal_Int32 i = 0;
2509  &s, pData,
2510  libreoffice_internal::ConstCharArrayDetector<T1>::toPointer(from),
2511  libreoffice_internal::ConstCharArrayDetector<T1>::length,
2512  libreoffice_internal::ConstCharArrayDetector<T2>::toPointer(to),
2513  libreoffice_internal::ConstCharArrayDetector<T2>::length,
2514  index == nullptr ? &i : index);
2515  if (s == nullptr) {
2516  throw std::bad_alloc();
2517  // should be std::length_error if resulting would be too large
2518  }
2519  return OUString(s, SAL_NO_ACQUIRE);
2520  }
2522  template<typename T1, typename T2> [[nodiscard]]
2523  typename
2524  libreoffice_internal::ConstCharArrayDetector<
2525  T1,
2526  typename libreoffice_internal::ConstCharArrayDetector<
2527  T2, OUString>::Type
2528  >::TypeUtf16
2529  replaceFirst(T1 & from, T2 & to, sal_Int32 * index = nullptr) const {
2530  rtl_uString * s = nullptr;
2531  sal_Int32 i = 0;
2533  &s, pData,
2534  libreoffice_internal::ConstCharArrayDetector<T1>::toPointer(from),
2535  libreoffice_internal::ConstCharArrayDetector<T1>::length,
2536  libreoffice_internal::ConstCharArrayDetector<T2>::toPointer(to),
2537  libreoffice_internal::ConstCharArrayDetector<T2>::length,
2538  index == nullptr ? &i : index);
2539  if (s == nullptr) {
2540  throw std::bad_alloc();
2541  // should be std::length_error if resulting would be too large
2542  }
2543  return OUString(s, SAL_NO_ACQUIRE);
2544  }
2546  template<typename T1, typename T2> [[nodiscard]]
2547  typename
2548  libreoffice_internal::ConstCharArrayDetector<
2549  T1,
2550  typename libreoffice_internal::ConstCharArrayDetector<
2551  T2, OUString>::TypeUtf16
2552  >::Type
2553  replaceFirst(T1 & from, T2 & to, sal_Int32 * index = nullptr) const {
2554  rtl_uString * s = nullptr;
2555  sal_Int32 i = 0;
2557  &s, pData,
2558  libreoffice_internal::ConstCharArrayDetector<T1>::toPointer(from),
2559  libreoffice_internal::ConstCharArrayDetector<T1>::length,
2560  libreoffice_internal::ConstCharArrayDetector<T2>::toPointer(to),
2561  libreoffice_internal::ConstCharArrayDetector<T2>::length,
2562  index == nullptr ? &i : index);
2563  if (s == nullptr) {
2564  throw std::bad_alloc();
2565  // should be std::length_error if resulting would be too large
2566  }
2567  return OUString(s, SAL_NO_ACQUIRE);
2568  }
2569 
2571  [[nodiscard]] OUString replaceFirst(
2572  OUStringLiteral const & from, OUString const & to,
2573  sal_Int32 * index = nullptr) const
2574  {
2575  rtl_uString * s = nullptr;
2576  sal_Int32 i = 0;
2578  &s, pData, from.data, from.size, to.pData,
2579  index == nullptr ? &i : index);
2580  return OUString(s, SAL_NO_ACQUIRE);
2581  }
2583  [[nodiscard]] OUString replaceFirst(
2584  OUString const & from, OUStringLiteral const & to,
2585  sal_Int32 * index = nullptr) const
2586  {
2587  rtl_uString * s = nullptr;
2588  sal_Int32 i = 0;
2590  &s, pData, from.pData, to.data, to.size,
2591  index == nullptr ? &i : index);
2592  return OUString(s, SAL_NO_ACQUIRE);
2593  }
2595  [[nodiscard]] OUString replaceFirst(
2596  OUStringLiteral const & from, OUStringLiteral const & to,
2597  sal_Int32 * index = nullptr) const
2598  {
2599  rtl_uString * s = nullptr;
2600  sal_Int32 i = 0;
2602  &s, pData, from.data, from.size, to.data, to.size,
2603  index == nullptr ? &i : index);
2604  return OUString(s, SAL_NO_ACQUIRE);
2605  }
2607  template<typename T> [[nodiscard]]
2608  typename libreoffice_internal::ConstCharArrayDetector<T, OUString >::Type
2609  replaceFirst(
2610  OUStringLiteral const & from, T & to, sal_Int32 * index = nullptr) const
2611  {
2612  assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(to));
2613  rtl_uString * s = nullptr;
2614  sal_Int32 i = 0;
2616  &s, pData, from.data, from.size,
2617  libreoffice_internal::ConstCharArrayDetector<T>::toPointer(to),
2618  libreoffice_internal::ConstCharArrayDetector<T>::length,
2619  index == nullptr ? &i : index);
2620  return OUString(s, SAL_NO_ACQUIRE);
2621  }
2623  template<typename T> [[nodiscard]]
2624  typename libreoffice_internal::ConstCharArrayDetector<T, OUString >::Type
2625  replaceFirst(
2626  T & from, OUStringLiteral const & to, sal_Int32 * index = nullptr) const
2627  {
2628  assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(from));
2629  rtl_uString * s = nullptr;
2630  sal_Int32 i = 0;
2632  &s, pData,
2633  libreoffice_internal::ConstCharArrayDetector<T>::toPointer(from),
2634  libreoffice_internal::ConstCharArrayDetector<T>::length, to.data,
2635  to.size, index == nullptr ? &i : index);
2636  return OUString(s, SAL_NO_ACQUIRE);
2637  }
2639  template<typename T> [[nodiscard]]
2640  typename
2641  libreoffice_internal::ConstCharArrayDetector<T, OUString >::TypeUtf16
2642  replaceFirst(
2643  OUStringLiteral const & from, T & to, sal_Int32 * index = nullptr) const
2644  {
2645  assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(to));
2646  rtl_uString * s = nullptr;
2647  sal_Int32 i = 0;
2649  &s, pData, from.data, from.size,
2650  libreoffice_internal::ConstCharArrayDetector<T>::toPointer(to),
2651  libreoffice_internal::ConstCharArrayDetector<T>::length,
2652  index == nullptr ? &i : index);
2653  return OUString(s, SAL_NO_ACQUIRE);
2654  }
2656  template<typename T> [[nodiscard]]
2657  typename
2658  libreoffice_internal::ConstCharArrayDetector<T, OUString >::TypeUtf16
2659  replaceFirst(
2660  T & from, OUStringLiteral const & to, sal_Int32 * index = nullptr) const
2661  {
2662  assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(from));
2663  rtl_uString * s = nullptr;
2664  sal_Int32 i = 0;
2666  &s, pData,
2667  libreoffice_internal::ConstCharArrayDetector<T>::toPointer(from),
2668  libreoffice_internal::ConstCharArrayDetector<T>::length, to.data,
2669  to.size, index == nullptr ? &i : index);
2670  return OUString(s, SAL_NO_ACQUIRE);
2671  }
2672 #endif
2673 
2690  OUString const & from, OUString const & to, sal_Int32 fromIndex = 0) const
2691  {
2692  rtl_uString * s = NULL;
2693  rtl_uString_newReplaceAllFromIndex(&s, pData, from.pData, to.pData, fromIndex);
2694  return OUString(s, SAL_NO_ACQUIRE);
2695  }
2696 
2710  template< typename T >
2712  {
2714  rtl_uString * s = NULL;
2716  &s, pData,
2719  return OUString(s, SAL_NO_ACQUIRE);
2720  }
2721 
2735  template< typename T >
2737  {
2739  rtl_uString * s = NULL;
2741  &s, pData, from.pData,
2744  return OUString(s, SAL_NO_ACQUIRE);
2745  }
2746 
2760  template< typename T1, typename T2 >
2762  replaceAll( T1& from, T2& to ) const
2763  {
2766  rtl_uString * s = NULL;
2768  &s, pData,
2773  return OUString(s, SAL_NO_ACQUIRE);
2774  }
2775 
2776 #if defined LIBO_INTERNAL_ONLY
2777 
2778  template<typename T> [[nodiscard]]
2779  typename
2781  replaceAll(T & from, OUString const & to) const {
2782  rtl_uString * s = nullptr;
2784  &s, pData,
2787  to.pData->buffer, to.pData->length);
2788  if (s == nullptr) {
2789  throw std::bad_alloc();
2790  // should be std::length_error if resulting would be too large
2791  }
2792  return OUString(s, SAL_NO_ACQUIRE);
2793  }
2795  template<typename T> [[nodiscard]]
2796  typename
2797  libreoffice_internal::ConstCharArrayDetector<T, OUString>::TypeUtf16
2798  replaceAll(OUString const & from, T & to) const {
2799  rtl_uString * s = nullptr;
2801  &s, pData, from.pData->buffer, from.pData->length,
2802  libreoffice_internal::ConstCharArrayDetector<T>::toPointer(to),
2803  libreoffice_internal::ConstCharArrayDetector<T>::length);
2804  if (s == nullptr) {
2805  throw std::bad_alloc();
2806  // should be std::length_error if resulting would be too large
2807  }
2808  return OUString(s, SAL_NO_ACQUIRE);
2809  }
2811  template<typename T1, typename T2> [[nodiscard]]
2812  typename
2813  libreoffice_internal::ConstCharArrayDetector<
2814  T1,
2815  typename libreoffice_internal::ConstCharArrayDetector<
2816  T2, OUString>::TypeUtf16
2817  >::TypeUtf16
2818  replaceAll(T1 & from, T2 & to) const {
2819  rtl_uString * s = nullptr;
2821  &s, pData,
2822  libreoffice_internal::ConstCharArrayDetector<T1>::toPointer(from),
2823  libreoffice_internal::ConstCharArrayDetector<T1>::length,
2824  libreoffice_internal::ConstCharArrayDetector<T2>::toPointer(to),
2825  libreoffice_internal::ConstCharArrayDetector<T2>::length);
2826  if (s == nullptr) {
2827  throw std::bad_alloc();
2828  // should be std::length_error if resulting would be too large
2829  }
2830  return OUString(s, SAL_NO_ACQUIRE);
2831  }
2833  template<typename T1, typename T2> [[nodiscard]]
2834  typename
2835  libreoffice_internal::ConstCharArrayDetector<
2836  T1,
2837  typename libreoffice_internal::ConstCharArrayDetector<
2838  T2, OUString>::Type
2839  >::TypeUtf16
2840  replaceAll(T1 & from, T2 & to) const {
2841  rtl_uString * s = nullptr;
2843  &s, pData,
2844  libreoffice_internal::ConstCharArrayDetector<T1>::toPointer(from),
2845  libreoffice_internal::ConstCharArrayDetector<T1>::length,
2846  libreoffice_internal::ConstCharArrayDetector<T2>::toPointer(to),
2847  libreoffice_internal::ConstCharArrayDetector<T2>::length);
2848  if (s == nullptr) {
2849  throw std::bad_alloc();
2850  // should be std::length_error if resulting would be too large
2851  }
2852  return OUString(s, SAL_NO_ACQUIRE);
2853  }
2855  template<typename T1, typename T2> [[nodiscard]]
2856  typename
2857  libreoffice_internal::ConstCharArrayDetector<
2858  T1,
2859  typename libreoffice_internal::ConstCharArrayDetector<
2860  T2, OUString>::TypeUtf16
2861  >::Type
2862  replaceAll(T1 & from, T2 & to) const {
2863  rtl_uString * s = nullptr;
2865  &s, pData,
2866  libreoffice_internal::ConstCharArrayDetector<T1>::toPointer(from),
2867  libreoffice_internal::ConstCharArrayDetector<T1>::length,
2868  libreoffice_internal::ConstCharArrayDetector<T2>::toPointer(to),
2869  libreoffice_internal::ConstCharArrayDetector<T2>::length);
2870  if (s == nullptr) {
2871  throw std::bad_alloc();
2872  // should be std::length_error if resulting would be too large
2873  }
2874  return OUString(s, SAL_NO_ACQUIRE);
2875  }
2876 
2878  [[nodiscard]] OUString replaceAll(
2879  OUStringLiteral const & from, OUString const & to) const
2880  {
2881  rtl_uString * s = nullptr;
2883  &s, pData, from.data, from.size, to.pData);
2884  return OUString(s, SAL_NO_ACQUIRE);
2885  }
2887  [[nodiscard]] OUString replaceAll(
2888  OUString const & from, OUStringLiteral const & to) const
2889  {
2890  rtl_uString * s = nullptr;
2892  &s, pData, from.pData, to.data, to.size);
2893  return OUString(s, SAL_NO_ACQUIRE);
2894  }
2896  [[nodiscard]] OUString replaceAll(
2897  OUStringLiteral const & from, OUStringLiteral const & to) const
2898  {
2899  rtl_uString * s = nullptr;
2901  &s, pData, from.data, from.size, to.data, to.size);
2902  return OUString(s, SAL_NO_ACQUIRE);
2903  }
2905  template<typename T> [[nodiscard]]
2906  typename libreoffice_internal::ConstCharArrayDetector<T, OUString >::Type
2907  replaceAll(OUStringLiteral const & from, T & to) const {
2908  assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(to));
2909  rtl_uString * s = nullptr;
2911  &s, pData, from.data, from.size,
2912  libreoffice_internal::ConstCharArrayDetector<T>::toPointer(to),
2913  libreoffice_internal::ConstCharArrayDetector<T>::length);
2914  return OUString(s, SAL_NO_ACQUIRE);
2915  }
2917  template<typename T> [[nodiscard]]
2918  typename libreoffice_internal::ConstCharArrayDetector<T, OUString >::Type
2919  replaceAll(T & from, OUStringLiteral const & to) const {
2920  assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(from));
2921  rtl_uString * s = nullptr;
2923  &s, pData,
2924  libreoffice_internal::ConstCharArrayDetector<T>::toPointer(from),
2925  libreoffice_internal::ConstCharArrayDetector<T>::length, to.data,
2926  to.size);
2927  return OUString(s, SAL_NO_ACQUIRE);
2928  }
2930  template<typename T> [[nodiscard]]
2931  typename
2932  libreoffice_internal::ConstCharArrayDetector<T, OUString >::TypeUtf16
2933  replaceAll(OUStringLiteral const & from, T & to) const {
2934  assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(to));
2935  rtl_uString * s = nullptr;
2937  &s, pData, from.data, from.size,
2938  libreoffice_internal::ConstCharArrayDetector<T>::toPointer(to),
2939  libreoffice_internal::ConstCharArrayDetector<T>::length);
2940  return OUString(s, SAL_NO_ACQUIRE);
2941  }
2943  template<typename T> [[nodiscard]]
2944  typename
2945  libreoffice_internal::ConstCharArrayDetector<T, OUString >::TypeUtf16
2946  replaceAll(T & from, OUStringLiteral const & to) const {
2947  assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(from));
2948  rtl_uString * s = nullptr;
2950  &s, pData,
2951  libreoffice_internal::ConstCharArrayDetector<T>::toPointer(from),
2952  libreoffice_internal::ConstCharArrayDetector<T>::length, to.data,
2953  to.size);
2954  return OUString(s, SAL_NO_ACQUIRE);
2955  }
2956 #endif
2957 
2969  {
2970  rtl_uString* pNew = NULL;
2971  rtl_uString_newToAsciiLowerCase( &pNew, pData );
2972  return OUString( pNew, SAL_NO_ACQUIRE );
2973  }
2974 
2986  {
2987  rtl_uString* pNew = NULL;
2988  rtl_uString_newToAsciiUpperCase( &pNew, pData );
2989  return OUString( pNew, SAL_NO_ACQUIRE );
2990  }
2991 
3006  {
3007  rtl_uString* pNew = NULL;
3008  rtl_uString_newTrim( &pNew, pData );
3009  return OUString( pNew, SAL_NO_ACQUIRE );
3010  }
3011 
3036  OUString getToken( sal_Int32 token, sal_Unicode cTok, sal_Int32& index ) const
3037  {
3038  rtl_uString * pNew = NULL;
3039  index = rtl_uString_getToken( &pNew, pData, token, cTok, index );
3040  return OUString( pNew, SAL_NO_ACQUIRE );
3041  }
3042 
3056  OUString getToken(sal_Int32 count, sal_Unicode separator) const {
3057  sal_Int32 n = 0;
3058  return getToken(count, separator, n);
3059  }
3060 
3069  bool toBoolean() const
3070  {
3071  return rtl_ustr_toBoolean( pData->buffer );
3072  }
3073 
3081  {
3082  return pData->buffer[0];
3083  }
3084 
3095  sal_Int32 toInt32( sal_Int16 radix = 10 ) const
3096  {
3097  return rtl_ustr_toInt32( pData->buffer, radix );
3098  }
3099 
3112  sal_uInt32 toUInt32( sal_Int16 radix = 10 ) const
3113  {
3114  return rtl_ustr_toUInt32( pData->buffer, radix );
3115  }
3116 
3127  sal_Int64 toInt64( sal_Int16 radix = 10 ) const
3128  {
3129  return rtl_ustr_toInt64( pData->buffer, radix );
3130  }
3131 
3144  sal_uInt64 toUInt64( sal_Int16 radix = 10 ) const
3145  {
3146  return rtl_ustr_toUInt64( pData->buffer, radix );
3147  }
3148 
3157  float toFloat() const
3158  {
3159  return rtl_ustr_toFloat( pData->buffer );
3160  }
3161 
3170  double toDouble() const
3171  {
3172  return rtl_ustr_toDouble( pData->buffer );
3173  }
3174 
3175 
3192  {
3193  rtl_uString * pNew = NULL;
3194  rtl_uString_intern( &pNew, pData );
3195  if (pNew == NULL) {
3196  throw std::bad_alloc();
3197  }
3198  return OUString( pNew, SAL_NO_ACQUIRE );
3199  }
3200 
3226  static OUString intern( const sal_Char * value, sal_Int32 length,
3227  rtl_TextEncoding encoding,
3228  sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS,
3229  sal_uInt32 *pInfo = NULL )
3230  {
3231  rtl_uString * pNew = NULL;
3232  rtl_uString_internConvert( &pNew, value, length, encoding,
3233  convertFlags, pInfo );
3234  if (pNew == NULL) {
3235  throw std::bad_alloc();
3236  }
3237  return OUString( pNew, SAL_NO_ACQUIRE );
3238  }
3239 
3264  bool convertToString(OString * pTarget, rtl_TextEncoding nEncoding,
3265  sal_uInt32 nFlags) const
3266  {
3267  return rtl_convertUStringToString(&pTarget->pData, pData->buffer,
3268  pData->length, nEncoding, nFlags);
3269  }
3270 
3322  sal_uInt32 iterateCodePoints(
3323  sal_Int32 * indexUtf16, sal_Int32 incrementCodePoints = 1) const
3324  {
3326  pData, indexUtf16, incrementCodePoints);
3327  }
3328 
3338  static OUString fromUtf8(const OString& rSource)
3339  {
3340  OUString aTarget;
3341  bool bSuccess = rtl_convertStringToUString(&aTarget.pData,
3342  rSource.getStr(),
3343  rSource.getLength(),
3346  (void) bSuccess;
3347  assert(bSuccess);
3348  return aTarget;
3349  }
3350 
3361  OString toUtf8() const
3362  {
3363  OString aTarget;
3364  bool bSuccess = rtl_convertUStringToString(&aTarget.pData,
3365  getStr(),
3366  getLength(),
3369  (void) bSuccess;
3370  assert(bSuccess);
3371  return aTarget;
3372  }
3373 
3374 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
3375 
3376  static OUStringNumber< int > number( int i, sal_Int16 radix = 10 )
3377  {
3378  return OUStringNumber< int >( i, radix );
3379  }
3380  static OUStringNumber< long long > number( long long ll, sal_Int16 radix = 10 )
3381  {
3382  return OUStringNumber< long long >( ll, radix );
3383  }
3384  static OUStringNumber< unsigned long long > number( unsigned long long ll, sal_Int16 radix = 10 )
3385  {
3386  return OUStringNumber< unsigned long long >( ll, radix );
3387  }
3388  static OUStringNumber< unsigned long long > number( unsigned int i, sal_Int16 radix = 10 )
3389  {
3390  return number( static_cast< unsigned long long >( i ), radix );
3391  }
3392  static OUStringNumber< long long > number( long i, sal_Int16 radix = 10)
3393  {
3394  return number( static_cast< long long >( i ), radix );
3395  }
3396  static OUStringNumber< unsigned long long > number( unsigned long i, sal_Int16 radix = 10 )
3397  {
3398  return number( static_cast< unsigned long long >( i ), radix );
3399  }
3400  static OUStringNumber< float > number( float f )
3401  {
3402  return OUStringNumber< float >( f );
3403  }
3404  static OUStringNumber< double > number( double d )
3405  {
3406  return OUStringNumber< double >( d );
3407  }
3408 #else
3409 
3419  static OUString number( int i, sal_Int16 radix = 10 )
3420  {
3422  return OUString(aBuf, rtl_ustr_valueOfInt32(aBuf, i, radix));
3423  }
3426  static OUString number( unsigned int i, sal_Int16 radix = 10 )
3427  {
3428  return number( static_cast< unsigned long long >( i ), radix );
3429  }
3432  static OUString number( long i, sal_Int16 radix = 10)
3433  {
3434  return number( static_cast< long long >( i ), radix );
3435  }
3438  static OUString number( unsigned long i, sal_Int16 radix = 10 )
3439  {
3440  return number( static_cast< unsigned long long >( i ), radix );
3441  }
3444  static OUString number( long long ll, sal_Int16 radix = 10 )
3445  {
3447  return OUString(aBuf, rtl_ustr_valueOfInt64(aBuf, ll, radix));
3448  }
3451  static OUString number( unsigned long long ll, sal_Int16 radix = 10 )
3452  {
3454  return OUString(aBuf, rtl_ustr_valueOfUInt64(aBuf, ll, radix));
3455  }
3456 
3466  static OUString number( float f )
3467  {
3469  return OUString(aBuf, rtl_ustr_valueOfFloat(aBuf, f));
3470  }
3471 
3481  static OUString number( double d )
3482  {
3484  return OUString(aBuf, rtl_ustr_valueOfDouble(aBuf, d));
3485  }
3486 #endif
3487 
3499  SAL_DEPRECATED("use boolean()") static OUString valueOf( sal_Bool b )
3500  {
3501  return boolean(b);
3502  }
3503 
3515  static OUString boolean( bool b )
3516  {
3518  return OUString(aBuf, rtl_ustr_valueOfBoolean(aBuf, b));
3519  }
3520 
3528  SAL_DEPRECATED("convert to OUString or use directly") static OUString valueOf( sal_Unicode c )
3529  {
3530  return OUString( &c, 1 );
3531  }
3532 
3543  SAL_DEPRECATED("use number()") static OUString valueOf( sal_Int32 i, sal_Int16 radix = 10 )
3544  {
3545  return number( i, radix );
3546  }
3547 
3558  SAL_DEPRECATED("use number()") static OUString valueOf( sal_Int64 ll, sal_Int16 radix = 10 )
3559  {
3560  return number( ll, radix );
3561  }
3562 
3572  SAL_DEPRECATED("use number()") static OUString valueOf( float f )
3573  {
3574  return number(f);
3575  }
3576 
3586  SAL_DEPRECATED("use number()") static OUString valueOf( double d )
3587  {
3588  return number(d);
3589  }
3590 
3606  static OUString createFromAscii( const sal_Char * value )
3607  {
3608  rtl_uString* pNew = NULL;
3609  rtl_uString_newFromAscii( &pNew, value );
3610  return OUString( pNew, SAL_NO_ACQUIRE );
3611  }
3612 
3613 #if defined LIBO_INTERNAL_ONLY
3614  operator std::u16string_view() const { return {getStr(), sal_uInt32(getLength())}; }
3615 #endif
3616 
3617 private:
3618  OUString & internalAppend( rtl_uString* pOtherData )
3619  {
3620  rtl_uString* pNewData = NULL;
3621  rtl_uString_newConcat( &pNewData, pData, pOtherData );
3622  if (pNewData == NULL) {
3623  throw std::bad_alloc();
3624  }
3625  rtl_uString_assign(&pData, pNewData);
3626  rtl_uString_release(pNewData);
3627  return *this;
3628  }
3629 
3630 };
3631 
3632 #if defined LIBO_INTERNAL_ONLY
3633 // Prevent the operator ==/!= overloads with 'sal_Unicode const *' parameter from
3634 // being selected for nonsensical code like
3635 //
3636 // if (ouIdAttr == nullptr)
3637 //
3638 void operator ==(OUString const &, std::nullptr_t) = delete;
3639 void operator ==(std::nullptr_t, OUString const &) = delete;
3640 void operator !=(OUString const &, std::nullptr_t) = delete;
3641 void operator !=(std::nullptr_t, OUString const &) = delete;
3642 #endif
3643 
3644 #if defined LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
3645 
3650 template<>
3651 struct ToStringHelper< OUString >
3652  {
3653  static std::size_t length( const OUString& s ) { return s.getLength(); }
3654  static sal_Unicode* addData( sal_Unicode* buffer, const OUString& s ) { return addDataHelper( buffer, s.getStr(), s.getLength()); }
3655  static const bool allowOStringConcat = false;
3656  static const bool allowOUStringConcat = true;
3657  };
3658 
3662 template<>
3663 struct ToStringHelper< OUStringLiteral >
3664  {
3665  static std::size_t length( const OUStringLiteral& str ) { return str.size; }
3666  static sal_Unicode* addData( sal_Unicode* buffer, const OUStringLiteral& str ) { return addDataLiteral( buffer, str.data, str.size ); }
3667  static const bool allowOStringConcat = false;
3668  static const bool allowOUStringConcat = true;
3669  };
3670 
3674 template< typename charT, typename traits, typename T1, typename T2 >
3675 inline std::basic_ostream<charT, traits> & operator <<(
3676  std::basic_ostream<charT, traits> & stream, OUStringConcat< T1, T2 >&& concat)
3677 {
3678  return stream << OUString( std::move(concat) );
3679 }
3680 
3682 #endif
3683 
3690 {
3700  size_t operator()(const OUString& rString) const
3701  { return static_cast<size_t>(rString.hashCode()); }
3702 };
3703 
3704 /* ======================================================================= */
3705 
3723 inline OUString OStringToOUString( const OString & rStr,
3724  rtl_TextEncoding encoding,
3725  sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS )
3726 {
3727  return OUString( rStr.getStr(), rStr.getLength(), encoding, convertFlags );
3728 }
3729 
3747 inline OString OUStringToOString( const OUString & rUnicode,
3748  rtl_TextEncoding encoding,
3749  sal_uInt32 convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS )
3750 {
3751  return OString( rUnicode.getStr(), rUnicode.getLength(), encoding, convertFlags );
3752 }
3753 
3754 /* ======================================================================= */
3755 
3764 template< typename charT, typename traits >
3765 inline std::basic_ostream<charT, traits> & operator <<(
3766  std::basic_ostream<charT, traits> & stream, OUString const & rString)
3767 {
3768  return stream <<
3770  // best effort; potentially loses data due to conversion failures
3771  // (stray surrogate halves) and embedded null characters
3772 }
3773 
3774 } // namespace
3775 
3776 #ifdef RTL_STRING_UNITTEST
3777 namespace rtl
3778 {
3779 typedef rtlunittest::OUString OUString;
3780 }
3781 #endif
3782 
3783 // In internal code, allow to use classes like OUString without having to
3784 // explicitly refer to the rtl namespace, which is kind of superfluous given
3785 // that OUString itself is namespaced by its OU prefix:
3786 #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
3787 using ::rtl::OUString;
3788 using ::rtl::OUStringHash;
3791 using ::rtl::OUStringLiteral;
3792 using ::rtl::OUStringChar;
3793 #endif
3794 
3796 
3801 #if defined LIBO_INTERNAL_ONLY
3802 namespace std {
3803 
3804 template<>
3805 struct hash<::rtl::OUString>
3806 {
3807  std::size_t operator()(::rtl::OUString const & s) const
3808  { return std::size_t(s.hashCode()); }
3809 };
3810 
3811 }
3812 
3813 #endif
3814 
3816 #endif /* _RTL_USTRING_HXX */
3817 
3818 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define OUSTRING_TO_OSTRING_CVTFLAGS
Definition: string.h:1350
sal_Int32 getLength() const
Returns the length of this string.
Definition: string.hxx:433
OUString(sal_uInt32 const *codePoints, sal_Int32 codePointCount)
Create a new string from an array of Unicode code points.
Definition: ustring.hxx:384
OString OUStringToOString(const OUString &rUnicode, rtl_TextEncoding encoding, sal_uInt32 convertFlags=OUSTRING_TO_OSTRING_CVTFLAGS)
Convert an OUString to an OString, using a specific text encoding.
Definition: ustring.hxx:3747
sal_Int32 indexOf(const OUString &str, sal_Int32 fromIndex=0) const
Returns the index within this string of the first occurrence of the specified substring, starting at the specified index.
Definition: ustring.hxx:2038
static OUString number(unsigned long i, sal_Int16 radix=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: ustring.hxx:3438
double toDouble() const
Returns the double value from this string.
Definition: ustring.hxx:3170
OUString getToken(sal_Int32 count, sal_Unicode separator) const
Returns a token from the string.
Definition: ustring.hxx:3056
#define RTL_TEXTENCODING_UTF8
Definition: textenc.h:113
SAL_DLLPUBLIC void rtl_uString_newReplaceAllFromIndex(rtl_uString **newStr, rtl_uString *str, rtl_uString const *from, rtl_uString const *to, sal_Int32 fromIndex) SAL_THROW_EXTERN_C()
Create a new string by replacing all occurrences of a given substring with another substring...
SAL_DLLPUBLIC void rtl_uString_intern(rtl_uString **newStr, rtl_uString *str) SAL_THROW_EXTERN_C()
Return a canonical representation for a string.
bool endsWithIgnoreAsciiCaseAsciiL(char const *asciiStr, sal_Int32 asciiStrLength) const
Check whether this string ends with a given ASCII string, ignoring the case of ASCII letters...
Definition: ustring.hxx:1733
libreoffice_internal::ConstCharArrayDetector< T, bool >::Type matchIgnoreAsciiCase(T &literal, sal_Int32 fromIndex=0) const
This is an overloaded member function, provided for convenience. It differs from the above function ...
Definition: ustring.hxx:1020
libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWith(T &literal, OUString *rest=NULL) const
This is an overloaded member function, provided for convenience. It differs from the above function ...
Definition: ustring.hxx:1360
#define RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR
Definition: textcvt.h:64
size_t operator()(const OUString &rString) const
Compute a hash code for a string.
Definition: ustring.hxx:3700
SAL_DLLPUBLIC void rtl_uString_newTrim(rtl_uString **newStr, rtl_uString *str) SAL_THROW_EXTERN_C()
Create a new string by removing white space from both ends of another string.
static OUString createFromAscii(const sal_Char *value)
Returns an OUString copied without conversion from an ASCII character string.
Definition: ustring.hxx:3606
OUString OStringToOUString(const OString &rStr, rtl_TextEncoding encoding, sal_uInt32 convertFlags=OSTRING_TO_OUSTRING_CVTFLAGS)
Convert an OString to an OUString, using a specific text encoding.
Definition: ustring.hxx:3723
libreoffice_internal::ConstCharArrayDetector< T, bool >::Type equalsIgnoreAsciiCase(T &literal) const
This is an overloaded member function, provided for convenience. It differs from the above function ...
Definition: ustring.hxx:886
SAL_DLLPUBLIC void rtl_uString_newReplaceFirstToAsciiL(rtl_uString **newStr, rtl_uString *str, rtl_uString const *from, char const *to, sal_Int32 toLength, sal_Int32 *index) SAL_THROW_EXTERN_C()
Create a new string by replacing the first occurrence of a given substring with another substring...
friend OUString operator+(const OUString &rStr1, const OUString &rStr2)
Definition: ustring.hxx:2280
SAL_WARN_UNUSED_RESULT OUString concat(const OUString &str) const
Concatenates the specified string to the end of this string.
Definition: ustring.hxx:2272
static OUString fromUtf8(const OString &rSource)
Convert an OString to an OUString, assuming that the OString is UTF-8-encoded.
Definition: ustring.hxx:3338
SAL_WARN_UNUSED_RESULT OUString copy(sal_Int32 beginIndex) const
Returns a new string that is a substring of this string.
Definition: ustring.hxx:2240
SAL_DLLPUBLIC void rtl_uString_newToAsciiUpperCase(rtl_uString **newStr, rtl_uString *str) SAL_THROW_EXTERN_C()
Create a new string by converting all ASCII lowercase letters to uppercase within another string...
sal_Int32 getLength() const
Returns the length of this string.
Definition: ustring.hxx:682
SAL_DLLPUBLIC sal_Int32 rtl_ustr_lastIndexOfChar_WithLength(const sal_Unicode *str, sal_Int32 len, sal_Unicode ch) SAL_THROW_EXTERN_C()
Search for the last occurrence of a character within a string.
std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &stream, OString const &rString)
Support for rtl::OString in std::ostream (and thus in CPPUNIT_ASSERT or SAL_INFO macros, for example).
Definition: string.hxx:1955
friend libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator==(const OUString &rString, T &literal)
Compare string to an ASCII string literal.
Definition: ustring.hxx:1774
SAL_DLLPUBLIC sal_Int32 rtl_ustr_compare_WithLength(const sal_Unicode *first, sal_Int32 firstLen, const sal_Unicode *second, sal_Int32 secondLen) SAL_THROW_EXTERN_C()
Compare two strings.
#define RTL_USTR_MAX_VALUEOFFLOAT
Definition: ustring.h:1022
libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWithIgnoreAsciiCase(T &literal, OUString *rest=NULL) const
This is an overloaded member function, provided for convenience. It differs from the above function ...
Definition: ustring.hxx:1453
#define RTL_USTR_MAX_VALUEOFUINT64
Definition: ustring.h:1003
SAL_DLLPUBLIC void rtl_uString_newFromLiteral(rtl_uString **newStr, const sal_Char *value, sal_Int32 len, sal_Int32 allocExtra) SAL_THROW_EXTERN_C()
static OUString number(unsigned long long ll, sal_Int16 radix=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: ustring.hxx:3451
libreoffice_internal::ConstCharArrayDetector< T, bool >::Type endsWithIgnoreAsciiCase(T &literal, OUString *rest=NULL) const
This is an overloaded member function, provided for convenience. It differs from the above function ...
Definition: ustring.hxx:1658
SAL_DLLPUBLIC void rtl_uString_newReplaceFirstAsciiLAsciiL(rtl_uString **newStr, rtl_uString *str, char const *from, sal_Int32 fromLength, char const *to, sal_Int32 toLength, sal_Int32 *index) SAL_THROW_EXTERN_C()
Create a new string by replacing the first occurrence of a given substring with another substring...
libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf(T &literal, sal_Int32 fromIndex=0) const
This is an overloaded member function, provided for convenience. It differs from the above function ...
Definition: ustring.hxx:2051
sal_Int32 compareTo(const OUString &str) const
Compares two strings.
Definition: ustring.hxx:733
SAL_DLLPUBLIC void rtl_uString_newReplaceStrAt(rtl_uString **newStr, rtl_uString *str, sal_Int32 idx, sal_Int32 count, rtl_uString *subStr) SAL_THROW_EXTERN_C()
Create a new string by replacing a substring of another string.
SAL_DLLPUBLIC sal_Int32 rtl_ustr_compareIgnoreAsciiCase_WithLength(const sal_Unicode *first, sal_Int32 firstLen, const sal_Unicode *second, sal_Int32 secondLen) SAL_THROW_EXTERN_C()
Compare two strings, ignoring the case of ASCII characters.
sal_Int32 lastIndexOf(const OUString &str, sal_Int32 fromIndex) const
Returns the index within this string of the last occurrence of the specified substring, searching backward starting before the specified index.
Definition: ustring.hxx:2164
sal_Unicode toChar() const
Returns the first character from this string.
Definition: ustring.hxx:3080
bool matchIgnoreAsciiCase(const OUString &str, sal_Int32 fromIndex=0) const
Match against a substring appearing in this string, ignoring the case of ASCII letters.
Definition: ustring.hxx:1007
bool operator!=(const Any &rAny, const C &value)
Template inequality operator: compares set value of left side any to right side value.
Definition: Any.hxx:664
SAL_DLLPUBLIC void rtl_uString_newFromAscii(rtl_uString **newStr, const sal_Char *value) SAL_THROW_EXTERN_C()
Allocate a new string that contains a copy of a character array.
SAL_DLLPUBLIC sal_Int32 rtl_ustr_asciil_reverseCompare_WithLength(const sal_Unicode *first, sal_Int32 firstLen, const sal_Char *second, sal_Int32 secondLen) SAL_THROW_EXTERN_C()
Compare two strings from back to front.
SAL_DLLPUBLIC void rtl_uString_internConvert(rtl_uString **newStr, const sal_Char *str, sal_Int32 len, rtl_TextEncoding encoding, sal_uInt32 convertFlags, sal_uInt32 *pInfo) SAL_THROW_EXTERN_C()
Return a canonical representation for a string.
bool operator<(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:90
SAL_DLLPUBLIC void rtl_uString_newReplaceAllAsciiL(rtl_uString **newStr, rtl_uString *str, char const *from, sal_Int32 fromLength, rtl_uString const *to) SAL_THROW_EXTERN_C()
Create a new string by replacing all occurrences of a given substring with another substring...
SAL_DLLPUBLIC void rtl_uString_newToAsciiLowerCase(rtl_uString **newStr, rtl_uString *str) SAL_THROW_EXTERN_C()
Create a new string by converting all ASCII uppercase letters to lowercase within another string...
sal_Int32 compareToIgnoreAsciiCase(const OUString &str) const
Perform an ASCII lowercase comparison of two strings.
Definition: ustring.hxx:873
libreoffice_internal::ConstCharArrayDetector< T, bool >::Type match(T &literal, sal_Int32 fromIndex=0) const
This is an overloaded member function, provided for convenience. It differs from the above function ...
Definition: ustring.hxx:950
SAL_DLLPUBLIC sal_Int32 rtl_ustr_valueOfBoolean(sal_Unicode *str, sal_Bool b) SAL_THROW_EXTERN_C()
Create the string representation of a boolean.
bool startsWith(OUString const &str, OUString *rest=NULL) const
Check whether this string starts with a given substring.
Definition: ustring.hxx:1346
static OUString const & unacquired(rtl_uString *const *ppHandle)
Provides an OUString const & passing a storage pointer of an rtl_uString * handle.
Definition: ustring.hxx:452
OUString getToken(sal_Int32 token, sal_Unicode cTok, sal_Int32 &index) const
Returns a token in the string.
Definition: ustring.hxx:3036
bool matchAsciiL(const sal_Char *asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex=0) const
Match against a substring appearing in this string.
Definition: ustring.hxx:1279
bool operator>(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:100
SAL_DLLPUBLIC sal_Int32 rtl_ustr_shortenedCompare_WithLength(const sal_Unicode *first, sal_Int32 firstLen, const sal_Unicode *second, sal_Int32 secondLen, sal_Int32 shortenedLen) SAL_THROW_EXTERN_C()
Compare two strings with a maximum count of characters.
SAL_DLLPUBLIC sal_Int32 rtl_ustr_lastIndexOfStr_WithLength(const sal_Unicode *str, sal_Int32 len, const sal_Unicode *subStr, sal_Int32 subLen) SAL_THROW_EXTERN_C()
Search for the last occurrence of a substring within a string.
SAL_DLLPUBLIC sal_Bool rtl_convertStringToUString(rtl_uString **target, char const *source, sal_Int32 length, rtl_TextEncoding encoding, sal_uInt32 flags) SAL_THROW_EXTERN_C()
Converts a byte string to a Unicode string, signalling failure.
bool operator==(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:110
SAL_DLLPUBLIC sal_uInt64 rtl_ustr_toUInt64(const sal_Unicode *str, sal_Int16 radix) SAL_THROW_EXTERN_C()
Interpret a string as an unsigned long integer.
Definition: stringutils.hxx:130
SAL_WARN_UNUSED_RESULT OUString toAsciiLowerCase() const
Converts from this string all ASCII uppercase characters (65-90) to ASCII lowercase characters (97-12...
Definition: ustring.hxx:2968
#define SAL_DEPRECATED(message)
Use as follows: SAL_DEPRECATED("Don&#39;t use, it&#39;s evil.") void doit(int nPara);.
Definition: types.h:465
sal_uInt32 iterateCodePoints(sal_Int32 *indexUtf16, sal_Int32 incrementCodePoints=1) const
Iterate through this string based on code points instead of UTF-16 code units.
Definition: ustring.hxx:3322
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:578
SAL_DLLPUBLIC sal_Int32 rtl_ustr_toInt32(const sal_Unicode *str, sal_Int16 radix) SAL_THROW_EXTERN_C()
Interpret a string as an integer.
sal_Int32 toInt32(sal_Int16 radix=10) const
Returns the int32 value from this string.
Definition: ustring.hxx:3095
bool equalsIgnoreAsciiCaseAsciiL(const sal_Char *asciiStr, sal_Int32 asciiStrLength) const
Perform an ASCII lowercase comparison of two strings.
Definition: ustring.hxx:1250
static OUString number(unsigned int i, sal_Int16 radix=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: ustring.hxx:3426
SAL_DLLPUBLIC void rtl_uString_newConcatUtf16L(rtl_uString **newString, rtl_uString *left, sal_Unicode const *right, sal_Int32 rightLength)
Create a new string that is the concatenation of two other strings.
const sal_Unicode * getStr() const SAL_RETURNS_NONNULL
Returns a pointer to the Unicode character buffer for this string.
Definition: ustring.hxx:704
SAL_DLLPUBLIC void rtl_uString_assign(rtl_uString **str, rtl_uString *rightValue) SAL_THROW_EXTERN_C()
Assign a new value to a string.
SAL_DLLPUBLIC float rtl_ustr_toFloat(const sal_Unicode *str) SAL_THROW_EXTERN_C()
Interpret a string as a float.
SAL_DLLPUBLIC void rtl_uString_acquire(rtl_uString *str) SAL_THROW_EXTERN_C() SAL_HOT
Increment the reference count of a string.
sal_Int32 compareTo(const OUString &str, sal_Int32 maxLength) const
Compares two strings with a maximum count of characters.
Definition: ustring.hxx:754
SAL_WARN_UNUSED_RESULT OUString toAsciiUpperCase() const
Converts from this string all ASCII lowercase characters (97-122) to ASCII uppercase characters (65-9...
Definition: ustring.hxx:2985
SAL_DLLPUBLIC sal_Bool rtl_ustr_asciil_reverseEquals_WithLength(const sal_Unicode *first, const sal_Char *second, sal_Int32 len) SAL_THROW_EXTERN_C()
Compare two strings from back to front for equality.
#define RTL_USTR_MAX_VALUEOFDOUBLE
Definition: ustring.h:1041
static OUString number(float f)
Returns the string representation of the float argument.
Definition: ustring.hxx:3466
SAL_DLLPUBLIC sal_uInt32 rtl_ustr_toUInt32(const sal_Unicode *str, sal_Int16 radix) SAL_THROW_EXTERN_C()
Interpret a string as an unsigned integer.
#define RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR
Definition: textcvt.h:147
bool equalsAsciiL(const sal_Char *asciiStr, sal_Int32 asciiStrLength) const
Perform a comparison of two strings.
Definition: ustring.hxx:1175
sal_Int32 indexOf(sal_Unicode ch, sal_Int32 fromIndex=0) const
Returns the index within this string of the first occurrence of the specified character, starting the search at the specified index.
Definition: ustring.hxx:1986
bool equalsIgnoreAsciiCaseAscii(const sal_Char *asciiStr) const
Perform an ASCII lowercase comparison of two strings.
Definition: ustring.hxx:1202
SAL_DLLPUBLIC sal_Int32 rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength(const sal_Unicode *first, sal_Int32 firstLen, const sal_Char *second, sal_Int32 shortenedLen) SAL_THROW_EXTERN_C()
Compare two strings with a maximum count of characters, ignoring the case of ASCII characters...
SAL_DLLPUBLIC void rtl_uString_newFromStr_WithLength(rtl_uString **newStr, const sal_Unicode *value, sal_Int32 len) SAL_THROW_EXTERN_C()
Allocate a new string that contains a copy of a character array.
SAL_DLLPUBLIC sal_Int32 rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength(const sal_Unicode *first, sal_Int32 firstLen, const sal_Char *second) SAL_THROW_EXTERN_C()
Compare two strings, ignoring the case of ASCII characters.
sal_uInt16 sal_Unicode
Definition: types.h:141
SAL_DLLPUBLIC void rtl_uString_newConcat(rtl_uString **newStr, rtl_uString *left, rtl_uString *right) SAL_THROW_EXTERN_C()
Create a new string that is the concatenation of two other strings.
SAL_WARN_UNUSED_RESULT libreoffice_internal::ConstCharArrayDetector< T1, typename libreoffice_internal::ConstCharArrayDetector< T2, OUString >::Type >::Type replaceAll(T1 &from, T2 &to) const
Returns a new string resulting from replacing all occurrences of a given substring with another subst...
Definition: ustring.hxx:2762
OUString(rtl_uString *str)
New string from OUString data.
Definition: ustring.hxx:175
unsigned char sal_Bool
Definition: types.h:38
const sal_Char * getStr() const SAL_RETURNS_NONNULL
Returns a pointer to the characters of this string.
Definition: string.hxx:459
SAL_WARN_UNUSED_RESULT OUString replace(sal_Unicode oldChar, sal_Unicode newChar) const
Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar...
Definition: ustring.hxx:2319
__sal_NoAcquire
Definition: types.h:370
bool equalsIgnoreAsciiCase(const OUString &str) const
Perform an ASCII lowercase comparison of two strings.
Definition: ustring.hxx:848
SAL_DLLPUBLIC void rtl_uString_release(rtl_uString *str) SAL_THROW_EXTERN_C() SAL_HOT
Decrement the reference count of a string.
bool match(const OUString &str, sal_Int32 fromIndex=0) const
Match against a substring appearing in this string.
Definition: ustring.hxx:938
bool convertToString(OString *pTarget, rtl_TextEncoding nEncoding, sal_uInt32 nFlags) const
Converts to an OString, signalling failure.
Definition: ustring.hxx:3264
friend libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator!=(const OUString &rString, T &literal)
Compare string to an ASCII string literal.
Definition: ustring.hxx:1806
SAL_DLLPUBLIC void rtl_uString_new(rtl_uString **newStr) SAL_THROW_EXTERN_C()
Allocate a new string containing no characters.
#define OSTRING_TO_OUSTRING_CVTFLAGS
Definition: ustring.h:2145
SAL_DLLPUBLIC sal_Bool rtl_ustr_toBoolean(const sal_Unicode *str) SAL_THROW_EXTERN_C()
Interpret a string as a boolean.
#define RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR
Definition: textcvt.h:71
SAL_DLLPUBLIC void rtl_uString_ensureCapacity(rtl_uString **str, sal_Int32 size) SAL_THROW_EXTERN_C()
Ensure a string has enough space for a given number of characters.
OUString & operator+=(const OUString &str)
Append a string to this string.
Definition: ustring.hxx:562
SAL_WARN_UNUSED_RESULT OUString copy(sal_Int32 beginIndex, sal_Int32 count) const
Returns a new string that is a substring of this string.
Definition: ustring.hxx:2257
SAL_WARN_UNUSED_RESULT libreoffice_internal::ConstCharArrayDetector< T, OUString >::Type replaceAll(OUString const &from, T &to) const
Returns a new string resulting from replacing all occurrences of a given substring with another subst...
Definition: ustring.hxx:2736
SAL_DLLPUBLIC rtl_uString * rtl_uString_alloc(sal_Int32 nLen) SAL_THROW_EXTERN_C()
Allocate a new string containing space for a given number of characters.
SAL_DLLPUBLIC sal_Int32 rtl_ustr_hashCode_WithLength(const sal_Unicode *str, sal_Int32 len) SAL_THROW_EXTERN_C()
Return a hash code for a string.
SAL_DLLPUBLIC void rtl_uString_newReplaceFirstAsciiL(rtl_uString **newStr, rtl_uString *str, char const *from, sal_Int32 fromLength, rtl_uString const *to, sal_Int32 *index) SAL_THROW_EXTERN_C()
Create a new string by replacing the first occurrence of a given substring with another substring...
sal_uInt16 rtl_TextEncoding
The various supported text encodings.
Definition: textenc.h:33
SAL_DLLPUBLIC void rtl_string2UString(rtl_uString **newStr, const sal_Char *str, sal_Int32 len, rtl_TextEncoding encoding, sal_uInt32 convertFlags) SAL_THROW_EXTERN_C()
Create a new Unicode string by converting a byte string, using a specific text encoding.
~OUString()
Release the string data.
Definition: ustring.hxx:436
SAL_DLLPUBLIC sal_Int32 rtl_uString_getToken(rtl_uString **newStr, rtl_uString *str, sal_Int32 token, sal_Unicode cTok, sal_Int32 idx) SAL_THROW_EXTERN_C()
Create a new string by extracting a single token from another string.
bool matchIgnoreAsciiCaseAsciiL(const sal_Char *asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex=0) const
Match against a substring appearing in this string, ignoring the case of ASCII letters.
Definition: ustring.hxx:1317
#define RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
Definition: textcvt.h:141
sal_Int32 lastIndexOf(const OUString &str) const
Returns the index within this string of the last occurrence of the specified substring, searching backward starting at the end.
Definition: ustring.hxx:2141
SAL_DLLPUBLIC sal_Int64 rtl_ustr_toInt64(const sal_Unicode *str, sal_Int16 radix) SAL_THROW_EXTERN_C()
Interpret a string as a long integer.
Definition: bootstrap.hxx:29
bool endsWithAsciiL(char const *asciiStr, sal_Int32 asciiStrLength) const
Check whether this string ends with a given ASCII string.
Definition: ustring.hxx:1612
SAL_DLLPUBLIC void rtl_uString_newReplace(rtl_uString **newStr, rtl_uString *str, sal_Unicode oldChar, sal_Unicode newChar) SAL_THROW_EXTERN_C()
Create a new string by replacing all occurrences of a single character within another string...
OUString(rtl_uString *str, __sal_NoAcquire)
New OUString from OUString data without acquiring it.
Definition: ustring.hxx:189
SAL_DLLPUBLIC sal_uInt32 rtl_uString_iterateCodePoints(rtl_uString const *string, sal_Int32 *indexUtf16, sal_Int32 incrementCodePoints)
Iterate through a string based on code points instead of UTF-16 code units.
sal_Int32 indexOfAsciiL(char const *str, sal_Int32 len, sal_Int32 fromIndex=0) const
Returns the index within this string of the first occurrence of the specified ASCII substring...
Definition: ustring.hxx:2110
OUString(const sal_Unicode *value)
New string from a Unicode character buffer array.
Definition: ustring.hxx:219
sal_Int32 compareToIgnoreAsciiCaseAscii(const sal_Char *asciiStr) const
Compares two ASCII strings ignoring case.
Definition: ustring.hxx:1225
A helper to use OUStrings with hash maps.
Definition: ustring.hxx:3689
SAL_DLLPUBLIC void rtl_uString_newConcatAsciiL(rtl_uString **newString, rtl_uString *left, char const *right, sal_Int32 rightLength)
Create a new string that is the concatenation of two other strings.
SAL_DLLPUBLIC sal_Int32 rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(sal_Unicode const *first, sal_Int32 firstLen, char const *second, sal_Int32 secondLen) SAL_THROW_EXTERN_C()
Compare two strings, ignoring the case of ASCII characters.
sal_Int32 lastIndexOf(sal_Unicode ch) const
Returns the index within this string of the last occurrence of the specified character, searching backward starting at the end.
Definition: ustring.hxx:2001
SAL_DLLPUBLIC sal_Int32 rtl_ustr_ascii_compare_WithLength(const sal_Unicode *first, sal_Int32 firstLen, const sal_Char *second) SAL_THROW_EXTERN_C()
Compare two strings.
SAL_WARN_UNUSED_RESULT libreoffice_internal::ConstCharArrayDetector< T, OUString >::Type replaceAll(T &from, OUString const &to) const
Returns a new string resulting from replacing all occurrences of a given substring with another subst...
Definition: ustring.hxx:2711
OUString(const OUString &str)
New string from OUString.
Definition: ustring.hxx:147
SAL_DLLPUBLIC sal_Int32 rtl_ustr_indexOfStr_WithLength(const sal_Unicode *str, sal_Int32 len, const sal_Unicode *subStr, sal_Int32 subLen) SAL_THROW_EXTERN_C()
Search for the first occurrence of a substring within a string.
This String class provide base functionality for C++ like 8-Bit character array handling.
Definition: string.hxx:97
libreoffice_internal::ConstCharArrayDetector< T, bool >::Type endsWith(T &literal, OUString *rest=NULL) const
This is an overloaded member function, provided for convenience. It differs from the above function ...
Definition: ustring.hxx:1539
definition of a no acquire enum for ctors
Definition: types.h:374
SAL_DLLPUBLIC sal_Int32 rtl_ustr_lastIndexOfAscii_WithLength(sal_Unicode const *str, sal_Int32 len, char const *subStr, sal_Int32 subLen) SAL_THROW_EXTERN_C()
Search for the last occurrence of an ASCII substring within a string.
SAL_DLLPUBLIC sal_Int32 rtl_ustr_valueOfInt32(sal_Unicode *str, sal_Int32 i, sal_Int16 radix) SAL_THROW_EXTERN_C()
Create the string representation of an integer.
SAL_DLLPUBLIC sal_Int32 rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength(const sal_Unicode *first, sal_Int32 firstLen, const sal_Unicode *second, sal_Int32 secondLen, sal_Int32 shortenedLen) SAL_THROW_EXTERN_C()
Compare two strings with a maximum count of characters, ignoring the case of ASCII characters...
SAL_WARN_UNUSED_RESULT libreoffice_internal::ConstCharArrayDetector< T1, typename libreoffice_internal::ConstCharArrayDetector< T2, OUString >::Type >::Type replaceFirst(T1 &from, T2 &to, sal_Int32 *index=NULL) const
Returns a new string resulting from replacing the first occurrence of a given substring with another ...
Definition: ustring.hxx:2440
SAL_DLLPUBLIC void rtl_uString_newReplaceAllUtf16LAsciiL(rtl_uString **newStr, rtl_uString *str, sal_Unicode const *from, sal_Int32 fromLength, char const *to, sal_Int32 toLength) SAL_THROW_EXTERN_C()
Create a new string by replacing all occurrences of a given substring with another substring...
SAL_WARN_UNUSED_RESULT libreoffice_internal::ConstCharArrayDetector< T, OUString >::Type replaceFirst(OUString const &from, T &to, sal_Int32 *index=NULL) const
Returns a new string resulting from replacing the first occurrence of a given substring with another ...
Definition: ustring.hxx:2406
SAL_DLLPUBLIC void rtl_uString_newReplaceAllAsciiLAsciiL(rtl_uString **newStr, rtl_uString *str, char const *from, sal_Int32 fromLength, char const *to, sal_Int32 toLength) SAL_THROW_EXTERN_C()
Create a new string by replacing all occurrences of a given substring with another substring...
static OUString intern(const sal_Char *value, sal_Int32 length, rtl_TextEncoding encoding, sal_uInt32 convertFlags=OSTRING_TO_OUSTRING_CVTFLAGS, sal_uInt32 *pInfo=NULL)
Return a canonical representation for a converted string.
Definition: ustring.hxx:3226
SAL_DLLPUBLIC sal_Int32 rtl_ustr_indexOfChar_WithLength(const sal_Unicode *str, sal_Int32 len, sal_Unicode ch) SAL_THROW_EXTERN_C()
Search for the first occurrence of a character within a string.
libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type lastIndexOf(T &literal) const
This is an overloaded member function, provided for convenience. It differs from the above function ...
Definition: ustring.hxx:2176
sal_Int32 reverseCompareToAsciiL(const sal_Char *asciiStr, sal_Int32 asciiStrLength) const
Compares two strings in reverse order.
Definition: ustring.hxx:1131
SAL_DLLPUBLIC void rtl_uString_newReplaceFirst(rtl_uString **newStr, rtl_uString *str, rtl_uString const *from, rtl_uString const *to, sal_Int32 *index) SAL_THROW_EXTERN_C()
Create a new string by replacing the first occurrence of a given substring with another substring...
SAL_DLLPUBLIC void rtl_uString_newReplaceFirstUtf16LAsciiL(rtl_uString **newStr, rtl_uString *str, sal_Unicode const *from, sal_Int32 fromLength, char const *to, sal_Int32 toLength, sal_Int32 *index) SAL_THROW_EXTERN_C()
Create a new string by replacing the first occurrence of a given substring with another substring...
SAL_DLLPUBLIC void rtl_uString_newReplaceAllUtf16LUtf16L(rtl_uString **newStr, rtl_uString *str, sal_Unicode const *from, sal_Int32 fromLength, sal_Unicode const *to, sal_Int32 toLength) SAL_THROW_EXTERN_C()
Create a new string by replacing all occurrences of a given substring with another substring...
sal_uInt32 toUInt32(sal_Int16 radix=10) const
Returns the uint32 value from this string.
Definition: ustring.hxx:3112
friend libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator==(T &literal, const OUString &rString)
Compare string to an ASCII string literal.
Definition: ustring.hxx:1790
bool endsWith(OUString const &str, OUString *rest=NULL) const
Check whether this string ends with a given substring.
Definition: ustring.hxx:1523
bool equals(const OUString &str) const
Perform a comparison of two strings.
Definition: ustring.hxx:824
static OUString number(int i, sal_Int16 radix=10)
Returns the string representation of the integer argument.
Definition: ustring.hxx:3419
SAL_DLLPUBLIC void rtl_uString_newFromStr(rtl_uString **newStr, const sal_Unicode *value) SAL_THROW_EXTERN_C()
Allocate a new string that contains a copy of a character array.
SAL_DLLPUBLIC sal_Int32 rtl_ustr_valueOfInt64(sal_Unicode *str, sal_Int64 l, sal_Int16 radix) SAL_THROW_EXTERN_C()
Create the string representation of a long integer.
float toFloat() const
Returns the float value from this string.
Definition: ustring.hxx:3157
SAL_DLLPUBLIC sal_Int32 rtl_ustr_reverseCompare_WithLength(const sal_Unicode *first, sal_Int32 firstLen, const sal_Unicode *second, sal_Int32 secondLen) SAL_THROW_EXTERN_C()
Compare two strings from back to front.
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:126
void clear()
Clears the string, i.e, makes a zero-character string.
Definition: ustring.hxx:669
SAL_DLLPUBLIC void rtl_uString_newReplaceFirstAsciiLUtf16L(rtl_uString **newStr, rtl_uString *str, char const *from, sal_Int32 fromLength, sal_Unicode const *to, sal_Int32 toLength, sal_Int32 *index) SAL_THROW_EXTERN_C()
Create a new string by replacing the first occurrence of a given substring with another substring...
libreoffice_internal::ConstCharArrayDetector< T, OUString &>::Type operator=(T &literal)
Assign a new string from an 8-Bit string literal that is expected to contain only characters in the A...
Definition: ustring.hxx:498
#define SAL_WARN_UNUSED_RESULT
Use this as markup for functions and methods whose return value must be checked.
Definition: types.h:302
OString toUtf8() const
Convert this string to an OString, assuming that the string can be UTF-8-encoded successfully.
Definition: ustring.hxx:3361
SAL_WARN_UNUSED_RESULT libreoffice_internal::ConstCharArrayDetector< T, OUString >::Type replaceFirst(T &from, OUString const &to, sal_Int32 *index=NULL) const
Returns a new string resulting from replacing the first occurrence of a given substring with another ...
Definition: ustring.hxx:2373
char sal_Char
A legacy synonym for char.
Definition: types.h:120
SAL_DLLPUBLIC void rtl_uString_newFromCodePoints(rtl_uString **newString, sal_uInt32 const *codePoints, sal_Int32 codePointCount) SAL_THROW_EXTERN_C()
Allocate a new string from an array of Unicode code points.
#define RTL_USTR_MAX_VALUEOFBOOLEAN
Definition: ustring.h:915
SAL_DLLPUBLIC sal_Int32 rtl_ustr_valueOfFloat(sal_Unicode *str, float f) SAL_THROW_EXTERN_C()
Create the string representation of a float.
SAL_DLLPUBLIC void rtl_uString_newFromSubString(rtl_uString **newStr, const rtl_uString *from, sal_Int32 beginIndex, sal_Int32 count) SAL_THROW_EXTERN_C()
Allocate a new string that is a substring of this string.
static OUString boolean(bool b)
Returns the string representation of the boolean argument.
Definition: ustring.hxx:3515
SAL_DLLPUBLIC void rtl_uString_newReplaceAllAsciiLUtf16L(rtl_uString **newStr, rtl_uString *str, char const *from, sal_Int32 fromLength, sal_Unicode const *to, sal_Int32 toLength) SAL_THROW_EXTERN_C()
Create a new string by replacing all occurrences of a given substring with another substring...
static OUString number(double d)
Returns the string representation of the double argument.
Definition: ustring.hxx:3481
SAL_DLLPUBLIC void rtl_uString_newReplaceFirstUtf16LUtf16L(rtl_uString **newStr, rtl_uString *str, sal_Unicode const *from, sal_Int32 fromLength, sal_Unicode const *to, sal_Int32 toLength, sal_Int32 *index) SAL_THROW_EXTERN_C()
Create a new string by replacing the first occurrence of a given substring with another substring...
SAL_DLLPUBLIC sal_Int32 rtl_ustr_indexOfAscii_WithLength(sal_Unicode const *str, sal_Int32 len, char const *subStr, sal_Int32 subLen) SAL_THROW_EXTERN_C()
Search for the first occurrence of an ASCII substring within a string.
SAL_DLLPUBLIC sal_Int32 rtl_ustr_ascii_shortenedCompare_WithLength(const sal_Unicode *first, sal_Int32 firstLen, const sal_Char *second, sal_Int32 shortenedLen) SAL_THROW_EXTERN_C()
Compare two strings with a maximum count of characters.
friend libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator!=(T &literal, const OUString &rString)
Compare string to an ASCII string literal.
Definition: ustring.hxx:1822
sal_Int32 lastIndexOfAsciiL(char const *str, sal_Int32 len) const
Returns the index within this string of the last occurrence of the specified ASCII substring...
Definition: ustring.hxx:2224
#define RTL_USTR_MAX_VALUEOFINT32
Definition: ustring.h:957
SAL_DLLPUBLIC double rtl_ustr_toDouble(const sal_Unicode *str) SAL_THROW_EXTERN_C()
Interpret a string as a double.
SAL_WARN_UNUSED_RESULT OUString replaceFirst(OUString const &from, OUString const &to, sal_Int32 *index=NULL) const
Returns a new string resulting from replacing the first occurrence of a given substring with another ...
Definition: ustring.hxx:2344
SAL_DLLPUBLIC void rtl_uString_newReplaceAllToAsciiL(rtl_uString **newStr, rtl_uString *str, rtl_uString const *from, char const *to, sal_Int32 toLength) SAL_THROW_EXTERN_C()
Create a new string by replacing all occurrences of a given substring with another substring...
bool equalsAscii(const sal_Char *asciiStr) const
Perform a comparison of two strings.
Definition: ustring.hxx:1152
SAL_WARN_UNUSED_RESULT OUString replaceAt(sal_Int32 index, sal_Int32 count, const OUString &newStr) const
Returns a new string resulting from replacing n = count characters from position index in this string...
Definition: ustring.hxx:2299
#define RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
Definition: textcvt.h:68
sal_Int32 reverseCompareTo(const OUString &str) const
Compares two strings in reverse order.
Definition: ustring.hxx:772
bool isEmpty() const
Checks if a string is empty.
Definition: ustring.hxx:692
OUString(sal_Unicode value)
New string from a single Unicode character.
Definition: ustring.hxx:197
SAL_WARN_UNUSED_RESULT OUString trim() const
Returns a new string resulting from removing white space from both ends of the string.
Definition: ustring.hxx:3005
bool startsWithIgnoreAsciiCase(OUString const &str, OUString *rest=NULL) const
Check whether this string starts with a given string, ignoring the case of ASCII letters.
Definition: ustring.hxx:1436
SAL_DLLPUBLIC sal_Int32 rtl_ustr_valueOfUInt64(sal_Unicode *str, sal_uInt64 l, sal_Int16 radix) SAL_THROW_EXTERN_C()
Create the string representation of an unsigned long integer.
sal_Int64 toInt64(sal_Int16 radix=10) const
Returns the int64 value from this string.
Definition: ustring.hxx:3127
Dummy Type
Definition: stringutils.hxx:279
OUString(const sal_Unicode *value, sal_Int32 length)
New string from a Unicode character buffer array.
Definition: ustring.hxx:233
sal_Int32 lastIndexOf(sal_Unicode ch, sal_Int32 fromIndex) const
Returns the index within this string of the last occurrence of the specified character, searching backward starting before the specified index.
Definition: ustring.hxx:2018
OUString & operator=(const OUString &str)
Assign a new string.
Definition: ustring.hxx:460
bool toBoolean() const
Returns the Boolean value from this string.
Definition: ustring.hxx:3069
OUString(T &literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type=libreoffice_internal::Dummy())
New string from an 8-Bit string literal that is expected to contain only characters in the ASCII set ...
Definition: ustring.hxx:255
sal_Int32 hashCode() const
Returns a hashcode for this string.
Definition: ustring.hxx:1968
#define RTL_USTR_MAX_VALUEOFINT64
Definition: ustring.h:980
SAL_WARN_UNUSED_RESULT OUString replaceAll(OUString const &from, OUString const &to, sal_Int32 fromIndex=0) const
Returns a new string resulting from replacing all occurrences of a given substring with another subst...
Definition: ustring.hxx:2689
bool endsWithIgnoreAsciiCase(OUString const &str, OUString *rest=NULL) const
Check whether this string ends with a given string, ignoring the case of ASCII letters.
Definition: ustring.hxx:1641
static OUString number(long long ll, sal_Int16 radix=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: ustring.hxx:3444
sal_uInt64 toUInt64(sal_Int16 radix=10) const
Returns the uint64 value from this string.
Definition: ustring.hxx:3144
libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type reverseCompareTo(T &literal) const
This is an overloaded member function, provided for convenience. It differs from the above function ...
Definition: ustring.hxx:784
OUString(const sal_Char *value, sal_Int32 length, rtl_TextEncoding encoding, sal_uInt32 convertFlags=OSTRING_TO_OUSTRING_CVTFLAGS)
New string from an 8-Bit character buffer array.
Definition: ustring.hxx:357
OUString()
New string containing no characters.
Definition: ustring.hxx:136
Dummy Type
Definition: stringutils.hxx:301
SAL_DLLPUBLIC sal_Int32 rtl_ustr_valueOfDouble(sal_Unicode *str, double d) SAL_THROW_EXTERN_C()
Create the string representation of a double.
OUString intern() const
Return a canonical representation for a string.
Definition: ustring.hxx:3191
sal_Int32 compareToAscii(const sal_Char *asciiStr) const
Compares two strings.
Definition: ustring.hxx:1077
SAL_DLLPUBLIC sal_Bool rtl_convertUStringToString(rtl_String **pTarget, sal_Unicode const *pSource, sal_Int32 nLength, rtl_TextEncoding nEncoding, sal_uInt32 nFlags) SAL_THROW_EXTERN_C()
Converts a Unicode string to a byte string, signalling failure.
static OUString number(long i, sal_Int16 radix=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: ustring.hxx:3432