LibreOffice
LibreOffice 7.6 SDK C/C++ API Reference
Loading...
Searching...
No Matches
string.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_STRING_HXX
25#define INCLUDED_RTL_STRING_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#include <string.h>
37
38#if defined LIBO_INTERNAL_ONLY
39#include <string_view>
40#include <type_traits>
41#endif
42
43#include "rtl/math.h"
44#include "rtl/textenc.h"
45#include "rtl/string.h"
46#include "rtl/stringutils.hxx"
47
48#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
49#include "config_global.h"
50#include "rtl/stringconcat.hxx"
51#endif
52
53#ifdef RTL_STRING_UNITTEST
54extern bool rtl_string_unittest_const_literal;
55extern bool rtl_string_unittest_const_literal_function;
56#endif
57
58// The unittest uses slightly different code to help check that the proper
59// calls are made. The class is put into a different namespace to make
60// sure the compiler generates a different (if generating also non-inline)
61// copy of the function and does not merge them together. The class
62// is "brought" into the proper rtl namespace by a typedef below.
63#ifdef RTL_STRING_UNITTEST
64#define rtl rtlunittest
65#endif
66
67namespace rtl
68{
69
71#ifdef RTL_STRING_UNITTEST
72#undef rtl
73// helper macro to make functions appear more readable
74#define RTL_STRING_CONST_FUNCTION rtl_string_unittest_const_literal_function = true;
75#else
76#define RTL_STRING_CONST_FUNCTION
77#endif
79
80#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
81
88template<std::size_t N> class SAL_WARN_UNUSED OStringLiteral {
89 static_assert(N != 0);
90 static_assert(N - 1 <= std::numeric_limits<sal_Int32>::max(), "literal too long");
91 friend class OString;
92 friend class OStringConstExpr;
93
94public:
95#if HAVE_CPP_CONSTEVAL
96 consteval
97#else
98 constexpr
99#endif
100 OStringLiteral(char const (&literal)[N]) {
101 assertLayout();
102 assert(literal[N - 1] == '\0');
103 //TODO: Use C++20 constexpr std::copy_n (P0202R3):
104 for (std::size_t i = 0; i != N; ++i) {
105 more.buffer[i] = literal[i];
106 }
107 }
108
109#if defined __cpp_char8_t
110#if HAVE_CPP_CONSTEVAL
111 consteval
112#else
113 constexpr
114#endif
115 explicit OStringLiteral(char8_t const (&literal)[N]) {
116 assertLayout();
117 assert(literal[N - 1] == '\0');
118 //TODO: Use C++20 constexpr std::copy_n (P0202R3):
119 for (std::size_t i = 0; i != N; ++i) {
120 more.buffer[i] = literal[i];
121 }
122 }
123#endif
124
125 constexpr sal_Int32 getLength() const { return more.length; }
126
127 constexpr char const * getStr() const SAL_RETURNS_NONNULL { return more.buffer; }
128
129 constexpr operator std::string_view() const { return {more.buffer, sal_uInt32(more.length)}; }
130
131private:
132 static constexpr void assertLayout() {
133 // These static_asserts verifying the layout compatibility with rtl_String cannot be class
134 // member declarations, as offsetof requires a complete type, so defer them to here:
135 static_assert(std::is_standard_layout_v<OStringLiteral>);
136 static_assert(offsetof(OStringLiteral, str.refCount) == offsetof(OStringLiteral, more.refCount));
137 static_assert(offsetof(OStringLiteral, str.length) == offsetof(OStringLiteral, more.length));
138 static_assert(offsetof(OStringLiteral, str.buffer) == offsetof(OStringLiteral, more.buffer));
139 }
140
141 struct Data {
142 Data() = default;
143
144 oslInterlockedCount refCount = 0x40000000; // SAL_STRING_STATIC_FLAG (sal/rtl/strimp.hxx)
145 sal_Int32 length = N - 1;
146 char buffer[N] = {}; //TODO: drop initialization for C++20 (P1331R2)
147 };
148
149 union {
150 rtl_String str;
151 Data more = {};
152 };
153};
154
163class OString;
164class OStringConstExpr
165{
166public:
167 template<std::size_t N> constexpr OStringConstExpr(OStringLiteral<N> const & literal):
168 pData(const_cast<rtl_String *>(&literal.str)) {}
169
170 // prevent mis-use
171 template<std::size_t N> constexpr OStringConstExpr(OStringLiteral<N> && literal)
172 = delete;
173
174 // no destructor necessary because we know we are pointing at a compile-time
175 // constant OStringLiteral, which bypasses ref-counting.
176
180 constexpr std::string_view asView() const { return std::string_view(pData->buffer, pData->length); }
181
182 inline operator const OString&() const;
183
184private:
185 rtl_String* pData;
186};
187
188#endif
189
190/* ======================================================================= */
191
217{
218public:
220 rtl_String * pData;
222
227 {
228 pData = NULL;
229 rtl_string_new( &pData );
230 }
231
237 OString( const OString & str )
238 {
239 pData = str.pData;
240 rtl_string_acquire( pData );
241 }
242
243#if defined LIBO_INTERNAL_ONLY
250 OString( OString && str ) noexcept
251 {
252 pData = str.pData;
253 str.pData = nullptr;
254 rtl_string_new( &str.pData );
255 }
256#endif
257
264 {
265 pData = str;
266 rtl_string_acquire( pData );
267 }
268
277 {
278 pData = str;
279 }
280
286 explicit OString( char value )
287 : pData (NULL)
288 {
289 rtl_string_newFromStr_WithLength( &pData, &value, 1 );
290 }
291
292#if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST_CONCAT
293 // Catch inadvertent conversions to the above ctor (e.g., from sal_[u]Int8, aka [un]signed
294 // char):
295 OString(int) = delete;
296#endif
297
306 template< typename T >
312
313 template< typename T >
319
320#if __cplusplus > 202002L // C++23 P2266R3 "Simpler implicit move"
321 template< typename T >
323 {
324 pData = NULL;
325 rtl_string_newFromStr( &pData, value );
326 }
327#endif
328
339 template< typename T >
358
367 OString( const char * value, sal_Int32 length )
368 {
369 pData = NULL;
370 rtl_string_newFromStr_WithLength( &pData, value, length );
371 }
372
373#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
375
380 template<std::size_t N> constexpr OString(OStringLiteral<N> const & literal):
381 pData(const_cast<rtl_String *>(&literal.str)) {}
382 template<std::size_t N> OString(OStringLiteral<N> &&) = delete;
384#endif
385
386#if defined LIBO_INTERNAL_ONLY
387 explicit OString(std::string_view sv) {
388 if (sv.size() > sal_uInt32(std::numeric_limits<sal_Int32>::max())) {
389 throw std::bad_alloc();
390 }
391 pData = nullptr;
392 rtl_string_newFromStr_WithLength(&pData, sv.data(), sv.size());
393 }
394#endif
395
410 OString( const sal_Unicode * value, sal_Int32 length,
413 {
414 pData = NULL;
415 rtl_uString2String( &pData, value, length, encoding, convertFlags );
416 if (pData == NULL) {
417 throw std::bad_alloc();
418 }
419 }
420
421#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
426 template< typename T1, typename T2 >
428 {
429 const sal_Int32 l = c.length();
430 pData = rtl_string_alloc( l );
431 if (l != 0)
432 {
433 char* end = c.addData( pData->buffer );
434 pData->length = l;
435 *end = '\0';
436 }
437 }
438
443 template< std::size_t N >
444 OString( OStringNumber< N >&& n )
445 : OString( n.buf, n.length )
446 {}
447#endif
448
449#ifdef LIBO_INTERNAL_ONLY
450 OString(std::nullptr_t) = delete;
451#endif
452
456#if defined LIBO_INTERNAL_ONLY && __cplusplus >= 202002L
457 constexpr
458#endif
460 {
461#if defined LIBO_INTERNAL_ONLY && __cplusplus >= 202002L
462 if (std::is_constant_evaluated()) {
463 //TODO: We would want to
464 //
465 // assert(SAL_STRING_IS_STATIC(pData));
466 //
467 // here, but that wouldn't work because read of member `str` of OUStringLiteral's
468 // anonymous union with active member `more` is not allowed in a constant expression.
469 } else
470#endif
471 rtl_string_release( pData );
472 }
473
474#if defined LIBO_INTERNAL_ONLY
486 static OString const & unacquired( rtl_String * const * ppHandle )
487 { return * reinterpret_cast< OString const * >( ppHandle ); }
488#endif
489
496 {
497 rtl_string_assign( &pData, str.pData );
498 return *this;
499 }
500
501#if defined LIBO_INTERNAL_ONLY
508 OString & operator=( OString && str ) noexcept
509 {
510 rtl_string_release( pData );
511 pData = str.pData;
512 str.pData = nullptr;
513 rtl_string_new( &str.pData );
514 return *this;
515 }
516#endif
517
523 template< typename T >
540
547#if defined LIBO_INTERNAL_ONLY
548 &
549#endif
550 {
551 rtl_string_newConcat( &pData, pData, str.pData );
552 return *this;
553 }
554#if defined LIBO_INTERNAL_ONLY
555 void operator+=(OString const &) && = delete;
556#endif
557
558#if defined LIBO_INTERNAL_ONLY
560 operator +=(T const & value) & { return operator +=(std::string_view(value)); }
561 template<typename T> typename libreoffice_internal::CharPtrDetector<T, OString &>::Type
562 operator +=(T const &) && = delete;
563
564 template<typename T>
565 typename libreoffice_internal::NonConstCharArrayDetector<T, OString &>::Type
566 operator +=(T & value) & { return operator +=(std::string_view(value)); }
567 template<typename T>
568 typename libreoffice_internal::NonConstCharArrayDetector<T, OString &>::Type operator +=(T &) &&
569 = delete;
570
571 template<typename T> typename libreoffice_internal::ConstCharArrayDetector<T, OString &>::Type
572 operator +=(T & literal) & {
573 assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
574 return operator +=(
575 std::string_view(
576 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
577 libreoffice_internal::ConstCharArrayDetector<T>::length));
578 }
579 template<typename T> typename libreoffice_internal::ConstCharArrayDetector<T, OString &>::Type
580 operator +=(T &) && = delete;
581
582 template<std::size_t N> OString & operator +=(OStringLiteral<N> const & literal) &
583 { return operator +=(std::string_view(literal.getStr(), literal.getLength())); }
584 template<std::size_t N> void operator +=(OStringLiteral<N> const &) && = delete;
585
586 OString & operator +=(std::string_view sv) & {
587 if (sv.empty()) {
588 return *this;
589 }
590 if (sv.size() > sal_uInt32(std::numeric_limits<sal_Int32>::max() - pData->length)) {
591 throw std::bad_alloc();
592 }
593 auto const l = pData->length + sv.size();
594 rtl_string_ensureCapacity(&pData, l);
595 *addDataHelper(pData->buffer + pData->length, sv.data(), sv.size()) = '\0';
596 pData->length = l;
597 return *this;
598 }
599 void operator +=(std::string_view) && = delete;
600#endif
601
602#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
607 template< typename T1, typename T2 >
608 OString& operator+=( OStringConcat< T1, T2 >&& c ) & {
609 sal_Int32 l = c.length();
610 if( l == 0 )
611 return *this;
612 l += pData->length;
613 rtl_string_ensureCapacity( &pData, l );
614 char* end = c.addData( pData->buffer + pData->length );
615 *end = '\0';
616 pData->length = l;
617 return *this;
618 }
619 template<typename T1, typename T2> void operator +=(
620 OStringConcat<T1, T2> &&) && = delete;
621
626 template< std::size_t N >
627 OString& operator+=( OStringNumber< N >&& n ) & {
628 return operator +=(std::string_view(n.buf, n.length));
629 }
630 template<std::size_t N> void operator +=(
631 OStringNumber<N> &&) && = delete;
632#endif
633
638 void clear()
639 {
640 rtl_string_new( &pData );
641 }
642
651 sal_Int32 getLength() const { return pData->length; }
652
661 bool isEmpty() const
662 {
663 return pData->length == 0;
664 }
665
677 const char * getStr() const SAL_RETURNS_NONNULL { return pData->buffer; }
678
688 char operator [](sal_Int32 index) const {
689 // silence spurious -Werror=strict-overflow warnings from GCC 4.8.2
690 assert(index >= 0 && static_cast<sal_uInt32>(index) < static_cast<sal_uInt32>(getLength()));
691 return getStr()[index];
692 }
693
707 {
708 return rtl_str_compare_WithLength( pData->buffer, pData->length,
709 str.pData->buffer, str.pData->length );
710 }
711
726 {
727 return rtl_str_shortenedCompare_WithLength( pData->buffer, pData->length,
728 rObj.pData->buffer, rObj.pData->length, maxLength );
729 }
730
744 {
745 return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
746 str.pData->buffer, str.pData->length );
747 }
748
760 bool equals( const OString & str ) const
761 {
762 if ( pData->length != str.pData->length )
763 return false;
764 if ( pData == str.pData )
765 return true;
766 return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
767 str.pData->buffer, str.pData->length ) == 0;
768 }
769
784 bool equalsL( const char* value, sal_Int32 length ) const
785 {
786 if ( pData->length != length )
787 return false;
788
789 return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
790 value, length ) == 0;
791 }
792
807#if defined LIBO_INTERNAL_ONLY
808 bool equalsIgnoreAsciiCase( std::string_view str ) const
809 {
810 if ( sal_uInt32(pData->length) != str.size() )
811 return false;
812 if ( pData->buffer == str.data() )
813 return true;
814 return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
815 str.data(), str.size() ) == 0;
816 }
817#else
818 bool equalsIgnoreAsciiCase( const OString & str ) const
819 {
820 if ( pData->length != str.pData->length )
821 return false;
822 if ( pData == str.pData )
823 return true;
824 return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
825 str.pData->buffer, str.pData->length ) == 0;
826 }
827#endif
828
850 template< typename T >
855
856 template< typename T >
861
867 template< typename T >
883
904 {
905 if ( pData->length != asciiStrLength )
906 return false;
907
908 return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
909 asciiStr, asciiStrLength ) == 0;
910 }
911
927#if defined LIBO_INTERNAL_ONLY
928 bool match( std::string_view str, sal_Int32 fromIndex = 0 ) const
929 {
930 return rtl_str_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
931 str.data(), str.size(), str.size() ) == 0;
932 }
933#else
934 bool match( const OString & str, sal_Int32 fromIndex = 0 ) const
935 {
936 return rtl_str_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
937 str.pData->buffer, str.pData->length, str.pData->length ) == 0;
938 }
939#endif
940
946 template< typename T >
961
978 bool matchL(
979 char const * str, sal_Int32 strLength, sal_Int32 fromIndex = 0)
980 const
981 {
983 pData->buffer + fromIndex, pData->length - fromIndex,
984 str, strLength, strLength) == 0;
985 }
986
987 // This overload is left undefined, to detect calls of matchL that
988 // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
989 // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
990 // platforms):
991#if SAL_TYPES_SIZEOFLONG == 8
992 void matchL(char const *, sal_Int32, rtl_TextEncoding) const;
993#endif
994
1013#if defined LIBO_INTERNAL_ONLY
1014 bool matchIgnoreAsciiCase( std::string_view str, sal_Int32 fromIndex = 0 ) const
1015 {
1016 return rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1017 str.data(), str.size(),
1018 str.size() ) == 0;
1019 }
1020#else
1022 {
1023 return rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1024 str.pData->buffer, str.pData->length,
1025 str.pData->length ) == 0;
1026 }
1027#endif
1033 template< typename T >
1048
1063#if defined LIBO_INTERNAL_ONLY
1064 bool startsWith(std::string_view str, OString * rest = NULL) const {
1065 bool b = match(str);
1066 if (b && rest != NULL) {
1067 *rest = copy(str.size());
1068 }
1069 return b;
1070 }
1071#else
1072 bool startsWith(OString const & str, OString * rest = NULL) const {
1073 bool b = match(str);
1074 if (b && rest != NULL) {
1075 *rest = copy(str.getLength());
1076 }
1077 return b;
1078 }
1079#endif
1080
1086 template< typename T >
1088 T & literal, OString * rest = NULL) const
1089 {
1091 bool b = match(literal, 0);
1092 if (b && rest != NULL) {
1093 *rest = copy(
1095 }
1096 return b;
1097 }
1098
1118#if defined LIBO_INTERNAL_ONLY
1119 bool startsWithIgnoreAsciiCase(std::string_view str, OString * rest = NULL)
1120 const
1121 {
1122 bool b = matchIgnoreAsciiCase(str);
1123 if (b && rest != NULL) {
1124 *rest = copy(str.size());
1125 }
1126 return b;
1127 }
1128#else
1130 const
1131 {
1132 bool b = matchIgnoreAsciiCase(str);
1133 if (b && rest != NULL) {
1134 *rest = copy(str.getLength());
1135 }
1136 return b;
1137 }
1138#endif
1139
1145 template< typename T >
1148 {
1150 assert(
1152 bool b = matchIgnoreAsciiCase(literal);
1153 if (b && rest != NULL) {
1154 *rest = copy(
1156 }
1157 return b;
1158 }
1159
1174#if defined LIBO_INTERNAL_ONLY
1175 bool endsWith(std::string_view str, OString * rest = NULL) const {
1176 bool b = str.size() <= sal_uInt32(getLength())
1177 && match(str, getLength() - str.size());
1178 if (b && rest != NULL) {
1179 *rest = copy(0, getLength() - str.size());
1180 }
1181 return b;
1182 }
1183#else
1184 bool endsWith(OString const & str, OString * rest = NULL) const {
1185 bool b = str.getLength() <= getLength()
1186 && match(str, getLength() - str.getLength());
1187 if (b && rest != NULL) {
1188 *rest = copy(0, getLength() - str.getLength());
1189 }
1190 return b;
1191 }
1192#endif
1193
1199 template< typename T >
1222
1236 bool endsWithL(char const * str, sal_Int32 strLength) const {
1237 return strLength <= getLength()
1238 && matchL(str, strLength, getLength() - strLength);
1239 }
1240
1241 friend bool operator == ( const OString& rStr1, const OString& rStr2 )
1242 { return rStr1.equals(rStr2); }
1243 friend bool operator != ( const OString& rStr1, const OString& rStr2 )
1244 { return !(operator == ( rStr1, rStr2 )); }
1245 friend bool operator < ( const OString& rStr1, const OString& rStr2 )
1246 { return rStr1.compareTo( rStr2 ) < 0; }
1247 friend bool operator > ( const OString& rStr1, const OString& rStr2 )
1248 { return rStr1.compareTo( rStr2 ) > 0; }
1249 friend bool operator <= ( const OString& rStr1, const OString& rStr2 )
1250 { return rStr1.compareTo( rStr2 ) <= 0; }
1251 friend bool operator >= ( const OString& rStr1, const OString& rStr2 )
1252 { return rStr1.compareTo( rStr2 ) >= 0; }
1253
1254 template< typename T >
1256 {
1257 return
1259 rStr1.getStr(), rStr1.getLength(), value, rtl_str_getLength(value))
1260 == 0;
1261 }
1262
1263 template< typename T >
1265 {
1266 return
1268 rStr1.getStr(), rStr1.getLength(), value, rtl_str_getLength(value))
1269 == 0;
1270 }
1271
1272 template< typename T >
1274 {
1275 return
1277 value, rtl_str_getLength(value), rStr2.getStr(), rStr2.getLength())
1278 == 0;
1279 }
1280
1281 template< typename T >
1283 {
1284 return
1286 value, rtl_str_getLength(value), rStr2.getStr(), rStr2.getLength())
1287 == 0;
1288 }
1289
1295 template< typename T >
1311
1317 template< typename T >
1333
1334 template< typename T >
1336 {
1337 return !(operator == ( rStr1, value ));
1338 }
1339
1340 template< typename T >
1342 {
1343 return !(operator == ( rStr1, value ));
1344 }
1345
1346 template< typename T >
1348 {
1349 return !(operator == ( value, rStr2 ));
1350 }
1351
1352 template< typename T >
1354 {
1355 return !(operator == ( value, rStr2 ));
1356 }
1357
1363 template< typename T >
1365 {
1366 return !( rStr == literal );
1367 }
1368
1374 template< typename T >
1376 {
1377 return !( literal == rStr );
1378 }
1379
1388 {
1389 return rtl_str_hashCode_WithLength( pData->buffer, pData->length );
1390 }
1391
1406 {
1407 sal_Int32 ret = rtl_str_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
1408 return (ret < 0 ? ret : ret+fromIndex);
1409 }
1410
1421 {
1422 return rtl_str_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
1423 }
1424
1438 {
1439 return rtl_str_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
1440 }
1441
1457#if defined LIBO_INTERNAL_ONLY
1458 sal_Int32 indexOf( std::string_view str, sal_Int32 fromIndex = 0 ) const
1459 {
1460 sal_Int32 ret = rtl_str_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1461 str.data(), str.size() );
1462 return (ret < 0 ? ret : ret+fromIndex);
1463 }
1464#else
1466 {
1467 sal_Int32 ret = rtl_str_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1468 str.pData->buffer, str.pData->length );
1469 return (ret < 0 ? ret : ret+fromIndex);
1470 }
1471#endif
1477 template< typename T >
1489
1509 const
1510 {
1512 pData->buffer + fromIndex, pData->length - fromIndex, str, len);
1513 return n < 0 ? n : n + fromIndex;
1514 }
1515
1516 // This overload is left undefined, to detect calls of indexOfL that
1517 // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
1518 // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
1519 // platforms):
1520#if SAL_TYPES_SIZEOFLONG == 8
1521 void indexOfL(char const *, sal_Int32, rtl_TextEncoding) const;
1522#endif
1523
1539#if defined LIBO_INTERNAL_ONLY
1540 sal_Int32 lastIndexOf( std::string_view str ) const
1541 {
1542 return rtl_str_lastIndexOfStr_WithLength( pData->buffer, pData->length,
1543 str.data(), str.size() );
1544 }
1545#else
1547 {
1548 return rtl_str_lastIndexOfStr_WithLength( pData->buffer, pData->length,
1549 str.pData->buffer, str.pData->length );
1550 }
1551#endif
1552
1570#if defined LIBO_INTERNAL_ONLY
1571 sal_Int32 lastIndexOf( std::string_view str, sal_Int32 fromIndex ) const
1572 {
1573 return rtl_str_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
1574 str.data(), str.size() );
1575 }
1576#else
1578 {
1579 return rtl_str_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
1580 str.pData->buffer, str.pData->length );
1581 }
1582#endif
1583
1595 {
1596 return copy(beginIndex, getLength() - beginIndex);
1597 }
1598
1617
1618#if defined LIBO_INTERNAL_ONLY
1629 SAL_WARN_UNUSED_RESULT std::string_view subView( sal_Int32 beginIndex ) const
1630 {
1631 assert(beginIndex >= 0);
1632 assert(beginIndex <= getLength());
1633 return subView(beginIndex, getLength() - beginIndex);
1634 }
1635
1648 SAL_WARN_UNUSED_RESULT std::string_view subView( sal_Int32 beginIndex, sal_Int32 count ) const
1649 {
1650 assert(beginIndex >= 0);
1651 assert(count >= 0);
1652 assert(beginIndex <= getLength());
1653 assert(count <= getLength() - beginIndex);
1654 return std::string_view(*this).substr(beginIndex, count);
1655 }
1656#endif
1657
1658#ifndef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
1667 SAL_WARN_UNUSED_RESULT OString concat( const OString & str ) const
1668 {
1669 rtl_String* pNew = NULL;
1670 rtl_string_newConcat( &pNew, pData, str.pData );
1671 return OString( pNew, SAL_NO_ACQUIRE );
1672 }
1673#endif
1674
1675#ifndef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
1676 friend OString operator+( const OString & str1, const OString & str2 )
1677 {
1678 return str1.concat( str2 );
1679 }
1680#endif
1681
1682// hide this from internal code to avoid ambiguous lookup error
1683#ifndef LIBO_INTERNAL_ONLY
1698 {
1699 rtl_String* pNew = NULL;
1700 rtl_string_newReplaceStrAt( &pNew, pData, index, count, newStr.pData );
1701 return OString( pNew, SAL_NO_ACQUIRE );
1702 }
1703#endif
1704
1705#ifdef LIBO_INTERNAL_ONLY
1706 SAL_WARN_UNUSED_RESULT OString replaceAt( sal_Int32 index, sal_Int32 count, std::string_view newStr ) const
1707 {
1708 rtl_String* pNew = NULL;
1709 rtl_string_newReplaceStrAt_WithLength ( &pNew, pData, index, count, newStr.data(), newStr.size() );
1710 return OString( pNew, SAL_NO_ACQUIRE );
1711 }
1712#endif
1713
1728 {
1729 rtl_String* pNew = NULL;
1731 return OString( pNew, SAL_NO_ACQUIRE );
1732 }
1733
1753 OString const & from, OString const & to, sal_Int32 * index = NULL) const
1754 {
1755 rtl_String * s = NULL;
1756 sal_Int32 i = 0;
1758 &s, pData, from.pData->buffer, from.pData->length,
1759 to.pData->buffer, to.pData->length, index == NULL ? &i : index);
1760 return OString(s, SAL_NO_ACQUIRE);
1761 }
1762
1777 rtl_String * s = NULL;
1779 &s, pData, from.pData->buffer, from.pData->length,
1780 to.pData->buffer, to.pData->length);
1781 return OString(s, SAL_NO_ACQUIRE);
1782 }
1783
1800
1817
1830 {
1831 rtl_String* pNew = NULL;
1832 rtl_string_newTrim( &pNew, pData );
1833 return OString( pNew, SAL_NO_ACQUIRE );
1834 }
1835
1861 {
1862 rtl_String * pNew = NULL;
1863 index = rtl_string_getToken( &pNew, pData, token, cTok, index );
1864 return OString( pNew, SAL_NO_ACQUIRE );
1865 }
1866
1881 sal_Int32 n = 0;
1882 return getToken(count, separator, n);
1883 }
1884
1893 bool toBoolean() const
1894 {
1895 return rtl_str_toBoolean( pData->buffer );
1896 }
1897
1904 char toChar() const
1905 {
1906 return pData->buffer[0];
1907 }
1908
1920 {
1921 return rtl_str_toInt32( pData->buffer, radix );
1922 }
1923
1937 {
1938 return rtl_str_toUInt32( pData->buffer, radix );
1939 }
1940
1952 {
1953 return rtl_str_toInt64( pData->buffer, radix );
1954 }
1955
1969 {
1970 return rtl_str_toUInt64( pData->buffer, radix );
1971 }
1972
1981 float toFloat() const
1982 {
1983 return rtl_str_toFloat( pData->buffer );
1984 }
1985
1994 double toDouble() const
1995 {
1996 return rtl_str_toDouble( pData->buffer );
1997 }
1998
1999#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2000
2001 static auto number( int i, sal_Int16 radix = 10 )
2002 {
2004 }
2005 static auto number( long long ll, sal_Int16 radix = 10 )
2006 {
2007 return OStringNumber<RTL_STR_MAX_VALUEOFINT64>(rtl_str_valueOfInt64, ll, radix);
2008 }
2009 static auto number( unsigned long long ll, sal_Int16 radix = 10 )
2010 {
2011 return OStringNumber<RTL_STR_MAX_VALUEOFUINT64>(rtl_str_valueOfUInt64, ll, radix);
2012 }
2013 static auto number( unsigned int i, sal_Int16 radix = 10 )
2014 {
2015 return number( static_cast< unsigned long long >( i ), radix );
2016 }
2017 static auto number( long i, sal_Int16 radix = 10)
2018 {
2019 return number( static_cast< long long >( i ), radix );
2020 }
2021 static auto number( unsigned long i, sal_Int16 radix = 10 )
2022 {
2023 return number( static_cast< unsigned long long >( i ), radix );
2024 }
2025#else
2036 static OString number( int i, sal_Int16 radix = 10 )
2037 {
2040 }
2043 static OString number( unsigned int i, sal_Int16 radix = 10 )
2044 {
2045 return number( static_cast< unsigned long long >( i ), radix );
2046 }
2049 static OString number( long i, sal_Int16 radix = 10 )
2050 {
2051 return number( static_cast< long long >( i ), radix );
2052 }
2055 static OString number( unsigned long i, sal_Int16 radix = 10 )
2056 {
2057 return number( static_cast< unsigned long long >( i ), radix );
2058 }
2061 static OString number( long long ll, sal_Int16 radix = 10 )
2062 {
2065 }
2068 static OString number( unsigned long long ll, sal_Int16 radix = 10 )
2069 {
2072 }
2073#endif
2074
2084 static OString number( float f )
2085 {
2086 rtl_String* pNew = NULL;
2087 // Same as rtl::str::valueOfFP, used for rtl_str_valueOfFloat
2089 RTL_STR_MAX_VALUEOFFLOAT - SAL_N_ELEMENTS("-x.E-xxx") + 1, '.',
2090 NULL, 0, true);
2091 if (pNew == NULL)
2092 throw std::bad_alloc();
2093
2094 return OString(pNew, SAL_NO_ACQUIRE);
2095 }
2096
2106 static OString number( double d )
2107 {
2108 rtl_String* pNew = NULL;
2109 // Same as rtl::str::valueOfFP, used for rtl_str_valueOfDouble
2111 RTL_STR_MAX_VALUEOFDOUBLE - SAL_N_ELEMENTS("-x.E-xxx") + 1, '.',
2112 NULL, 0, true);
2113 if (pNew == NULL)
2114 throw std::bad_alloc();
2115
2116 return OString(pNew, SAL_NO_ACQUIRE);
2117 }
2118
2119#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2120 static auto boolean(bool b)
2121 {
2123 }
2124#else
2136 SAL_DEPRECATED("use boolean()") static OString valueOf( sal_Bool b )
2137 {
2138 return boolean(b);
2139 }
2140
2152 static OString boolean( bool b )
2153 {
2156 }
2157#endif
2158
2166 SAL_DEPRECATED("convert to OString or use directly") static OString valueOf( char c )
2167 {
2168 return OString( &c, 1 );
2169 }
2170
2181 SAL_DEPRECATED("use number()") static OString valueOf( sal_Int32 i, sal_Int16 radix = 10 )
2182 {
2183 return number( i, radix );
2184 }
2185
2196 SAL_DEPRECATED("use number()") static OString valueOf( sal_Int64 ll, sal_Int16 radix = 10 )
2197 {
2198 return number( ll, radix );
2199 }
2200
2210 SAL_DEPRECATED("use number()") static OString valueOf( float f )
2211 {
2212 return number(f);
2213 }
2214
2224 SAL_DEPRECATED("use number()") static OString valueOf( double d )
2225 {
2226 return number(d);
2227 }
2228
2229#if defined LIBO_INTERNAL_ONLY
2230 operator std::string_view() const { return {getStr(), sal_uInt32(getLength())}; }
2231#endif
2232
2233#if defined LIBO_INTERNAL_ONLY
2234 // A wrapper for the first expression in an
2235 //
2236 // OString::Concat(e1) + e2 + ...
2237 //
2238 // concatenation chain, when neither of the first two e1, e2 is one of our rtl string-related
2239 // classes (so something like
2240 //
2241 // OString s = "a" + (b ? std::string_view("c") : std::string_view("dd"));
2242 //
2243 // would not compile):
2244 template<typename T> [[nodiscard]] static
2245 OStringConcat<OStringConcatMarker, T>
2246 Concat(T const & value) { return OStringConcat<OStringConcatMarker, T>(value); }
2247
2248 // This overload is needed so that an argument of type 'char const[N]' ends up as
2249 // 'OStringConcat<rtl::OStringConcatMarker, char const[N]>' rather than as
2250 // 'OStringConcat<rtl::OStringConcatMarker, char[N]>':
2251 template<typename T, std::size_t N> [[nodiscard]] static
2252 OStringConcat<OStringConcatMarker, T[N]>
2253 Concat(T (& value)[N]) { return OStringConcat<OStringConcatMarker, T[N]>(value); }
2254#endif
2255};
2256
2257#if defined LIBO_INTERNAL_ONLY
2258// Can only define this after we define OString
2259inline OStringConstExpr::operator const OString &() const { return OString::unacquired(&pData); }
2260#endif
2261
2262#if defined LIBO_INTERNAL_ONLY
2263inline bool operator ==(OString const & lhs, StringConcatenation<char> const & rhs)
2264{ return lhs == std::string_view(rhs); }
2265inline bool operator !=(OString const & lhs, StringConcatenation<char> const & rhs)
2266{ return lhs != std::string_view(rhs); }
2267inline bool operator ==(StringConcatenation<char> const & lhs, OString const & rhs)
2268{ return std::string_view(lhs) == rhs; }
2269inline bool operator !=(StringConcatenation<char> const & lhs, OString const & rhs)
2270{ return std::string_view(lhs) != rhs; }
2271#endif
2272
2273/* ======================================================================= */
2274
2275#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2276
2280template<>
2281struct ToStringHelper< OString >
2282{
2283 static std::size_t length( const OString& s ) { return s.getLength(); }
2284 char* operator()( char* buffer, const OString& s ) const { return addDataHelper( buffer, s.getStr(), s.getLength()); }
2285};
2286
2290template<std::size_t N>
2291struct ToStringHelper< OStringLiteral<N> >
2292{
2293 static constexpr std::size_t length( const OStringLiteral<N>& str ) { return str.getLength(); }
2294 char* operator()( char* buffer, const OStringLiteral<N>& str ) const { return addDataHelper( buffer, str.getStr(), str.getLength() ); }
2295};
2296
2300template< typename charT, typename traits, typename T1, typename T2 >
2301inline std::basic_ostream<charT, traits> & operator <<(
2302 std::basic_ostream<charT, traits> & stream, OStringConcat< T1, T2 >&& concat)
2303{
2304 return stream << OString( std::move(concat) );
2305}
2306#endif
2307
2308
2315{
2325 size_t operator()( const OString& rString ) const
2326 { return static_cast<size_t>(rString.hashCode()); }
2327};
2328
2331{
2332 bool operator()( const char* p1, const char* p2) const
2333 { return rtl_str_compare(p1, p2) == 0; }
2334};
2335
2338{
2339 size_t operator()(const char* p) const
2340 { return rtl_str_hashCode(p); }
2341};
2342
2343/* ======================================================================= */
2344
2351template< typename charT, typename traits > std::basic_ostream<charT, traits> &
2353 std::basic_ostream<charT, traits> & stream, OString const & rString)
2354{
2355 return stream << rString.getStr();
2356 // best effort; potentially loses data due to embedded null characters
2357}
2358
2359} /* Namespace */
2360
2361#ifdef RTL_STRING_UNITTEST
2362namespace rtl
2363{
2364typedef rtlunittest::OString OString;
2365}
2366#undef RTL_STRING_CONST_FUNCTION
2367#endif
2368
2369#if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
2370using ::rtl::OString;
2371using ::rtl::OStringChar;
2372using ::rtl::Concat2View;
2373using ::rtl::OStringHash;
2374using ::rtl::OStringLiteral;
2375#endif
2376
2378
2383#if defined LIBO_INTERNAL_ONLY
2384namespace std {
2385
2386template<>
2387struct hash<::rtl::OString>
2388{
2389 std::size_t operator()(::rtl::OString const & s) const
2390 {
2391 if constexpr (sizeof(std::size_t) == 8)
2392 {
2393 // return a hash that uses the full 64-bit range instead of a 32-bit value
2394 size_t n = s.getLength();
2395 for (sal_Int32 i = 0, len = s.getLength(); i < len; ++i)
2396 n = 37 * n + s[i];
2397 return n;
2398 }
2399 else
2400 return std::size_t(s.hashCode());
2401 }
2402};
2403
2404}
2405
2406#endif
2408
2409#endif // INCLUDED_RTL_STRING_HXX
2410
2411/* 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
@ 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 void rtl_math_doubleToString(rtl_String **pResult, sal_Int32 *pResultCapacity, sal_Int32 nResultOffset, double fValue, enum rtl_math_StringFormat eFormat, sal_Int32 nDecPlaces, char cDecSeparator, sal_Int32 const *pGroups, char cGroupSeparator, sal_Bool bEraseTrailingDecZeros) SAL_THROW_EXTERN_C()
Conversions analogous to sprintf() using internal rounding.
SAL_DLLPUBLIC double rtl_str_toDouble(const char *str) SAL_THROW_EXTERN_C()
Interpret a string as a double.
SAL_DLLPUBLIC sal_Int32 rtl_str_compare(const char *first, const char *second) SAL_THROW_EXTERN_C()
Compare two strings.
SAL_DLLPUBLIC sal_Int32 rtl_str_hashCode_WithLength(const char *str, sal_Int32 len) SAL_THROW_EXTERN_C()
Return a hash code for a string.
SAL_DLLPUBLIC void rtl_string_newReplaceStrAt(rtl_String **newStr, rtl_String *str, sal_Int32 idx, sal_Int32 count, rtl_String *subStr) SAL_THROW_EXTERN_C()
Create a new string by replacing a substring of another string.
SAL_DLLPUBLIC sal_Bool rtl_str_toBoolean(const char *str) SAL_THROW_EXTERN_C()
Interpret a string as a boolean.
#define RTL_STR_MAX_VALUEOFDOUBLE
Definition string.h:715
#define RTL_STR_MAX_VALUEOFINT32
Definition string.h:631
SAL_DLLPUBLIC void rtl_string_acquire(rtl_String *str) SAL_THROW_EXTERN_C()
Increment the reference count of a string.
SAL_DLLPUBLIC rtl_String * rtl_string_alloc(sal_Int32 nLen) SAL_THROW_EXTERN_C()
Allocate a new string containing space for a given number of characters.
SAL_DLLPUBLIC void rtl_string_newConcat(rtl_String **newStr, rtl_String *left, rtl_String *right) SAL_THROW_EXTERN_C()
Create a new string that is the concatenation of two other strings.
SAL_DLLPUBLIC sal_uInt32 rtl_str_toUInt32(const char *str, sal_Int16 radix) SAL_THROW_EXTERN_C()
Interpret a string as an unsigned integer.
SAL_DLLPUBLIC sal_Int32 rtl_str_compareIgnoreAsciiCase(const char *first, const char *second) SAL_THROW_EXTERN_C()
Compare two strings, ignoring the case of ASCII characters.
SAL_DLLPUBLIC void rtl_string_assign(rtl_String **str, rtl_String *rightValue) SAL_THROW_EXTERN_C()
Assign a new value to a string.
SAL_DLLPUBLIC sal_Int32 rtl_str_lastIndexOfStr_WithLength(const char *str, sal_Int32 len, const char *subStr, sal_Int32 subLen) SAL_THROW_EXTERN_C()
Search for the last occurrence of a substring within a string.
SAL_DLLPUBLIC void rtl_string_newReplaceAll(rtl_String **newStr, rtl_String *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_str_reverseCompare_WithLength(const char *first, sal_Int32 firstLen, const char *second, sal_Int32 secondLen) SAL_THROW_EXTERN_C()
Compare two strings from back to front.
SAL_DLLPUBLIC sal_uInt64 rtl_str_toUInt64(const char *str, sal_Int16 radix) SAL_THROW_EXTERN_C()
Interpret a string as an unsigned long integer.
SAL_DLLPUBLIC sal_Int32 rtl_string_getToken(rtl_String **newStr, rtl_String *str, sal_Int32 token, char cTok, sal_Int32 idx) SAL_THROW_EXTERN_C()
Create a new string by extracting a single token from another string.
SAL_DLLPUBLIC sal_Int32 rtl_str_valueOfInt64(char *str, sal_Int64 l, sal_Int16 radix) SAL_THROW_EXTERN_C()
Create the string representation of a long integer.
SAL_DLLPUBLIC void rtl_string_newReplaceFirst(rtl_String **newStr, rtl_String *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 void rtl_string_newFromStr(rtl_String **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_str_shortenedCompare_WithLength(const char *first, sal_Int32 firstLen, const char *second, sal_Int32 secondLen, sal_Int32 shortenedLen) SAL_THROW_EXTERN_C()
Compare two strings with a maximum count of characters.
SAL_DLLPUBLIC void rtl_string_new(rtl_String **newStr) SAL_THROW_EXTERN_C()
Allocate a new string containing no characters.
SAL_DLLPUBLIC sal_Int32 rtl_str_shortenedCompareIgnoreAsciiCase_WithLength(const char *first, sal_Int32 firstLen, const char *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 sal_Int32 rtl_str_indexOfChar_WithLength(const char *str, sal_Int32 len, char ch) SAL_THROW_EXTERN_C()
Search for the first occurrence of a character within a string.
SAL_DLLPUBLIC void rtl_uString2String(rtl_String **newStr, const sal_Unicode *str, sal_Int32 len, rtl_TextEncoding encoding, sal_uInt32 convertFlags) SAL_THROW_EXTERN_C()
Create a new byte string by converting a Unicode string, using a specific text encoding.
SAL_DLLPUBLIC sal_Int32 rtl_str_valueOfBoolean(char *str, sal_Bool b) SAL_THROW_EXTERN_C()
Create the string representation of a boolean.
#define OUSTRING_TO_OSTRING_CVTFLAGS
Definition string.h:1358
SAL_DLLPUBLIC void rtl_string_newFromLiteral(rtl_String **newStr, const char *value, sal_Int32 len, sal_Int32 allocExtra) SAL_THROW_EXTERN_C()
#define RTL_STR_MAX_VALUEOFBOOLEAN
Definition string.h:589
#define RTL_STR_MAX_VALUEOFFLOAT
Definition string.h:696
SAL_DLLPUBLIC sal_Int32 rtl_str_hashCode(const char *str) SAL_THROW_EXTERN_C()
Return a hash code for a string.
SAL_DLLPUBLIC sal_Int32 rtl_str_valueOfInt32(char *str, sal_Int32 i, sal_Int16 radix) SAL_THROW_EXTERN_C()
Create the string representation of an integer.
SAL_DLLPUBLIC sal_Int32 rtl_str_getLength(const char *str) SAL_THROW_EXTERN_C()
Return the length of a string.
#define RTL_STR_MAX_VALUEOFUINT64
Definition string.h:677
SAL_DLLPUBLIC void rtl_string_newToAsciiLowerCase(rtl_String **newStr, rtl_String *str) SAL_THROW_EXTERN_C()
Create a new string by converting all ASCII uppercase letters to lowercase within another string.
SAL_DLLPUBLIC void rtl_string_newFromStr_WithLength(rtl_String **newStr, const char *value, sal_Int32 len) SAL_THROW_EXTERN_C()
Allocate a new string that contains a copy of a character array.
SAL_DLLPUBLIC void rtl_string_newTrim(rtl_String **newStr, rtl_String *str) SAL_THROW_EXTERN_C()
Create a new string by removing white space from both ends of another string.
SAL_DLLPUBLIC sal_Int32 rtl_str_toInt32(const char *str, sal_Int16 radix) SAL_THROW_EXTERN_C()
Interpret a string as an integer.
#define RTL_STR_MAX_VALUEOFINT64
Definition string.h:654
SAL_DLLPUBLIC void rtl_string_ensureCapacity(rtl_String **str, sal_Int32 size) SAL_THROW_EXTERN_C()
Ensure a string has enough space for a given number of characters.
SAL_DLLPUBLIC void rtl_string_release(rtl_String *str) SAL_THROW_EXTERN_C()
Decrement the reference count of a string.
SAL_DLLPUBLIC void rtl_string_newFromSubString(rtl_String **newStr, const rtl_String *from, sal_Int32 beginIndex, sal_Int32 count) SAL_THROW_EXTERN_C()
Allocate a new string that is a substring of this string.
SAL_DLLPUBLIC sal_Int32 rtl_str_indexOfStr_WithLength(const char *str, sal_Int32 len, const char *subStr, sal_Int32 subLen) SAL_THROW_EXTERN_C()
Search for the first occurrence of a substring within a string.
SAL_DLLPUBLIC sal_Int32 rtl_str_valueOfUInt64(char *str, sal_uInt64 l, sal_Int16 radix) SAL_THROW_EXTERN_C()
Create the string representation of an unsigned long integer.
SAL_DLLPUBLIC void rtl_string_newToAsciiUpperCase(rtl_String **newStr, rtl_String *str) SAL_THROW_EXTERN_C()
Create a new string by converting all ASCII lowercase letters to uppercase within another string.
SAL_DLLPUBLIC float rtl_str_toFloat(const char *str) SAL_THROW_EXTERN_C()
Interpret a string as a float.
SAL_DLLPUBLIC void rtl_string_newReplace(rtl_String **newStr, rtl_String *str, char oldChar, char newChar) SAL_THROW_EXTERN_C()
Create a new string by replacing all occurrences of a single character within another string.
SAL_DLLPUBLIC sal_Int64 rtl_str_toInt64(const char *str, sal_Int16 radix) SAL_THROW_EXTERN_C()
Interpret a string as a long integer.
SAL_DLLPUBLIC sal_Int32 rtl_str_compareIgnoreAsciiCase_WithLength(const char *first, sal_Int32 firstLen, const char *second, sal_Int32 secondLen) SAL_THROW_EXTERN_C()
Compare two strings, ignoring the case of ASCII characters.
SAL_DLLPUBLIC sal_Int32 rtl_str_compare_WithLength(const char *first, sal_Int32 firstLen, const char *second, sal_Int32 secondLen) SAL_THROW_EXTERN_C()
Compare two strings.
SAL_DLLPUBLIC sal_Int32 rtl_str_lastIndexOfChar_WithLength(const char *str, sal_Int32 len, char ch) SAL_THROW_EXTERN_C()
Search for the last occurrence of a character within a string.
sal_uInt16 rtl_TextEncoding
The various supported text encodings.
Definition textenc.h:37
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
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
OString(T &literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type=libreoffice_internal::Dummy())
New string from a string literal.
Definition string.hxx:340
OString(const sal_Unicode *value, sal_Int32 length, rtl_TextEncoding encoding, sal_uInt32 convertFlags=OUSTRING_TO_OSTRING_CVTFLAGS)
New string from a Unicode character buffer array.
Definition string.hxx:410
libreoffice_internal::ConstCharArrayDetector< T, bool >::Type endsWith(T &literal, OString *rest=NULL) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition string.hxx:1200
static OString 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 string.hxx:2055
bool startsWith(OString const &str, OString *rest=NULL) const
Check whether this string starts with a given substring.
Definition string.hxx:1072
friend libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator==(const OString &rStr, T &literal)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition string.hxx:1296
libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWith(T &literal, OString *rest=NULL) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition string.hxx:1087
friend libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator==(T &literal, const OString &rStr)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition string.hxx:1318
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 string.hxx:1478
OString(const char *value, sal_Int32 length)
New string from a character buffer array.
Definition string.hxx:367
static OString 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 string.hxx:2068
static OString number(int i, sal_Int16 radix=10)
Returns the string representation of the integer argument.
Definition string.hxx:2036
sal_uInt64 toUInt64(sal_Int16 radix=10) const
Returns the uint64 value from this string.
Definition string.hxx:1968
sal_Int32 indexOfL(char const *str, sal_Int32 len, sal_Int32 fromIndex=0) const
Returns the index within this string of the first occurrence of the specified substring,...
Definition string.hxx:1508
libreoffice_internal::ConstCharArrayDetector< T, OString & >::Type operator=(T &literal)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition string.hxx:524
sal_Int32 compareTo(const OString &str) const
Compares two strings.
Definition string.hxx:706
OString & operator+=(const OString &str)
Append a string to this string.
Definition string.hxx:546
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 string.hxx:868
SAL_WARN_UNUSED_RESULT OString toAsciiUpperCase() const
Converts from this string all ASCII lowercase characters (97-122) to ASCII uppercase characters (65-9...
Definition string.hxx:1811
libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWithIgnoreAsciiCase(T &literal, OString *rest=NULL) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition string.hxx:1147
friend libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator!=(T &literal, const OString &rStr)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition string.hxx:1375
char toChar() const
Returns the first character from this string.
Definition string.hxx:1904
bool toBoolean() const
Returns the Boolean value from this string.
Definition string.hxx:1893
friend OString operator+(const OString &str1, const OString &str2)
Definition string.hxx:1676
SAL_WARN_UNUSED_RESULT OString copy(sal_Int32 beginIndex) const
Returns a new string that is a substring of this string.
Definition string.hxx:1594
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator!=(const OString &rStr1, T &value)
Definition string.hxx:1341
OString(rtl_String *str)
New string from OString data.
Definition string.hxx:263
bool startsWithIgnoreAsciiCase(OString const &str, OString *rest=NULL) const
Check whether this string starts with a given string, ignoring the case of ASCII letters.
Definition string.hxx:1129
static OString 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 string.hxx:2061
sal_Int32 lastIndexOf(const OString &str) const
Returns the index within this string of the last occurrence of the specified substring,...
Definition string.hxx:1546
void clear()
Clears the string, i.e, makes a zero-character string.
Definition string.hxx:638
SAL_WARN_UNUSED_RESULT OString replaceFirst(OString const &from, OString const &to, sal_Int32 *index=NULL) const
Returns a new string resulting from replacing the first occurrence of a given substring with another ...
Definition string.hxx:1752
OString getToken(sal_Int32 count, char separator) const
Returns a token from the string.
Definition string.hxx:1880
static OString 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 string.hxx:2043
const char * getStr() const SAL_RETURNS_NONNULL
Returns a pointer to the characters of this string.
Definition string.hxx:677
OString & operator=(const OString &str)
Assign a new string.
Definition string.hxx:495
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 string.hxx:1034
sal_Int32 compareTo(const OString &rObj, sal_Int32 maxLength) const
Compares two strings with an maximum count of characters.
Definition string.hxx:725
bool isEmpty() const
Checks if a string is empty.
Definition string.hxx:661
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator==(T &value, const OString &rStr2)
Definition string.hxx:1282
OString(const T &value, typename libreoffice_internal::CharPtrDetector< T, libreoffice_internal::Dummy >::Type=libreoffice_internal::Dummy())
New string from a character buffer array.
Definition string.hxx:307
OString getToken(sal_Int32 token, char cTok, sal_Int32 &index) const
Returns a token in the string.
Definition string.hxx:1860
sal_Int32 reverseCompareTo(const OString &str) const
Compares two strings in reverse order.
Definition string.hxx:743
sal_Int32 lastIndexOf(const OString &str, sal_Int32 fromIndex) const
Returns the index within this string of the last occurrence of the specified substring,...
Definition string.hxx:1577
sal_Int32 lastIndexOf(char ch) const
Returns the index within this string of the last occurrence of the specified character,...
Definition string.hxx:1420
SAL_WARN_UNUSED_RESULT OString copy(sal_Int32 beginIndex, sal_Int32 count) const
Returns a new string that is a substring of this string.
Definition string.hxx:1611
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=(const OString &rStr1, const T &value)
Definition string.hxx:1335
SAL_WARN_UNUSED_RESULT OString replace(char oldChar, char newChar) const
Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.
Definition string.hxx:1727
sal_Int32 hashCode() const
Returns a hashcode for this string.
Definition string.hxx:1387
static OString boolean(bool b)
Returns the string representation of the boolean argument.
Definition string.hxx:2152
bool matchL(char const *str, sal_Int32 strLength, sal_Int32 fromIndex=0) const
Match against a substring appearing in this string.
Definition string.hxx:978
bool equalsL(const char *value, sal_Int32 length) const
Perform a comparison of two strings.
Definition string.hxx:784
SAL_WARN_UNUSED_RESULT OString trim() const
Returns a new string resulting from removing white space from both ends of the string.
Definition string.hxx:1829
OString(const OString &str)
New string from OString.
Definition string.hxx:237
SAL_WARN_UNUSED_RESULT OString replaceAll(OString const &from, OString const &to) const
Returns a new string resulting from replacing all occurrences of a given substring with another subst...
Definition string.hxx:1776
bool endsWithL(char const *str, sal_Int32 strLength) const
Check whether this string ends with a given substring.
Definition string.hxx:1236
SAL_WARN_UNUSED_RESULT OString toAsciiLowerCase() const
Converts from this string all ASCII uppercase characters (65-90) to ASCII lowercase characters (97-12...
Definition string.hxx:1794
bool match(const OString &str, sal_Int32 fromIndex=0) const
Match against a substring appearing in this string.
Definition string.hxx:934
float toFloat() const
Returns the float value from this string.
Definition string.hxx:1981
OString()
New string containing no characters.
Definition string.hxx:226
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 string.hxx:947
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator==(const T &value, const OString &rStr2)
Definition string.hxx:1273
OString(char value)
New string from a single character.
Definition string.hxx:286
static OString number(long i, sal_Int16 radix=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition string.hxx:2049
bool equalsIgnoreAsciiCase(const OString &str) const
Perform an ASCII lowercase comparison of two strings.
Definition string.hxx:818
sal_Int64 toInt64(sal_Int16 radix=10) const
Returns the int64 value from this string.
Definition string.hxx:1951
sal_Int32 indexOf(const OString &str, sal_Int32 fromIndex=0) const
Returns the index within this string of the first occurrence of the specified substring,...
Definition string.hxx:1465
sal_Int32 toInt32(sal_Int16 radix=10) const
Returns the int32 value from this string.
Definition string.hxx:1919
~OString()
Release the string data.
Definition string.hxx:459
libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type equalsIgnoreAsciiCase(T &asciiStr) const
Definition string.hxx:857
friend libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator!=(const OString &rStr, T &literal)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition string.hxx:1364
libreoffice_internal::CharPtrDetector< T, bool >::Type equalsIgnoreAsciiCase(const T &asciiStr) const
Perform an ASCII lowercase comparison of two strings.
Definition string.hxx:851
sal_Int32 indexOf(char ch, sal_Int32 fromIndex=0) const
Returns the index within this string of the first occurrence of the specified character,...
Definition string.hxx:1405
SAL_WARN_UNUSED_RESULT OString replaceAt(sal_Int32 index, sal_Int32 count, const OString &newStr) const
Returns a new string resulting from replacing n = count characters from position index in this string...
Definition string.hxx:1697
sal_Int32 getLength() const
Returns the length of this string.
Definition string.hxx:651
double toDouble() const
Returns the double value from this string.
Definition string.hxx:1994
static OString number(double d)
Returns the string representation of the double argument.
Definition string.hxx:2106
bool endsWith(OString const &str, OString *rest=NULL) const
Check whether this string ends with a given substring.
Definition string.hxx:1184
bool equals(const OString &str) const
Perform a comparison of two strings.
Definition string.hxx:760
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator==(const OString &rStr1, T &value)
Definition string.hxx:1264
OString(rtl_String *str, __sal_NoAcquire)
New string from OString data without acquiring it.
Definition string.hxx:276
sal_Int32 lastIndexOf(char ch, sal_Int32 fromIndex) const
Returns the index within this string of the last occurrence of the specified character,...
Definition string.hxx:1437
OString(T &value, typename libreoffice_internal::NonConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type=libreoffice_internal::Dummy())
Definition string.hxx:314
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator==(const OString &rStr1, const T &value)
Definition string.hxx:1255
sal_uInt32 toUInt32(sal_Int16 radix=10) const
Returns the uint32 value from this string.
Definition string.hxx:1936
static OString number(float f)
Returns the string representation of the float argument.
Definition string.hxx:2084
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=(const T &value, const OString &rStr2)
Definition string.hxx:1347
bool equalsIgnoreAsciiCaseL(const char *asciiStr, sal_Int32 asciiStrLength) const
Perform an ASCII lowercase comparison of two strings.
Definition string.hxx:903
bool matchIgnoreAsciiCase(const OString &str, sal_Int32 fromIndex=0) const
Match against a substring appearing in this string, ignoring the case of ASCII letters.
Definition string.hxx:1021
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator!=(T &value, const OString &rStr2)
Definition string.hxx:1353
A helper to use OStrings with hash maps.
Definition string.hxx:2315
size_t operator()(const OString &rString) const
Compute a hash code for a string.
Definition string.hxx:2325
Equality functor for classic c-strings (i.e., null-terminated char* strings).
Definition string.hxx:2331
bool operator()(const char *p1, const char *p2) const
Definition string.hxx:2332
Hashing functor for classic c-strings (i.e., null-terminated char* strings).
Definition string.hxx:2338
size_t operator()(const char *p) const
Definition string.hxx:2339
Definition stringutils.hxx:140
Definition stringutils.hxx:143