LibreOffice
LibreOffice 7.6 SDK C/C++ API Reference
Loading...
Searching...
No Matches
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/*
21 * This file is part of LibreOffice published API.
22 */
23
24#ifndef INCLUDED_RTL_USTRING_HXX
25#define INCLUDED_RTL_USTRING_HXX
26
27#include "sal/config.h"
28
29#include <cassert>
30#include <cstddef>
31#include <cstdlib>
32#include <limits>
33#include <new>
34#include <ostream>
35#include <utility>
36
37#if defined LIBO_INTERNAL_ONLY
38#include <algorithm>
39#include <string_view>
40#include <type_traits>
41#endif
42
43#include "rtl/math.h"
44#include "rtl/ustring.h"
45#include "rtl/string.hxx"
46#include "rtl/stringutils.hxx"
47#include "rtl/textenc.h"
48
49#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
50#include "config_global.h"
51#include "o3tl/safeint.hxx"
52#include "rtl/stringconcat.hxx"
53#endif
54
55#ifdef RTL_STRING_UNITTEST
56extern bool rtl_string_unittest_invalid_conversion;
57#endif
58
59// The unittest uses slightly different code to help check that the proper
60// calls are made. The class is put into a different namespace to make
61// sure the compiler generates a different (if generating also non-inline)
62// copy of the function and does not merge them together. The class
63// is "brought" into the proper rtl namespace by a typedef below.
64#ifdef RTL_STRING_UNITTEST
65#define rtl rtlunittest
66#endif
67
68namespace rtl
69{
70
71class OUStringBuffer;
72
73#ifdef RTL_STRING_UNITTEST
74#undef rtl
75#endif
76
77#if defined LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
79
86template<std::size_t N> class SAL_WARN_UNUSED OUStringLiteral {
87 static_assert(N != 0);
88 static_assert(N - 1 <= std::numeric_limits<sal_Int32>::max(), "literal too long");
89 friend class OUString;
90 friend class OUStringConstExpr;
91
92public:
93#if HAVE_CPP_CONSTEVAL
94 consteval
95#else
96 constexpr
97#endif
98 OUStringLiteral(char16_t const (&literal)[N]) {
99 assertLayout();
100 assert(literal[N - 1] == '\0');
101 //TODO: Use C++20 constexpr std::copy_n (P0202R3):
102 for (std::size_t i = 0; i != N; ++i) {
103 more.buffer[i] = literal[i];
104 }
105 }
106
107 constexpr sal_Int32 getLength() const { return more.length; }
108
109 constexpr sal_Unicode const * getStr() const SAL_RETURNS_NONNULL { return more.buffer; }
110
111 constexpr operator std::u16string_view() const { return {more.buffer, sal_uInt32(more.length)}; }
112
113private:
114 static constexpr void assertLayout() {
115 // These static_asserts verifying the layout compatibility with rtl_uString cannot be class
116 // member declarations, as offsetof requires a complete type, so defer them to here:
117 static_assert(std::is_standard_layout_v<OUStringLiteral>);
118 static_assert(offsetof(OUStringLiteral, str.refCount) == offsetof(OUStringLiteral, more.refCount));
119 static_assert(offsetof(OUStringLiteral, str.length) == offsetof(OUStringLiteral, more.length));
120 static_assert(offsetof(OUStringLiteral, str.buffer) == offsetof(OUStringLiteral, more.buffer));
121 }
122
123 struct Data {
124 Data() = default;
125
126 oslInterlockedCount refCount = 0x40000000; // SAL_STRING_STATIC_FLAG (sal/rtl/strimp.hxx)
127 sal_Int32 length = N - 1;
128 sal_Unicode buffer[N] = {}; //TODO: drop initialization for C++20 (P1331R2)
129 };
130
131 union {
132 rtl_uString str;
133 Data more = {};
134 };
135};
136
137#if defined RTL_STRING_UNITTEST
138namespace libreoffice_internal {
139template<std::size_t N> struct ExceptConstCharArrayDetector<OUStringLiteral<N>> {};
140template<std::size_t N> struct ExceptCharArrayDetector<OUStringLiteral<N>> {};
141}
142#endif
143
152class OUString;
153class OUStringConstExpr
154{
155public:
156 template<std::size_t N> constexpr OUStringConstExpr(OUStringLiteral<N> const & literal):
157 pData(const_cast<rtl_uString *>(&literal.str)) {}
158
159 // prevent mis-use
160 template<std::size_t N> constexpr OUStringConstExpr(OUStringLiteral<N> && literal)
161 = delete;
162
163 // no destructor necessary because we know we are pointing at a compile-time
164 // constant OUStringLiteral, which bypasses ref-counting.
165
169 constexpr std::u16string_view asView() const { return std::u16string_view(pData->buffer, pData->length); }
170
171 inline operator const OUString&() const;
172
173private:
174 rtl_uString* pData;
175};
176
178#endif
179
180/* ======================================================================= */
181
206{
207public:
209 rtl_uString * pData;
211
216 {
217 pData = NULL;
218 rtl_uString_new( &pData );
219 }
220
227 {
228 pData = str.pData;
229 rtl_uString_acquire( pData );
230 }
231
232#if defined LIBO_INTERNAL_ONLY
239 OUString( OUString && str ) noexcept
240 {
241 pData = str.pData;
242 str.pData = nullptr;
243 rtl_uString_new( &str.pData );
244 }
245#endif
246
253 {
254 pData = str;
255 rtl_uString_acquire( pData );
256 }
257
258#if defined LIBO_INTERNAL_ONLY
260 // Catch inadvertent conversions to the above ctor:
261 OUString(std::nullptr_t) = delete;
263#endif
264
275
281 explicit OUString( sal_Unicode value )
282 : pData (NULL)
283 {
284 rtl_uString_newFromStr_WithLength( &pData, &value, 1 );
285 }
286
287#if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST_CONCAT
289 // Catch inadvertent conversions to the above ctor (but still allow
290 // construction from char literals):
291 OUString(int) = delete;
292 explicit OUString(char c):
294 {}
296#endif
297
298#if defined LIBO_INTERNAL_ONLY
299
300 template<typename T> explicit OUString(
301 T const & value,
302 typename libreoffice_internal::CharPtrDetector<T, libreoffice_internal::Dummy>::TypeUtf16
303 = libreoffice_internal::Dummy()):
304 pData(nullptr)
305 { rtl_uString_newFromStr(&pData, value); }
306
307 template<typename T> explicit OUString(
308 T & value,
309 typename
310 libreoffice_internal::NonConstCharArrayDetector<T, libreoffice_internal::Dummy>::TypeUtf16
311 = libreoffice_internal::Dummy()):
312 pData(nullptr)
313 { rtl_uString_newFromStr(&pData, value); }
314
315#else
316
322 OUString( const sal_Unicode * value )
323 {
324 pData = NULL;
325 rtl_uString_newFromStr( &pData, value );
326 }
327
328#endif
329
338 OUString( const sal_Unicode * value, sal_Int32 length )
339 {
340 pData = NULL;
341 rtl_uString_newFromStr_WithLength( &pData, value, length );
342 }
343
359 template< typename T >
378
379#if defined LIBO_INTERNAL_ONLY
381 template<typename T> OUString(
382 T & literal,
384 T, libreoffice_internal::Dummy>::TypeUtf16
386 pData(nullptr)
387 {
388 assert(
391 rtl_uString_new(&pData);
392 } else {
394 &pData,
395 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
396 literal),
397 libreoffice_internal::ConstCharArrayDetector<T>::length);
398 }
399 }
400#endif
401
402#if defined LIBO_INTERNAL_ONLY && defined RTL_STRING_UNITTEST
404
408 template< typename T >
409 OUString( T&, typename libreoffice_internal::ExceptConstCharArrayDetector< T >::Type = libreoffice_internal::Dummy() )
410 {
411 pData = NULL;
412 rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
413 rtl_string_unittest_invalid_conversion = true;
414 }
419 template< typename T >
420 OUString( const T&, typename libreoffice_internal::ExceptCharArrayDetector< T >::Type = libreoffice_internal::Dummy() )
421 {
422 pData = NULL;
423 rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
424 rtl_string_unittest_invalid_conversion = true;
425 }
427#endif
428
429#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
431
436 template<std::size_t N> constexpr OUString(OUStringLiteral<N> const & literal):
437 pData(const_cast<rtl_uString *>(&literal.str)) {}
438 template<std::size_t N> OUString(OUStringLiteral<N> &&) = delete;
440#endif
441
456 OUString( const char * value, sal_Int32 length,
459 {
460 pData = NULL;
461 rtl_string2UString( &pData, value, length, encoding, convertFlags );
462 if (pData == NULL) {
463 throw std::bad_alloc();
464 }
465 }
466
483 explicit OUString(
485 pData(NULL)
486 {
488 if (pData == NULL) {
489 throw std::bad_alloc();
490 }
491 }
492
493#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
498 template< typename T1, typename T2 >
500 {
501 const sal_Int32 l = c.length();
502 pData = rtl_uString_alloc( l );
503 if (l != 0)
504 {
505 sal_Unicode* end = c.addData( pData->buffer );
506 pData->length = l;
507 *end = '\0';
508 }
509 }
510
515 template< std::size_t N >
516 OUString( OUStringNumber< N >&& n )
517 : OUString( n.buf, n.length )
518 {}
519#endif
520
521#if defined LIBO_INTERNAL_ONLY
522 explicit OUString(std::u16string_view sv) {
523 if (sv.size() > sal_uInt32(std::numeric_limits<sal_Int32>::max())) {
524 throw std::bad_alloc();
525 }
526 pData = nullptr;
527 rtl_uString_newFromStr_WithLength(&pData, sv.data(), sv.size());
528 }
529#endif
530
534#if defined LIBO_INTERNAL_ONLY && __cplusplus >= 202002L
535 constexpr
536#endif
538 {
539#if defined LIBO_INTERNAL_ONLY && __cplusplus >= 202002L
540 if (std::is_constant_evaluated()) {
541 //TODO: We would want to
542 //
543 // assert(SAL_STRING_IS_STATIC(pData));
544 //
545 // here, but that wouldn't work because read of member `str` of OUStringLiteral's
546 // anonymous union with active member `more` is not allowed in a constant expression.
547 } else
548#endif
549 rtl_uString_release( pData );
550 }
551
563 static OUString const & unacquired( rtl_uString * const * ppHandle )
564 { return * reinterpret_cast< OUString const * >( ppHandle ); }
565
566#if defined LIBO_INTERNAL_ONLY
579 static OUString const& unacquired(const OUStringBuffer& str);
580#endif
581
588 {
589 rtl_uString_assign( &pData, str.pData );
590 return *this;
591 }
592
593#if defined LIBO_INTERNAL_ONLY
600 OUString & operator=( OUString && str ) noexcept
601 {
602 std::swap(pData, str.pData);
603 return *this;
604 }
605#endif
606
619 template< typename T >
635
636#if defined LIBO_INTERNAL_ONLY
638 template<typename T>
639 typename
641 operator =(T & literal) {
643 rtl_uString_new(&pData);
644 } else {
646 &pData,
647 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
648 literal),
649 libreoffice_internal::ConstCharArrayDetector<T>::length);
650 }
651 return *this;
652 }
653
655 template<std::size_t N> OUString & operator =(OUStringLiteral<N> const & literal) {
656 rtl_uString_release(pData);
657 pData = const_cast<rtl_uString *>(&literal.str);
658 return *this;
659 }
660 template<std::size_t N> OUString & operator =(OUStringLiteral<N> &&) = delete;
661
662 template <std::size_t N>
663 OUString & operator =(OUStringNumber<N> && n) {
664 // n.length should never be zero, so no need to add an optimization for that case
665 rtl_uString_newFromStr_WithLength(&pData, n.buf, n.length);
666 return *this;
667 }
668
669 OUString & operator =(std::u16string_view sv) {
670 if (sv.empty()) {
671 rtl_uString_new(&pData);
672 } else {
673 rtl_uString_newFromStr_WithLength(&pData, sv.data(), sv.size());
674 }
675 return *this;
676 }
677#endif
678
679#if defined LIBO_INTERNAL_ONLY
688 inline OUString & operator+=( const OUStringBuffer & str ) &;
689#endif
690
699#if defined LIBO_INTERNAL_ONLY
700 &
701#endif
702 {
703 return internalAppend(str.pData);
704 }
705#if defined LIBO_INTERNAL_ONLY
706 void operator+=(OUString const &) && = delete;
707#endif
708
715 template<typename T>
730#if defined LIBO_INTERNAL_ONLY
731 template<typename T>
733 operator +=(T &) && = delete;
734#endif
735
736#if defined LIBO_INTERNAL_ONLY
738 template<typename T>
739 typename
741 operator +=(T & literal) & {
743 &pData, pData,
746 return *this;
747 }
748 template<typename T>
749 typename
750 libreoffice_internal::ConstCharArrayDetector<T, OUString &>::TypeUtf16
751 operator +=(T &) && = delete;
752
754 template<std::size_t N> OUString & operator +=(OUStringLiteral<N> const & literal) & {
755 rtl_uString_newConcatUtf16L(&pData, pData, literal.getStr(), literal.getLength());
756 return *this;
757 }
758 template<std::size_t N> void operator +=(OUStringLiteral<N> const &) && = delete;
759
760 OUString & operator +=(std::u16string_view sv) & {
761 if (sv.size() > sal_uInt32(std::numeric_limits<sal_Int32>::max())) {
762 throw std::bad_alloc();
763 }
764 rtl_uString_newConcatUtf16L(&pData, pData, sv.data(), sv.size());
765 return *this;
766 }
767 void operator +=(std::u16string_view) && = delete;
768#endif
769
770#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
775 template< typename T1, typename T2 >
776 OUString& operator+=( OUStringConcat< T1, T2 >&& c ) & {
777 sal_Int32 l = c.length();
778 if( l == 0 )
779 return *this;
780 l += pData->length;
781 rtl_uString_ensureCapacity( &pData, l );
782 sal_Unicode* end = c.addData( pData->buffer + pData->length );
783 *end = '\0';
784 pData->length = l;
785 return *this;
786 }
787 template<typename T1, typename T2> void operator +=(
788 OUStringConcat<T1, T2> &&) && = delete;
789
794 template< std::size_t N >
795 OUString& operator+=( OUStringNumber< N >&& n ) & {
796 sal_Int32 l = n.length;
797 if( l == 0 )
798 return *this;
799 l += pData->length;
800 rtl_uString_ensureCapacity( &pData, l );
801 sal_Unicode* end = addDataHelper( pData->buffer + pData->length, n.buf, n.length );
802 *end = '\0';
803 pData->length = l;
804 return *this;
805 }
806 template<std::size_t N> void operator +=(
807 OUStringNumber<N> &&) && = delete;
808#endif
809
814 void clear()
815 {
816 rtl_uString_new( &pData );
817 }
818
827 sal_Int32 getLength() const { return pData->length; }
828
837 bool isEmpty() const
838 {
839 return pData->length == 0;
840 }
841
849 const sal_Unicode * getStr() const SAL_RETURNS_NONNULL { return pData->buffer; }
850
861 // silence spurious -Werror=strict-overflow warnings from GCC 4.8.2
862 assert(index >= 0 && static_cast<sal_uInt32>(index) < static_cast<sal_uInt32>(getLength()));
863 return getStr()[index];
864 }
865
878#if defined LIBO_INTERNAL_ONLY
879 sal_Int32 compareTo( std::u16string_view str ) const
880 {
881 return rtl_ustr_compare_WithLength( pData->buffer, pData->length,
882 str.data(), str.length() );
883 }
884#else
886 {
887 return rtl_ustr_compare_WithLength( pData->buffer, pData->length,
888 str.pData->buffer, str.pData->length );
889 }
890#endif
891
907#if defined LIBO_INTERNAL_ONLY
908 sal_Int32 compareTo( std::u16string_view str, sal_Int32 maxLength ) const
909 {
910 return rtl_ustr_shortenedCompare_WithLength( pData->buffer, pData->length,
911 str.data(), str.length(), maxLength );
912 }
913#else
915 {
916 return rtl_ustr_shortenedCompare_WithLength( pData->buffer, pData->length,
917 str.pData->buffer, str.pData->length, maxLength );
918 }
919#endif
920
933#if defined LIBO_INTERNAL_ONLY
934 sal_Int32 reverseCompareTo(std::u16string_view sv) const {
936 pData->buffer, pData->length, sv.data(), sv.size());
937 }
938#else
940 {
941 return rtl_ustr_reverseCompare_WithLength( pData->buffer, pData->length,
942 str.pData->buffer, str.pData->length );
943 }
944#endif
945
951 template< typename T >
961
973 bool equals( const OUString & str ) const
974 {
975 if ( pData->length != str.pData->length )
976 return false;
977 if ( pData == str.pData )
978 return true;
979 return rtl_ustr_reverseCompare_WithLength( pData->buffer, pData->length,
980 str.pData->buffer, str.pData->length ) == 0;
981 }
982
997#if defined LIBO_INTERNAL_ONLY
998 bool equalsIgnoreAsciiCase(std::u16string_view sv) const {
999 if ( sal_uInt32(pData->length) != sv.size() )
1000 return false;
1001 if ( pData->buffer == sv.data() )
1002 return true;
1003 return
1005 pData->buffer, pData->length, sv.data(), sv.size())
1006 == 0;
1007 }
1008#else
1009 bool equalsIgnoreAsciiCase( const OUString & str ) const
1010 {
1011 if ( pData->length != str.pData->length )
1012 return false;
1013 if ( pData == str.pData )
1014 return true;
1015 return rtl_ustr_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
1016 str.pData->buffer, str.pData->length ) == 0;
1017 }
1018#endif
1019
1035#if defined LIBO_INTERNAL_ONLY
1036 sal_Int32 compareToIgnoreAsciiCase(std::u16string_view sv) const {
1038 pData->buffer, pData->length, sv.data(), sv.size());
1039 }
1040#else
1042 {
1043 return rtl_ustr_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
1044 str.pData->buffer, str.pData->length );
1045 }
1046#endif
1047
1053 template< typename T >
1067
1083#if defined LIBO_INTERNAL_ONLY
1084 bool match(std::u16string_view sv, sal_Int32 fromIndex = 0) const {
1085 return
1087 pData->buffer + fromIndex, pData->length - fromIndex, sv.data(), sv.size(),
1088 sv.size())
1089 == 0;
1090 }
1091#else
1092 bool match( const OUString & str, sal_Int32 fromIndex = 0 ) const
1093 {
1094 return rtl_ustr_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1095 str.pData->buffer, str.pData->length, str.pData->length ) == 0;
1096 }
1097#endif
1098
1104 template< typename T >
1117
1136#if defined LIBO_INTERNAL_ONLY
1137 bool matchIgnoreAsciiCase(std::u16string_view sv, sal_Int32 fromIndex = 0) const {
1138 return
1140 pData->buffer + fromIndex, pData->length - fromIndex, sv.data(), sv.size(),
1141 sv.size())
1142 == 0;
1143 }
1144#else
1146 {
1147 return rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1148 str.pData->buffer, str.pData->length,
1149 str.pData->length ) == 0;
1150 }
1151#endif
1152
1158 template< typename T >
1167
1184 sal_Int32 compareToAscii( const char* asciiStr ) const
1185 {
1186 return rtl_ustr_ascii_compare_WithLength( pData->buffer, pData->length, asciiStr );
1187 }
1188
1212 "replace s1.compareToAscii(s2, strlen(s2)) == 0 with s1.startsWith(s2)")
1213 sal_Int32 compareToAscii( const char * asciiStr, sal_Int32 maxLength ) const
1214 {
1215 return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer, pData->length,
1217 }
1218
1238 {
1239 return rtl_ustr_asciil_reverseCompare_WithLength( pData->buffer, pData->length,
1241 }
1242
1258 bool equalsAscii( const char* asciiStr ) const
1259 {
1260 return rtl_ustr_ascii_compare_WithLength( pData->buffer, pData->length,
1261 asciiStr ) == 0;
1262 }
1263
1281 {
1282 if ( pData->length != asciiStrLength )
1283 return false;
1284
1286 pData->buffer, asciiStr, asciiStrLength );
1287 }
1288
1307 bool equalsIgnoreAsciiCaseAscii( const char * asciiStr ) const
1308 {
1309 return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr ) == 0;
1310 }
1311
1312#if defined LIBO_INTERNAL_ONLY
1313 bool equalsIgnoreAsciiCaseAscii( std::string_view asciiStr ) const
1314 {
1315 return o3tl::make_unsigned(pData->length) == asciiStr.length()
1317 pData->buffer, pData->length, asciiStr.data(), asciiStr.length()) == 0;
1318 }
1319#endif
1320
1340 {
1341 return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr );
1342 }
1343
1344#if defined LIBO_INTERNAL_ONLY
1345 sal_Int32 compareToIgnoreAsciiCaseAscii( std::string_view asciiStr ) const
1346 {
1347 sal_Int32 nMax = std::min<size_t>(asciiStr.length(), std::numeric_limits<sal_Int32>::max());
1349 pData->buffer, pData->length, asciiStr.data(), nMax);
1350 if (result == 0 && o3tl::make_unsigned(pData->length) < asciiStr.length())
1351 result = -1;
1352 return result;
1353 }
1354#endif
1355
1376 {
1377 if ( pData->length != asciiStrLength )
1378 return false;
1379
1380 return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr ) == 0;
1381 }
1382
1404 {
1405 return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1406 asciiStr, asciiStrLength ) == 0;
1407 }
1408
1409 // This overload is left undefined, to detect calls of matchAsciiL that
1410 // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
1411 // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
1412 // platforms):
1413#if SAL_TYPES_SIZEOFLONG == 8
1414 void matchAsciiL(char const *, sal_Int32, rtl_TextEncoding) const;
1415#endif
1416
1445
1446 // This overload is left undefined, to detect calls of
1447 // matchIgnoreAsciiCaseAsciiL that erroneously use
1448 // RTL_CONSTASCII_USTRINGPARAM instead of RTL_CONSTASCII_STRINGPARAM (but
1449 // would lead to ambiguities on 32 bit platforms):
1450#if SAL_TYPES_SIZEOFLONG == 8
1451 void matchIgnoreAsciiCaseAsciiL(char const *, sal_Int32, rtl_TextEncoding)
1452 const;
1453#endif
1454
1469#if defined LIBO_INTERNAL_ONLY
1470 bool startsWith(std::u16string_view sv, OUString * rest = nullptr) const {
1471 auto const b = match(sv);
1472 if (b && rest != nullptr) {
1473 *rest = copy(sv.size());
1474 }
1475 return b;
1476 }
1477#else
1478 bool startsWith(OUString const & str, OUString * rest = NULL) const {
1479 bool b = match(str);
1480 if (b && rest != NULL) {
1481 *rest = copy(str.getLength());
1482 }
1483 return b;
1484 }
1485#endif
1486
1492 template< typename T >
1512
1533#if defined LIBO_INTERNAL_ONLY
1534 bool startsWithIgnoreAsciiCase(std::u16string_view sv, OUString * rest = nullptr) const {
1535 auto const b = matchIgnoreAsciiCase(sv);
1536 if (b && rest != nullptr) {
1537 *rest = copy(sv.size());
1538 }
1539 return b;
1540 }
1541#else
1543 const
1544 {
1545 bool b = matchIgnoreAsciiCase(str);
1546 if (b && rest != NULL) {
1547 *rest = copy(str.getLength());
1548 }
1549 return b;
1550 }
1551#endif
1552
1558 template< typename T >
1580
1595#if defined LIBO_INTERNAL_ONLY
1596 bool endsWith(std::u16string_view sv, OUString * rest = nullptr) const {
1597 auto const b = sv.size() <= sal_uInt32(pData->length)
1598 && match(sv, pData->length - sv.size());
1599 if (b && rest != nullptr) {
1600 *rest = copy(0, (pData->length - sv.size()));
1601 }
1602 return b;
1603 }
1604#else
1605 bool endsWith(OUString const & str, OUString * rest = NULL) const {
1606 bool b = str.getLength() <= getLength()
1607 && match(str, getLength() - str.getLength());
1608 if (b && rest != NULL) {
1609 *rest = copy(0, getLength() - str.getLength());
1610 }
1611 return b;
1612 }
1613#endif
1614
1620 template< typename T >
1643
1656 const
1657 {
1658 return asciiStrLength <= pData->length
1660 pData->buffer + pData->length - asciiStrLength, asciiStr,
1662 }
1663
1684#if defined LIBO_INTERNAL_ONLY
1685 bool endsWithIgnoreAsciiCase(std::u16string_view sv, OUString * rest = nullptr) const {
1686 auto const b = sv.size() <= sal_uInt32(pData->length)
1687 && matchIgnoreAsciiCase(sv, pData->length - sv.size());
1688 if (b && rest != nullptr) {
1689 *rest = copy(0, pData->length - sv.size());
1690 }
1691 return b;
1692 }
1693#else
1695 {
1696 bool b = str.getLength() <= getLength()
1697 && matchIgnoreAsciiCase(str, getLength() - str.getLength());
1698 if (b && rest != NULL) {
1699 *rest = copy(0, getLength() - str.getLength());
1700 }
1701 return b;
1702 }
1703#endif
1704
1710 template< typename T >
1735
1747 char const * asciiStr, sal_Int32 asciiStrLength) const
1748 {
1749 return asciiStrLength <= pData->length
1751 pData->buffer + pData->length - asciiStrLength,
1753 == 0);
1754 }
1755
1756 friend bool operator == ( const OUString& rStr1, const OUString& rStr2 )
1757 { return rStr1.equals(rStr2); }
1758
1759 friend bool operator != ( const OUString& rStr1, const OUString& rStr2 )
1760 { return !(operator == ( rStr1, rStr2 )); }
1761
1762 friend bool operator < ( const OUString& rStr1, const OUString& rStr2 )
1763 { return rStr1.compareTo( rStr2 ) < 0; }
1764 friend bool operator > ( const OUString& rStr1, const OUString& rStr2 )
1765 { return rStr1.compareTo( rStr2 ) > 0; }
1766 friend bool operator <= ( const OUString& rStr1, const OUString& rStr2 )
1767 { return rStr1.compareTo( rStr2 ) <= 0; }
1768 friend bool operator >= ( const OUString& rStr1, const OUString& rStr2 )
1769 { return rStr1.compareTo( rStr2 ) >= 0; }
1770
1771#if defined LIBO_INTERNAL_ONLY
1772
1773 template<typename T> friend typename libreoffice_internal::CharPtrDetector<T, bool>::TypeUtf16
1774 operator ==(OUString const & s1, T const & s2) {
1775 return rtl_ustr_compare_WithLength(s1.getStr(), s1.getLength(), s2, rtl_ustr_getLength(s2))
1776 == 0;
1777 }
1778
1779 template<typename T>
1780 friend typename libreoffice_internal::NonConstCharArrayDetector<T, bool>::TypeUtf16
1781 operator ==(OUString const & s1, T & s2) {
1782 return rtl_ustr_compare_WithLength(s1.getStr(), s1.getLength(), s2, rtl_ustr_getLength(s2))
1783 == 0;
1784 }
1785
1786 template<typename T> friend typename libreoffice_internal::CharPtrDetector<T, bool>::TypeUtf16
1787 operator ==(T const & s1, OUString const & s2) {
1788 return rtl_ustr_compare_WithLength(s1, rtl_ustr_getLength(s1), s2.getStr(), s2.getLength())
1789 == 0;
1790 }
1791
1792 template<typename T>
1793 friend typename libreoffice_internal::NonConstCharArrayDetector<T, bool>::TypeUtf16
1794 operator ==(T & s1, OUString const & s2) {
1795 return rtl_ustr_compare_WithLength(s1, rtl_ustr_getLength(s1), s2.getStr(), s2.getLength())
1796 == 0;
1797 }
1798
1799 template<typename T> friend typename libreoffice_internal::CharPtrDetector<T, bool>::TypeUtf16
1800 operator !=(OUString const & s1, T const & s2) { return !(s1 == s2); }
1801
1802 template<typename T>
1803 friend typename libreoffice_internal::NonConstCharArrayDetector<T, bool>::TypeUtf16
1804 operator !=(OUString const & s1, T & s2) { return !(s1 == s2); }
1805
1806 template<typename T> friend typename libreoffice_internal::CharPtrDetector<T, bool>::TypeUtf16
1807 operator !=(T const & s1, OUString const & s2) { return !(s1 == s2); }
1808
1809 template<typename T>
1810 friend typename libreoffice_internal::NonConstCharArrayDetector<T, bool>::TypeUtf16
1811 operator !=(T & s1, OUString const & s2) { return !(s1 == s2); }
1812
1813#else
1814
1815 friend bool operator == ( const OUString& rStr1, const sal_Unicode * pStr2 )
1816 { return rStr1.compareTo( pStr2 ) == 0; }
1817 friend bool operator == ( const sal_Unicode * pStr1, const OUString& rStr2 )
1818 { return OUString( pStr1 ).compareTo( rStr2 ) == 0; }
1819
1820 friend bool operator != ( const OUString& rStr1, const sal_Unicode * pStr2 )
1821 { return !(operator == ( rStr1, pStr2 )); }
1822 friend bool operator != ( const sal_Unicode * pStr1, const OUString& rStr2 )
1823 { return !(operator == ( pStr1, rStr2 )); }
1824
1825#endif
1826
1834 template< typename T >
1850 template< typename T >
1866 template< typename T >
1882 template< typename T >
1891
1892#if defined LIBO_INTERNAL_ONLY
1894 template<typename T> friend typename libreoffice_internal::ConstCharArrayDetector<T, bool>::TypeUtf16
1895 operator ==(OUString const & string, T & literal) {
1896 return
1898 string.pData->buffer, string.pData->length,
1900 literal),
1902 == 0;
1903 }
1905 template<typename T> friend typename libreoffice_internal::ConstCharArrayDetector<T, bool>::TypeUtf16
1906 operator ==(T & literal, OUString const & string) {
1907 return
1909 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
1910 literal),
1911 libreoffice_internal::ConstCharArrayDetector<T>::length,
1912 string.pData->buffer, string.pData->length)
1913 == 0;
1914 }
1916 template<typename T> friend typename libreoffice_internal::ConstCharArrayDetector<T, bool>::TypeUtf16
1917 operator !=(OUString const & string, T & literal) {
1918 return
1920 string.pData->buffer, string.pData->length,
1921 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
1922 literal),
1923 libreoffice_internal::ConstCharArrayDetector<T>::length)
1924 != 0;
1925 }
1927 template<typename T> friend typename libreoffice_internal::ConstCharArrayDetector<T, bool>::TypeUtf16
1928 operator !=(T & literal, OUString const & string) {
1929 return
1931 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
1932 literal),
1933 libreoffice_internal::ConstCharArrayDetector<T>::length,
1934 string.pData->buffer, string.pData->length)
1935 != 0;
1936 }
1937#endif
1938
1947 {
1948 return rtl_ustr_hashCode_WithLength( pData->buffer, pData->length );
1949 }
1950
1965 {
1966 sal_Int32 ret = rtl_ustr_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
1967 return (ret < 0 ? ret : ret+fromIndex);
1968 }
1969
1980 {
1981 return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
1982 }
1983
2000
2016#if defined LIBO_INTERNAL_ONLY
2017 sal_Int32 indexOf(std::u16string_view sv, sal_Int32 fromIndex = 0) const {
2018 auto const n = rtl_ustr_indexOfStr_WithLength(
2019 pData->buffer + fromIndex, pData->length - fromIndex, sv.data(), sv.size());
2020 return n < 0 ? n : n + fromIndex;
2021 }
2022#else
2024 {
2025 sal_Int32 ret = rtl_ustr_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
2026 str.pData->buffer, str.pData->length );
2027 return (ret < 0 ? ret : ret+fromIndex);
2028 }
2029#endif
2030
2036 template< typename T >
2047
2072 char const * str, sal_Int32 len, sal_Int32 fromIndex = 0) const
2073 {
2075 pData->buffer + fromIndex, pData->length - fromIndex, str, len);
2076 return ret < 0 ? ret : ret + fromIndex;
2077 }
2078
2079 // This overload is left undefined, to detect calls of indexOfAsciiL that
2080 // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
2081 // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
2082 // platforms):
2083#if SAL_TYPES_SIZEOFLONG == 8
2084 void indexOfAsciiL(char const *, sal_Int32 len, rtl_TextEncoding) const;
2085#endif
2086
2102#if defined LIBO_INTERNAL_ONLY
2103 sal_Int32 lastIndexOf(std::u16string_view sv) const {
2105 pData->buffer, pData->length, sv.data(), sv.size());
2106 }
2107#else
2109 {
2110 return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, pData->length,
2111 str.pData->buffer, str.pData->length );
2112 }
2113#endif
2114
2132#if defined LIBO_INTERNAL_ONLY
2133 sal_Int32 lastIndexOf(std::u16string_view sv, sal_Int32 fromIndex) const {
2134 return rtl_ustr_lastIndexOfStr_WithLength(pData->buffer, fromIndex, sv.data(), sv.size());
2135 }
2136#else
2138 {
2139 return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
2140 str.pData->buffer, str.pData->length );
2141 }
2142#endif
2143
2149 template< typename T >
2159
2180 {
2182 pData->buffer, pData->length, str, len);
2183 }
2184
2196 {
2197 return copy(beginIndex, getLength() - beginIndex);
2198 }
2199
2218
2219#if defined LIBO_INTERNAL_ONLY
2230 SAL_WARN_UNUSED_RESULT std::u16string_view subView( sal_Int32 beginIndex ) const
2231 {
2232 assert(beginIndex >= 0);
2233 assert(beginIndex <= getLength());
2234 return subView(beginIndex, getLength() - beginIndex);
2235 }
2236
2249 SAL_WARN_UNUSED_RESULT std::u16string_view subView( sal_Int32 beginIndex, sal_Int32 count ) const
2250 {
2251 assert(beginIndex >= 0);
2252 assert(count >= 0);
2253 assert(beginIndex <= getLength());
2254 assert(count <= getLength() - beginIndex);
2255 return std::u16string_view(*this).substr(beginIndex, count);
2256 }
2257#endif
2258
2259#ifndef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2268 SAL_WARN_UNUSED_RESULT OUString concat( const OUString & str ) const
2269 {
2271 rtl_uString_newConcat( &pNew, pData, str.pData );
2272 return OUString( pNew, SAL_NO_ACQUIRE );
2273 }
2274#endif
2275
2276#ifndef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2278 {
2279 return rStr1.concat( rStr2 );
2280 }
2281#endif
2282
2283// hide this from internal code to avoid ambiguous lookup error
2284#ifndef LIBO_INTERNAL_ONLY
2299 {
2301 rtl_uString_newReplaceStrAt( &pNew, pData, index, count, newStr.pData );
2302 return OUString( pNew, SAL_NO_ACQUIRE );
2303 }
2304#endif
2305
2306#ifdef LIBO_INTERNAL_ONLY
2307 SAL_WARN_UNUSED_RESULT OUString replaceAt( sal_Int32 index, sal_Int32 count, std::u16string_view newStr ) const
2308 {
2310 rtl_uString_newReplaceStrAtUtf16L( &pNew, pData, index, count, newStr.data(), newStr.size() );
2311 return OUString( pNew, SAL_NO_ACQUIRE );
2312 }
2313#endif
2314
2334
2353#if defined LIBO_INTERNAL_ONLY
2354 [[nodiscard]] OUString replaceFirst(
2355 std::u16string_view from, std::u16string_view to, sal_Int32 * index = nullptr) const
2356 {
2357 rtl_uString * s = nullptr;
2358 sal_Int32 i = 0;
2360 &s, pData, from.data(), from.size(), to.data(), to.size(),
2361 index == nullptr ? &i : index);
2362 return OUString(s, SAL_NO_ACQUIRE);
2363 }
2364#else
2366 OUString const & from, OUString const & to, sal_Int32 * index = NULL) const
2367 {
2368 rtl_uString * s = NULL;
2369 sal_Int32 i = 0;
2371 &s, pData, from.pData, to.pData, index == NULL ? &i : index);
2372 return OUString(s, SAL_NO_ACQUIRE);
2373 }
2374#endif
2375
2394#if defined LIBO_INTERNAL_ONLY
2395 template<typename T> [[nodiscard]]
2397 T & from, std::u16string_view to, sal_Int32 * index = nullptr) const
2398 {
2400 rtl_uString * s = nullptr;
2401 sal_Int32 i = 0;
2405 index == nullptr ? &i : index);
2406 return OUString(s, SAL_NO_ACQUIRE);
2407 }
2408#else
2409 template< typename T >
2423#endif
2424
2443#if defined LIBO_INTERNAL_ONLY
2444 template<typename T> [[nodiscard]]
2446 std::u16string_view from, T & to, sal_Int32 * index = nullptr) const
2447 {
2449 rtl_uString * s = nullptr;
2450 sal_Int32 i = 0;
2452 &s, pData, from.data(), from.size(),
2454 libreoffice_internal::ConstCharArrayDetector<T>::length, index == nullptr ? &i : index);
2455 return OUString(s, SAL_NO_ACQUIRE);
2456 }
2457#else
2458 template< typename T >
2472#endif
2473
2492 template< typename T1, typename T2 >
2509
2525#if defined LIBO_INTERNAL_ONLY
2526 [[nodiscard]] OUString replaceAll(
2527 std::u16string_view from, std::u16string_view to, sal_Int32 fromIndex = 0) const
2528 {
2529 rtl_uString * s = nullptr;
2531 &s, pData, from.data(), from.size(), to.data(), to.size(), fromIndex);
2532 return OUString(s, SAL_NO_ACQUIRE);
2533 }
2534#else
2536 OUString const & from, OUString const & to, sal_Int32 fromIndex = 0) const
2537 {
2538 rtl_uString * s = NULL;
2539 rtl_uString_newReplaceAllFromIndex(&s, pData, from.pData, to.pData, fromIndex);
2540 return OUString(s, SAL_NO_ACQUIRE);
2541 }
2542#endif
2543
2557#if defined LIBO_INTERNAL_ONLY
2558 template<typename T> [[nodiscard]]
2560 T & from, std::u16string_view to) const
2561 {
2563 rtl_uString * s = nullptr;
2567 return OUString(s, SAL_NO_ACQUIRE);
2568 }
2569#else
2570 template< typename T >
2581#endif
2582
2596#if defined LIBO_INTERNAL_ONLY
2597 template<typename T> [[nodiscard]]
2599 std::u16string_view from, T & to) const
2600 {
2602 rtl_uString * s = nullptr;
2604 &s, pData, from.data(), from.size(),
2607 return OUString(s, SAL_NO_ACQUIRE);
2608 }
2609#else
2610 template< typename T >
2621#endif
2622
2636 template< typename T1, typename T2 >
2651
2668
2685
2700 {
2702 rtl_uString_newTrim( &pNew, pData );
2703 return OUString( pNew, SAL_NO_ACQUIRE );
2704 }
2705
2731 {
2732 rtl_uString * pNew = NULL;
2733 index = rtl_uString_getToken( &pNew, pData, token, cTok, index );
2734 return OUString( pNew, SAL_NO_ACQUIRE );
2735 }
2736
2751 sal_Int32 n = 0;
2752 return getToken(count, separator, n);
2753 }
2754
2763 bool toBoolean() const
2764 {
2765 return rtl_ustr_toBoolean( pData->buffer );
2766 }
2767
2775 {
2776 return pData->buffer[0];
2777 }
2778
2790 {
2791 return rtl_ustr_toInt32( pData->buffer, radix );
2792 }
2793
2807 {
2808 return rtl_ustr_toUInt32( pData->buffer, radix );
2809 }
2810
2822 {
2823 return rtl_ustr_toInt64( pData->buffer, radix );
2824 }
2825
2839 {
2840 return rtl_ustr_toUInt64( pData->buffer, radix );
2841 }
2842
2851 float toFloat() const
2852 {
2853 return rtl_ustr_toFloat( pData->buffer );
2854 }
2855
2864 double toDouble() const
2865 {
2866 return rtl_ustr_toDouble( pData->buffer );
2867 }
2868
2869
2886 {
2887 rtl_uString * pNew = NULL;
2888 rtl_uString_intern( &pNew, pData );
2889 if (pNew == NULL) {
2890 throw std::bad_alloc();
2891 }
2892 return OUString( pNew, SAL_NO_ACQUIRE );
2893 }
2894
2920 static OUString intern( const char * value, sal_Int32 length,
2923 sal_uInt32 *pInfo = NULL )
2924 {
2925 rtl_uString * pNew = NULL;
2926 rtl_uString_internConvert( &pNew, value, length, encoding,
2928 if (pNew == NULL) {
2929 throw std::bad_alloc();
2930 }
2931 return OUString( pNew, SAL_NO_ACQUIRE );
2932 }
2933
2959 sal_uInt32 nFlags) const
2960 {
2961 return rtl_convertUStringToString(&pTarget->pData, pData->buffer,
2962 pData->length, nEncoding, nFlags);
2963 }
2964
3022
3032#if defined LIBO_INTERNAL_ONLY
3033 static OUString fromUtf8(std::string_view rSource)
3034 {
3037 rSource.data(),
3038 rSource.length(),
3041 (void) bSuccess;
3042 assert(bSuccess);
3043 return aTarget;
3044 }
3045#else
3058#endif
3059
3071 {
3074 getStr(),
3075 getLength(),
3078 (void) bSuccess;
3079 assert(bSuccess);
3080 return aTarget;
3081 }
3082
3083#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
3084
3085 static auto number( int i, sal_Int16 radix = 10 )
3086 {
3088 }
3089 static auto number( long long ll, sal_Int16 radix = 10 )
3090 {
3091 return OUStringNumber<RTL_USTR_MAX_VALUEOFINT64>(rtl_ustr_valueOfInt64, ll, radix);
3092 }
3093 static auto number( unsigned long long ll, sal_Int16 radix = 10 )
3094 {
3095 return OUStringNumber<RTL_USTR_MAX_VALUEOFUINT64>(rtl_ustr_valueOfUInt64, ll, radix);
3096 }
3097 static auto number( unsigned int i, sal_Int16 radix = 10 )
3098 {
3099 return number( static_cast< unsigned long long >( i ), radix );
3100 }
3101 static auto number( long i, sal_Int16 radix = 10)
3102 {
3103 return number( static_cast< long long >( i ), radix );
3104 }
3105 static auto number( unsigned long i, sal_Int16 radix = 10 )
3106 {
3107 return number( static_cast< unsigned long long >( i ), radix );
3108 }
3109#else
3127 static OUString number( unsigned int i, sal_Int16 radix = 10 )
3128 {
3129 return number( static_cast< unsigned long long >( i ), radix );
3130 }
3133 static OUString number( long i, sal_Int16 radix = 10)
3134 {
3135 return number( static_cast< long long >( i ), radix );
3136 }
3139 static OUString number( unsigned long i, sal_Int16 radix = 10 )
3140 {
3141 return number( static_cast< unsigned long long >( i ), radix );
3142 }
3145 static OUString number( long long ll, sal_Int16 radix = 10 )
3146 {
3149 }
3152 static OUString number( unsigned long long ll, sal_Int16 radix = 10 )
3153 {
3156 }
3157#endif
3158
3168 static OUString number( float f )
3169 {
3171 // Same as rtl::str::valueOfFP, used for rtl_ustr_valueOfFloat
3173 RTL_USTR_MAX_VALUEOFFLOAT - SAL_N_ELEMENTS("-x.E-xxx") + 1, '.',
3174 NULL, 0, true);
3175 if (pNew == NULL)
3176 throw std::bad_alloc();
3177
3178 return OUString(pNew, SAL_NO_ACQUIRE);
3179 }
3180
3190 static OUString number( double d )
3191 {
3193 // Same as rtl::str::valueOfFP, used for rtl_ustr_valueOfDouble
3195 RTL_USTR_MAX_VALUEOFDOUBLE - SAL_N_ELEMENTS("-x.E-xxx") + 1, '.',
3196 NULL, 0, true);
3197 if (pNew == NULL)
3198 throw std::bad_alloc();
3199
3200 return OUString(pNew, SAL_NO_ACQUIRE);
3201 }
3202
3203#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
3204 static auto boolean(bool b)
3205 {
3207 }
3208#else
3220 SAL_DEPRECATED("use boolean()") static OUString valueOf( sal_Bool b )
3221 {
3222 return boolean(b);
3223 }
3224
3241#endif
3242
3250 SAL_DEPRECATED("convert to OUString or use directly") static OUString valueOf( sal_Unicode c )
3251 {
3252 return OUString( &c, 1 );
3253 }
3254
3265 SAL_DEPRECATED("use number()") static OUString valueOf( sal_Int32 i, sal_Int16 radix = 10 )
3266 {
3267 return number( i, radix );
3268 }
3269
3280 SAL_DEPRECATED("use number()") static OUString valueOf( sal_Int64 ll, sal_Int16 radix = 10 )
3281 {
3282 return number( ll, radix );
3283 }
3284
3294 SAL_DEPRECATED("use number()") static OUString valueOf( float f )
3295 {
3296 return number(f);
3297 }
3298
3308 SAL_DEPRECATED("use number()") static OUString valueOf( double d )
3309 {
3310 return number(d);
3311 }
3312
3328 static OUString createFromAscii( const char * value )
3329 {
3331 rtl_uString_newFromAscii( &pNew, value );
3332 return OUString( pNew, SAL_NO_ACQUIRE );
3333 }
3334
3335#if defined LIBO_INTERNAL_ONLY
3336 static OUString createFromAscii(std::string_view value) {
3337 rtl_uString * p = nullptr;
3338 rtl_uString_newFromLiteral(&p, value.data(), value.size(), 0); //TODO: check for overflow
3339 return OUString(p, SAL_NO_ACQUIRE);
3340 }
3341 #endif
3342
3343#if defined LIBO_INTERNAL_ONLY
3344 operator std::u16string_view() const { return {getStr(), sal_uInt32(getLength())}; }
3345#endif
3346
3347#if defined LIBO_INTERNAL_ONLY
3348 // A wrapper for the first expression in an
3349 //
3350 // OUString::Concat(e1) + e2 + ...
3351 //
3352 // concatenation chain, when neither of the first two e1, e2 is one of our rtl string-related
3353 // classes (so something like
3354 //
3355 // OUString s = "a" + (b ? std::u16string_view(u"c") : std::u16string_view(u"dd"));
3356 //
3357 // would not compile):
3358 template<typename T> [[nodiscard]] static
3359 OUStringConcat<OUStringConcatMarker, T>
3360 Concat(T const & value) { return OUStringConcat<OUStringConcatMarker, T>(value); }
3361
3362 // This overload is needed so that an argument of type 'char const[N]' ends up as
3363 // 'OUStringConcat<rtl::OUStringConcatMarker, char const[N]>' rather than as
3364 // 'OUStringConcat<rtl::OUStringConcatMarker, char[N]>':
3365 template<typename T, std::size_t N> [[nodiscard]] static
3366 OUStringConcat<OUStringConcatMarker, T[N]>
3367 Concat(T (& value)[N]) { return OUStringConcat<OUStringConcatMarker, T[N]>(value); }
3368#endif
3369
3370private:
3371 OUString & internalAppend( rtl_uString* pOtherData )
3372 {
3373 rtl_uString* pNewData = NULL;
3374 rtl_uString_newConcat( &pNewData, pData, pOtherData );
3375 if (pNewData == NULL) {
3376 throw std::bad_alloc();
3377 }
3378 rtl_uString_assign(&pData, pNewData);
3379 rtl_uString_release(pNewData);
3380 return *this;
3381 }
3382
3383};
3384
3385#if defined LIBO_INTERNAL_ONLY
3386// Can only define this after we define OUString
3387inline OUStringConstExpr::operator const OUString &() const { return OUString::unacquired(&pData); }
3388#endif
3389
3390#if defined LIBO_INTERNAL_ONLY
3391// Prevent the operator ==/!= overloads with 'sal_Unicode const *' parameter from
3392// being selected for nonsensical code like
3393//
3394// if (ouIdAttr == nullptr)
3395//
3396void operator ==(OUString const &, std::nullptr_t) = delete;
3397void operator ==(std::nullptr_t, OUString const &) = delete;
3398void operator !=(OUString const &, std::nullptr_t) = delete;
3399void operator !=(std::nullptr_t, OUString const &) = delete;
3400#endif
3401
3402#if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
3403inline bool operator ==(OUString const & lhs, StringConcatenation<char16_t> const & rhs)
3404{ return lhs == std::u16string_view(rhs); }
3405inline bool operator !=(OUString const & lhs, StringConcatenation<char16_t> const & rhs)
3406{ return lhs != std::u16string_view(rhs); }
3407inline bool operator ==(StringConcatenation<char16_t> const & lhs, OUString const & rhs)
3408{ return std::u16string_view(lhs) == rhs; }
3409inline bool operator !=(StringConcatenation<char16_t> const & lhs, OUString const & rhs)
3410{ return std::u16string_view(lhs) != rhs; }
3411#endif
3412
3413#if defined LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
3415
3419template<>
3420struct ToStringHelper< OUString >
3421{
3422 static std::size_t length( const OUString& s ) { return s.getLength(); }
3423 sal_Unicode* operator() ( sal_Unicode* buffer, const OUString& s ) const { return addDataHelper( buffer, s.getStr(), s.getLength()); }
3424};
3425
3429template<std::size_t N>
3430struct ToStringHelper< OUStringLiteral<N> >
3431{
3432 static std::size_t length( const OUStringLiteral<N>& str ) { return str.getLength(); }
3433 sal_Unicode* operator()( sal_Unicode* buffer, const OUStringLiteral<N>& str ) const { return addDataHelper( buffer, str.getStr(), str.getLength() ); }
3434};
3435
3439template< typename charT, typename traits, typename T1, typename T2 >
3440inline std::basic_ostream<charT, traits> & operator <<(
3441 std::basic_ostream<charT, traits> & stream, OUStringConcat< T1, T2 >&& concat)
3442{
3443 return stream << OUString( std::move(concat) );
3444}
3445
3447#endif
3448
3455{
3465 size_t operator()(const OUString& rString) const
3466 { return static_cast<size_t>(rString.hashCode()); }
3467};
3468
3469/* ======================================================================= */
3470
3488#if defined LIBO_INTERNAL_ONLY
3489inline OUString OStringToOUString( std::string_view rStr,
3490 rtl_TextEncoding encoding,
3491 sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS )
3492{
3493 return OUString( rStr.data(), rStr.length(), encoding, convertFlags );
3494}
3495#else
3502#endif
3503
3521#if defined LIBO_INTERNAL_ONLY
3522inline OString OUStringToOString( std::u16string_view rUnicode,
3523 rtl_TextEncoding encoding,
3524 sal_uInt32 convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS )
3525{
3526 return OString( rUnicode.data(), rUnicode.length(), encoding, convertFlags );
3527}
3528#else
3532{
3533 return OString( rUnicode.getStr(), rUnicode.getLength(), encoding, convertFlags );
3534}
3535#endif
3536
3537/* ======================================================================= */
3538
3547template< typename charT, typename traits >
3548inline std::basic_ostream<charT, traits> & operator <<(
3549 std::basic_ostream<charT, traits> & stream, OUString const & rString)
3550{
3551 return stream <<
3553 // best effort; potentially loses data due to conversion failures
3554 // (stray surrogate halves) and embedded null characters
3555}
3556
3557} // namespace
3558
3559#ifdef RTL_STRING_UNITTEST
3560namespace rtl
3561{
3562typedef rtlunittest::OUString OUString;
3563}
3564#endif
3565
3566// In internal code, allow to use classes like OUString without having to
3567// explicitly refer to the rtl namespace, which is kind of superfluous given
3568// that OUString itself is namespaced by its OU prefix:
3569#if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
3570using ::rtl::OUString;
3571using ::rtl::OUStringHash;
3572using ::rtl::OStringToOUString;
3573using ::rtl::OUStringToOString;
3574using ::rtl::OUStringLiteral;
3575using ::rtl::OUStringChar;
3576using ::rtl::Concat2View;
3577#endif
3578
3580
3585#if defined LIBO_INTERNAL_ONLY
3586namespace std {
3587
3588template<>
3589struct hash<::rtl::OUString>
3590{
3591 std::size_t operator()(::rtl::OUString const & s) const
3592 {
3593 if constexpr (sizeof(std::size_t) == 8)
3594 {
3595 // return a hash that uses the full 64-bit range instead of a 32-bit value
3596 size_t n = s.getLength();
3597 for (sal_Int32 i = 0, len = s.getLength(); i < len; ++i)
3598 n = 37 * n + s[i];
3599 return n;
3600 }
3601 else
3602 return std::size_t(s.hashCode());
3603 }
3604};
3605
3606}
3607
3608#endif
3610
3611#endif /* _RTL_USTRING_HXX */
3612
3613/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define SAL_N_ELEMENTS(arr)
Definition macros.h:51
#define SAL_DEPRECATED(message)
Use as follows: SAL_DEPRECATED("Don't use, it's evil.") void doit(int nPara);.
Definition types.h:474
__sal_NoAcquire
Definition types.h:353
@ SAL_NO_ACQUIRE
definition of a no acquire enum for ctors
Definition types.h:356
unsigned char sal_Bool
Definition types.h:38
sal_uInt16 sal_Unicode
Definition types.h:123
#define SAL_WARN_UNUSED_RESULT
Use this as markup for functions and methods whose return value must be checked.
Definition types.h:284
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition types.h:587
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_DLLPUBLIC void rtl_uString_assign(rtl_uString **str, rtl_uString *rightValue) SAL_THROW_EXTERN_C()
Assign a new value to a string.
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 float rtl_ustr_toFloat(const sal_Unicode *str) SAL_THROW_EXTERN_C()
Interpret a string as a float.
SAL_DLLPUBLIC sal_Int32 rtl_ustr_ascii_shortenedCompare_WithLength(const sal_Unicode *first, sal_Int32 firstLen, const char *second, sal_Int32 shortenedLen) SAL_THROW_EXTERN_C()
Compare two strings with a maximum count of characters.
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:2187
#define RTL_USTR_MAX_VALUEOFFLOAT
Definition ustring.h:1026
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.
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.
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_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 sal_Int32 rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength(const sal_Unicode *first, sal_Int32 firstLen, const 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 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.
#define RTL_USTR_MAX_VALUEOFDOUBLE
Definition ustring.h:1045
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_Bool rtl_ustr_asciil_reverseEquals_WithLength(const sal_Unicode *first, const char *second, sal_Int32 len) SAL_THROW_EXTERN_C()
Compare two strings from back to front for equality.
SAL_DLLPUBLIC void rtl_uString_newFromLiteral(rtl_uString **newStr, const char *value, sal_Int32 len, sal_Int32 allocExtra) SAL_THROW_EXTERN_C()
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.
SAL_DLLPUBLIC sal_Int32 rtl_ustr_valueOfBoolean(sal_Unicode *str, sal_Bool b) SAL_THROW_EXTERN_C()
Create the string representation of a boolean.
SAL_DLLPUBLIC double rtl_ustr_toDouble(const sal_Unicode *str) SAL_THROW_EXTERN_C()
Interpret a string as a double.
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_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.
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.
#define RTL_USTR_MAX_VALUEOFINT64
Definition ustring.h:984
SAL_DLLPUBLIC sal_Int32 rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength(const sal_Unicode *first, sal_Int32 firstLen, const char *second) SAL_THROW_EXTERN_C()
Compare two strings, ignoring the case of ASCII characters.
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.
SAL_DLLPUBLIC void rtl_uString_internConvert(rtl_uString **newStr, const 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.
SAL_DLLPUBLIC void rtl_uString_acquire(rtl_uString *str) SAL_THROW_EXTERN_C() SAL_HOT
Increment the reference count of a string.
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.
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.
#define RTL_USTR_MAX_VALUEOFUINT64
Definition ustring.h:1007
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.
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.
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_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_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.
SAL_DLLPUBLIC void rtl_uString_release(rtl_uString *str) SAL_THROW_EXTERN_C() SAL_HOT
Decrement the reference count of a string.
SAL_DLLPUBLIC sal_Int32 rtl_ustr_getLength(const sal_Unicode *str) SAL_THROW_EXTERN_C()
Return the length of a string.
SAL_DLLPUBLIC void rtl_uString_newFromAscii(rtl_uString **newStr, const char *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.
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 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_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 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_uInt64 rtl_ustr_toUInt64(const sal_Unicode *str, sal_Int16 radix) SAL_THROW_EXTERN_C()
Interpret a string as an unsigned long integer.
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_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_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.
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.
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.
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.
SAL_DLLPUBLIC void rtl_uString_intern(rtl_uString **newStr, rtl_uString *str) SAL_THROW_EXTERN_C()
Return a canonical representation for a string.
SAL_DLLPUBLIC void rtl_string2UString(rtl_uString **newStr, const 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.
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_asciil_reverseCompare_WithLength(const sal_Unicode *first, sal_Int32 firstLen, const char *second, sal_Int32 secondLen) SAL_THROW_EXTERN_C()
Compare two strings from back to front.
SAL_DLLPUBLIC sal_Int32 rtl_ustr_ascii_compare_WithLength(const sal_Unicode *first, sal_Int32 firstLen, const char *second) SAL_THROW_EXTERN_C()
Compare two strings.
#define RTL_USTR_MAX_VALUEOFBOOLEAN
Definition ustring.h:919
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_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.
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_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.
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_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.
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_valueOfInt32(sal_Unicode *str, sal_Int32 i, sal_Int16 radix) SAL_THROW_EXTERN_C()
Create the string representation of an integer.
SAL_DLLPUBLIC sal_Bool rtl_ustr_toBoolean(const sal_Unicode *str) SAL_THROW_EXTERN_C()
Interpret a string as a boolean.
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.
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_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_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.
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_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_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.
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.
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.
#define RTL_USTR_MAX_VALUEOFINT32
Definition ustring.h:961
#define RTL_TEXTENCODING_UTF8
Definition textenc.h:117
sal_uInt16 rtl_TextEncoding
The various supported text encodings.
Definition textenc.h:37
SAL_DLLPUBLIC void rtl_math_doubleToUString(rtl_uString **pResult, sal_Int32 *pResultCapacity, sal_Int32 nResultOffset, double fValue, enum rtl_math_StringFormat eFormat, sal_Int32 nDecPlaces, sal_Unicode cDecSeparator, sal_Int32 const *pGroups, sal_Unicode cGroupSeparator, sal_Bool bEraseTrailingDecZeros) SAL_THROW_EXTERN_C()
Conversions analogous to sprintf() using internal rounding.
@ rtl_math_StringFormat_G
Like sprintf() G, 'F' or 'E' format is used depending on which one is more compact.
Definition math.h:53
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.
#define OUSTRING_TO_OSTRING_CVTFLAGS
Definition string.h:1358
#define RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR
Definition textcvt.h:151
#define RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR
Definition textcvt.h:75
#define RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
Definition textcvt.h:72
#define RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR
Definition textcvt.h:68
#define RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
Definition textcvt.h:145
sal_Int32 oslInterlockedCount
Definition interlck.h:44
Definition bootstrap.hxx:34
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,...
Definition string.hxx:2352
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:3496
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:3529
Template reference class for reference type.
Definition ref.hxx:46
Reference()
Constructor...
Definition ref.hxx:55
This String class provide base functionality for C++ like 8-Bit character array handling.
Definition string.hxx:217
Definition stringutils.hxx:140
Definition stringutils.hxx:143
A string buffer implements a mutable sequence of characters.
Definition ustrbuf.hxx:73
This String class provides base functionality for C++ like Unicode character array handling.
Definition ustring.hxx:206
static OUString number(int i, sal_Int16 radix=10)
Returns the string representation of the integer argument.
Definition ustring.hxx:3120
OUString intern() const
Return a canonical representation for a string.
Definition ustring.hxx:2885
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 o...
Definition ustring.hxx:2037
bool endsWith(OUString const &str, OUString *rest=NULL) const
Check whether this string ends with a given substring.
Definition ustring.hxx:1605
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:1746
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:2662
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:2571
const sal_Unicode * getStr() const SAL_RETURNS_NONNULL
Returns a pointer to the Unicode character buffer for this string.
Definition ustring.hxx:849
bool equalsIgnoreAsciiCase(const OUString &str) const
Perform an ASCII lowercase comparison of two strings.
Definition ustring.hxx:1009
bool endsWithAsciiL(char const *asciiStr, sal_Int32 asciiStrLength) const
Check whether this string ends with a given ASCII string.
Definition ustring.hxx:1655
OUString(const OUString &str)
New string from OUString.
Definition ustring.hxx:226
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:3016
static OUString fromUtf8(const OString &rSource)
Convert an OString to an OUString, assuming that the OString is UTF-8-encoded.
Definition ustring.hxx:3046
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 o...
Definition ustring.hxx:1105
sal_Int32 toInt32(sal_Int16 radix=10) const
Returns the int32 value from this string.
Definition ustring.hxx:2789
void clear()
Clears the string, i.e, makes a zero-character string.
Definition ustring.hxx:814
bool equalsIgnoreAsciiCaseAsciiL(const char *asciiStr, sal_Int32 asciiStrLength) const
Perform an ASCII lowercase comparison of two strings.
Definition ustring.hxx:1375
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:3152
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:2071
SAL_WARN_UNUSED_RESULT libreoffice_internal::ConstCharArrayDetector< T1, typenamelibreoffice_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:2638
~OUString()
Release the string data.
Definition ustring.hxx:537
sal_Int32 compareTo(const OUString &str, sal_Int32 maxLength) const
Compares two strings with a maximum count of characters.
Definition ustring.hxx:914
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:2179
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,...
Definition ustring.hxx:1964
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:2611
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:3145
bool matchAsciiL(const char *asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex=0) const
Match against a substring appearing in this string.
Definition ustring.hxx:1403
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:2535
float toFloat() const
Returns the float value from this string.
Definition ustring.hxx:2851
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:3139
static OUString createFromAscii(const char *value)
Returns an OUString copied without conversion from an ASCII character string.
Definition ustring.hxx:3328
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:2410
SAL_WARN_UNUSED_RESULT libreoffice_internal::ConstCharArrayDetector< T1, typenamelibreoffice_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:2494
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:2328
sal_Int32 hashCode() const
Returns a hashcode for this string.
Definition ustring.hxx:1946
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 o...
Definition ustring.hxx:952
friend libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator==(T &literal, const OUString &rString)
Compare string to an ASCII string literal.
Definition ustring.hxx:1851
friend libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator==(const OUString &rString, T &literal)
Compare string to an ASCII string literal.
Definition ustring.hxx:1835
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:3133
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 o...
Definition ustring.hxx:1054
sal_uInt64 toUInt64(sal_Int16 radix=10) const
Returns the uint64 value from this string.
Definition ustring.hxx:2838
bool matchIgnoreAsciiCaseAsciiL(const 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:1440
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 o...
Definition ustring.hxx:1560
OString toUtf8() const
Convert this string to an OString, assuming that the string can be UTF-8-encoded successfully.
Definition ustring.hxx:3070
sal_Int32 reverseCompareToAsciiL(const char *asciiStr, sal_Int32 asciiStrLength) const
Compares two strings in reverse order.
Definition ustring.hxx:1237
bool equalsAsciiL(const char *asciiStr, sal_Int32 asciiStrLength) const
Perform a comparison of two strings.
Definition ustring.hxx:1280
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:3127
bool convertToString(OString *pTarget, rtl_TextEncoding nEncoding, sal_uInt32 nFlags) const
Converts to an OString, signalling failure.
Definition ustring.hxx:2958
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 o...
Definition ustring.hxx:1493
OUString(rtl_uString *str)
New string from OUString data.
Definition ustring.hxx:252
OUString(const sal_Unicode *value, sal_Int32 length)
New string from a Unicode character buffer array.
Definition ustring.hxx:338
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:1694
sal_Int32 compareTo(const OUString &str) const
Compares two strings.
Definition ustring.hxx:885
friend libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator!=(const OUString &rString, T &literal)
Compare string to an ASCII string literal.
Definition ustring.hxx:1867
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:620
bool startsWith(OUString const &str, OUString *rest=NULL) const
Check whether this string starts with a given substring.
Definition ustring.hxx:1478
sal_Int32 lastIndexOf(sal_Unicode ch) const
Returns the index within this string of the last occurrence of the specified character,...
Definition ustring.hxx:1979
sal_Int32 compareToIgnoreAsciiCaseAscii(const char *asciiStr) const
Compares two ASCII strings ignoring case.
Definition ustring.hxx:1339
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:2459
OUString(sal_Unicode value)
New string from a single Unicode character.
Definition ustring.hxx:281
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:2365
sal_Int64 toInt64(sal_Int16 radix=10) const
Returns the int64 value from this string.
Definition ustring.hxx:2821
sal_uInt32 toUInt32(sal_Int16 radix=10) const
Returns the uint32 value from this string.
Definition ustring.hxx:2806
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:1542
sal_Int32 lastIndexOf(const OUString &str, sal_Int32 fromIndex) const
Returns the index within this string of the last occurrence of the specified substring,...
Definition ustring.hxx:2137
static OUString const & unacquired(rtl_uString *const *ppHandle)
Provides an OUString const & passing a storage pointer of an rtl_uString * handle.
Definition ustring.hxx:563
double toDouble() const
Returns the double value from this string.
Definition ustring.hxx:2864
bool equalsAscii(const char *asciiStr) const
Perform a comparison of two strings.
Definition ustring.hxx:1258
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 o...
Definition ustring.hxx:1159
OUString getToken(sal_Int32 token, sal_Unicode cTok, sal_Int32 &index) const
Returns a token in the string.
Definition ustring.hxx:2730
sal_Int32 getLength() const
Returns the length of this string.
Definition ustring.hxx:827
bool equalsIgnoreAsciiCaseAscii(const char *asciiStr) const
Perform an ASCII lowercase comparison of two strings.
Definition ustring.hxx:1307
OUString()
New string containing no characters.
Definition ustring.hxx:215
OUString(const sal_Unicode *value)
New string from a Unicode character buffer array.
Definition ustring.hxx:322
OUString(const 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:456
OUString & operator=(const OUString &str)
Assign a new string.
Definition ustring.hxx:587
static OUString number(float f)
Returns the string representation of the float argument.
Definition ustring.hxx:3168
bool isEmpty() const
Checks if a string is empty.
Definition ustring.hxx:837
sal_Int32 compareToIgnoreAsciiCase(const OUString &str) const
Perform an ASCII lowercase comparison of two strings.
Definition ustring.hxx:1041
OUString(sal_uInt32 const *codePoints, sal_Int32 codePointCount)
Create a new string from an array of Unicode code points.
Definition ustring.hxx:483
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 o...
Definition ustring.hxx:1622
OUString & operator+=(const OUString &str)
Append a string to this string.
Definition ustring.hxx:698
sal_Unicode toChar() const
Returns the first character from this string.
Definition ustring.hxx:2774
OUString getToken(sal_Int32 count, sal_Unicode separator) const
Returns a token from the string.
Definition ustring.hxx:2750
static OUString boolean(bool b)
Returns the string representation of the boolean argument.
Definition ustring.hxx:3236
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 o...
Definition ustring.hxx:2150
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:2212
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 o...
Definition ustring.hxx:1712
OUString(rtl_uString *str, __sal_NoAcquire)
New OUString from OUString data without acquiring it.
Definition ustring.hxx:273
sal_Int32 lastIndexOf(sal_Unicode ch, sal_Int32 fromIndex) const
Returns the index within this string of the last occurrence of the specified character,...
Definition ustring.hxx:1996
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:2699
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:2679
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:2298
bool match(const OUString &str, sal_Int32 fromIndex=0) const
Match against a substring appearing in this string.
Definition ustring.hxx:1092
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:1145
sal_Int32 compareToAscii(const char *asciiStr) const
Compares two strings.
Definition ustring.hxx:1184
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:360
sal_Int32 reverseCompareTo(const OUString &str) const
Compares two strings in reverse order.
Definition ustring.hxx:939
static OUString number(double d)
Returns the string representation of the double argument.
Definition ustring.hxx:3190
friend OUString operator+(const OUString &rStr1, const OUString &rStr2)
Definition ustring.hxx:2277
SAL_WARN_UNUSED_RESULT OUString copy(sal_Int32 beginIndex) const
Returns a new string that is a substring of this string.
Definition ustring.hxx:2195
friend libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator!=(T &literal, const OUString &rString)
Compare string to an ASCII string literal.
Definition ustring.hxx:1883
bool equals(const OUString &str) const
Perform a comparison of two strings.
Definition ustring.hxx:973
sal_Int32 lastIndexOf(const OUString &str) const
Returns the index within this string of the last occurrence of the specified substring,...
Definition ustring.hxx:2108
bool toBoolean() const
Returns the Boolean value from this string.
Definition ustring.hxx:2763
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,...
Definition ustring.hxx:2023
static OUString intern(const 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:2920
A helper to use OUStrings with hash maps.
Definition ustring.hxx:3455
size_t operator()(const OUString &rString) const
Compute a hash code for a string.
Definition ustring.hxx:3465