LibreOffice
LibreOffice 7.4 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/textenc.h"
44#include "rtl/string.h"
45#include "rtl/stringutils.hxx"
46
47#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
48#include "config_global.h"
49#include "rtl/stringconcat.hxx"
50#endif
51
52#ifdef RTL_STRING_UNITTEST
53extern bool rtl_string_unittest_const_literal;
54extern bool rtl_string_unittest_const_literal_function;
55#endif
56
57// The unittest uses slightly different code to help check that the proper
58// calls are made. The class is put into a different namespace to make
59// sure the compiler generates a different (if generating also non-inline)
60// copy of the function and does not merge them together. The class
61// is "brought" into the proper rtl namespace by a typedef below.
62#ifdef RTL_STRING_UNITTEST
63#define rtl rtlunittest
64#endif
65
66namespace rtl
67{
68
70#ifdef RTL_STRING_UNITTEST
71#undef rtl
72// helper macro to make functions appear more readable
73#define RTL_STRING_CONST_FUNCTION rtl_string_unittest_const_literal_function = true;
74#else
75#define RTL_STRING_CONST_FUNCTION
76#endif
78
79#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
86template<std::size_t N> class SAL_WARN_UNUSED OStringLiteral {
87 static_assert(N != 0);
88 static_assert(N - 1 <= std::numeric_limits<sal_Int32>::max(), "literal too long");
89 friend class OString;
90
91public:
92#if HAVE_CPP_CONSTEVAL
93 consteval
94#else
95 constexpr
96#endif
97 OStringLiteral(char const (&literal)[N]) {
98 assertLayout();
99 assert(literal[N - 1] == '\0');
100 //TODO: Use C++20 constexpr std::copy_n (P0202R3):
101 for (std::size_t i = 0; i != N; ++i) {
102 more.buffer[i] = literal[i];
103 }
104 }
105
106#if defined __cpp_char8_t
107#if HAVE_CPP_CONSTEVAL
108 consteval
109#else
110 constexpr
111#endif
112 explicit OStringLiteral(char8_t const (&literal)[N]) {
113 assertLayout();
114 assert(literal[N - 1] == '\0');
115 //TODO: Use C++20 constexpr std::copy_n (P0202R3):
116 for (std::size_t i = 0; i != N; ++i) {
117 more.buffer[i] = literal[i];
118 }
119 }
120#endif
121
122 constexpr sal_Int32 getLength() const { return more.length; }
123
124 constexpr char const * getStr() const SAL_RETURNS_NONNULL { return more.buffer; }
125
126 constexpr operator std::string_view() const { return {more.buffer, sal_uInt32(more.length)}; }
127
128private:
129 static constexpr void assertLayout() {
130 // These static_asserts verifying the layout compatibility with rtl_String cannot be class
131 // member declarations, as offsetof requires a complete type, so defer them to here:
132 static_assert(std::is_standard_layout_v<OStringLiteral>);
133 static_assert(offsetof(OStringLiteral, str.refCount) == offsetof(OStringLiteral, more.refCount));
134 static_assert(offsetof(OStringLiteral, str.length) == offsetof(OStringLiteral, more.length));
135 static_assert(offsetof(OStringLiteral, str.buffer) == offsetof(OStringLiteral, more.buffer));
136 }
137
138 struct Data {
139 Data() = default;
140
141 oslInterlockedCount refCount = 0x40000000; // SAL_STRING_STATIC_FLAG (sal/rtl/strimp.hxx)
142 sal_Int32 length = N - 1;
143 char buffer[N] = {}; //TODO: drop initialization for C++20 (P1331R2)
144 };
145
146 union {
147 rtl_String str;
148 Data more = {};
149 };
150};
151#endif
152
153/* ======================================================================= */
154
179class SAL_WARN_UNUSED SAL_DLLPUBLIC_RTTI OString
180{
181public:
183 rtl_String * pData;
185
190 {
191 pData = NULL;
192 rtl_string_new( &pData );
193 }
194
200 OString( const OString & str )
201 {
202 pData = str.pData;
203 rtl_string_acquire( pData );
204 }
205
206#if defined LIBO_INTERNAL_ONLY
213 OString( OString && str ) noexcept
214 {
215 pData = str.pData;
216 str.pData = nullptr;
217 rtl_string_new( &str.pData );
218 }
219#endif
220
226 OString( rtl_String * str )
227 {
228 pData = str;
229 rtl_string_acquire( pData );
230 }
231
239 OString( rtl_String * str, __sal_NoAcquire )
240 {
241 pData = str;
242 }
243
249 explicit OString( char value )
250 : pData (NULL)
251 {
252 rtl_string_newFromStr_WithLength( &pData, &value, 1 );
253 }
254
255#if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST_CONCAT
256 // Catch inadvertent conversions to the above ctor (e.g., from sal_[u]Int8, aka [un]signed
257 // char):
258 OString(int) = delete;
259#endif
260
269 template< typename T >
271 {
272 pData = NULL;
273 rtl_string_newFromStr( &pData, value );
274 }
275
276 template< typename T >
278 {
279 pData = NULL;
280 rtl_string_newFromStr( &pData, value );
281 }
282
293 template< typename T >
295 {
296 assert(
298 pData = NULL;
300 rtl_string_new(&pData);
301 } else {
303 &pData,
305 literal),
307 }
308#ifdef RTL_STRING_UNITTEST
309 rtl_string_unittest_const_literal = true;
310#endif
311 }
312
321 OString( const char * value, sal_Int32 length )
322 {
323 pData = NULL;
324 rtl_string_newFromStr_WithLength( &pData, value, length );
325 }
326
327#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
329
334 template<std::size_t N> constexpr OString(OStringLiteral<N> const & literal):
335 pData(const_cast<rtl_String *>(&literal.str)) {}
336 template<std::size_t N> OString(OStringLiteral<N> &&) = delete;
338#endif
339
340#if defined LIBO_INTERNAL_ONLY
341 explicit OString(std::string_view sv) {
342 if (sv.size() > sal_uInt32(std::numeric_limits<sal_Int32>::max())) {
343 throw std::bad_alloc();
344 }
345 pData = nullptr;
346 rtl_string_newFromStr_WithLength(&pData, sv.data(), sv.size());
347 }
348#endif
349
364 OString( const sal_Unicode * value, sal_Int32 length,
365 rtl_TextEncoding encoding,
366 sal_uInt32 convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS )
367 {
368 pData = NULL;
369 rtl_uString2String( &pData, value, length, encoding, convertFlags );
370 if (pData == NULL) {
371 throw std::bad_alloc();
372 }
373 }
374
375#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
380 template< typename T1, typename T2 >
381 OString( OStringConcat< T1, T2 >&& c )
382 {
383 const sal_Int32 l = c.length();
384 pData = rtl_string_alloc( l );
385 if (l != 0)
386 {
387 char* end = c.addData( pData->buffer );
388 pData->length = l;
389 *end = '\0';
390 }
391 }
392
397 template< typename T >
398 OString( OStringNumber< T >&& n )
399 : OString( n.buf, n.length )
400 {}
401#endif
402
403#ifdef LIBO_INTERNAL_ONLY
404 OString(std::nullptr_t) = delete;
405#endif
406
411 {
412 rtl_string_release( pData );
413 }
414
420 OString & operator=( const OString & str )
421 {
422 rtl_string_assign( &pData, str.pData );
423 return *this;
424 }
425
426#if defined LIBO_INTERNAL_ONLY
433 OString & operator=( OString && str ) noexcept
434 {
435 rtl_string_release( pData );
436 pData = str.pData;
437 str.pData = nullptr;
438 rtl_string_new( &str.pData );
439 return *this;
440 }
441#endif
442
448 template< typename T >
450 {
451 RTL_STRING_CONST_FUNCTION
452 assert(
455 rtl_string_new(&pData);
456 } else {
458 &pData,
460 literal),
462 }
463 return *this;
464 }
465
471 OString & operator+=( const OString & str )
472#if defined LIBO_INTERNAL_ONLY
473 &
474#endif
475 {
476 rtl_string_newConcat( &pData, pData, str.pData );
477 return *this;
478 }
479#if defined LIBO_INTERNAL_ONLY
480 void operator+=(OString const &) && = delete;
481#endif
482
483#if defined LIBO_INTERNAL_ONLY
485 operator +=(T const & value) & { return operator +=(std::string_view(value)); }
486 template<typename T> typename libreoffice_internal::CharPtrDetector<T, OString &>::Type
487 operator +=(T const &) && = delete;
488
489 template<typename T>
490 typename libreoffice_internal::NonConstCharArrayDetector<T, OString &>::Type
491 operator +=(T & value) & { return operator +=(std::string_view(value)); }
492 template<typename T>
493 typename libreoffice_internal::NonConstCharArrayDetector<T, OString &>::Type operator +=(T &) &&
494 = delete;
495
496 template<typename T> typename libreoffice_internal::ConstCharArrayDetector<T, OString &>::Type
497 operator +=(T & literal) & {
498 assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
499 return operator +=(
500 std::string_view(
501 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
502 libreoffice_internal::ConstCharArrayDetector<T>::length));
503 }
504 template<typename T> typename libreoffice_internal::ConstCharArrayDetector<T, OString &>::Type
505 operator +=(T &) && = delete;
506
507 template<std::size_t N> OString & operator +=(OStringLiteral<N> const & literal) &
508 { return operator +=(std::string_view(literal.getStr(), literal.getLength())); }
509 template<std::size_t N> void operator +=(OStringLiteral<N> const &) && = delete;
510
511 OString & operator +=(std::string_view sv) & {
512 if (sv.empty()) {
513 return *this;
514 }
515 if (sv.size() > sal_uInt32(std::numeric_limits<sal_Int32>::max() - pData->length)) {
516 throw std::bad_alloc();
517 }
518 auto const l = pData->length + sv.size();
519 rtl_string_ensureCapacity(&pData, l);
520 *addDataHelper(pData->buffer + pData->length, sv.data(), sv.size()) = '\0';
521 pData->length = l;
522 return *this;
523 }
524 void operator +=(std::string_view) && = delete;
525#endif
526
527#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
532 template< typename T1, typename T2 >
533 OString& operator+=( OStringConcat< T1, T2 >&& c ) & {
534 sal_Int32 l = c.length();
535 if( l == 0 )
536 return *this;
537 l += pData->length;
538 rtl_string_ensureCapacity( &pData, l );
539 char* end = c.addData( pData->buffer + pData->length );
540 *end = '\0';
541 pData->length = l;
542 return *this;
543 }
544 template<typename T1, typename T2> void operator +=(
545 OStringConcat<T1, T2> &&) && = delete;
546
551 template< typename T >
552 OString& operator+=( OStringNumber< T >&& n ) & {
553 return operator +=(std::string_view(n.buf, n.length));
554 }
555 template<typename T> void operator +=(
556 OStringNumber<T> &&) && = delete;
557#endif
558
563 void clear()
564 {
565 rtl_string_new( &pData );
566 }
567
576 sal_Int32 getLength() const { return pData->length; }
577
586 bool isEmpty() const
587 {
588 return pData->length == 0;
589 }
590
602 const char * getStr() const SAL_RETURNS_NONNULL { return pData->buffer; }
603
613 char operator [](sal_Int32 index) const {
614 // silence spurious -Werror=strict-overflow warnings from GCC 4.8.2
615 assert(index >= 0 && static_cast<sal_uInt32>(index) < static_cast<sal_uInt32>(getLength()));
616 return getStr()[index];
617 }
618
631 sal_Int32 compareTo( const OString & str ) const
632 {
633 return rtl_str_compare_WithLength( pData->buffer, pData->length,
634 str.pData->buffer, str.pData->length );
635 }
636
650 sal_Int32 compareTo( const OString & rObj, sal_Int32 maxLength ) const
651 {
652 return rtl_str_shortenedCompare_WithLength( pData->buffer, pData->length,
653 rObj.pData->buffer, rObj.pData->length, maxLength );
654 }
655
668 sal_Int32 reverseCompareTo( const OString & str ) const
669 {
670 return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
671 str.pData->buffer, str.pData->length );
672 }
673
685 bool equals( const OString & str ) const
686 {
687 if ( pData->length != str.pData->length )
688 return false;
689 if ( pData == str.pData )
690 return true;
691 return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
692 str.pData->buffer, str.pData->length ) == 0;
693 }
694
710 bool equalsL( const char* value, sal_Int32 length ) const
711 {
712 if ( pData->length != length )
713 return false;
714
715 return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
716 value, length ) == 0;
717 }
718
733#if defined LIBO_INTERNAL_ONLY
734 bool equalsIgnoreAsciiCase( std::string_view str ) const
735 {
736 if ( sal_uInt32(pData->length) != str.size() )
737 return false;
738 if ( pData->buffer == str.data() )
739 return true;
740 return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
741 str.data(), str.size() ) == 0;
742 }
743#else
744 bool equalsIgnoreAsciiCase( const OString & str ) const
745 {
746 if ( pData->length != str.pData->length )
747 return false;
748 if ( pData == str.pData )
749 return true;
750 return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
751 str.pData->buffer, str.pData->length ) == 0;
752 }
753#endif
754
776 template< typename T >
778 {
779 return rtl_str_compareIgnoreAsciiCase( pData->buffer, asciiStr ) == 0;
780 }
781
782 template< typename T >
784 {
785 return rtl_str_compareIgnoreAsciiCase( pData->buffer, asciiStr ) == 0;
786 }
787
793 template< typename T >
795 {
796 RTL_STRING_CONST_FUNCTION
797 assert(
799 return
800 (pData->length
803 pData->buffer, pData->length,
805 literal),
807 == 0);
808 }
809
829 bool equalsIgnoreAsciiCaseL( const char * asciiStr, sal_Int32 asciiStrLength ) const
830 {
831 if ( pData->length != asciiStrLength )
832 return false;
833
834 return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
835 asciiStr, asciiStrLength ) == 0;
836 }
837
853#if defined LIBO_INTERNAL_ONLY
854 bool match( std::string_view str, sal_Int32 fromIndex = 0 ) const
855 {
856 return rtl_str_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
857 str.data(), str.size(), str.size() ) == 0;
858 }
859#else
860 bool match( const OString & str, sal_Int32 fromIndex = 0 ) const
861 {
862 return rtl_str_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
863 str.pData->buffer, str.pData->length, str.pData->length ) == 0;
864 }
865#endif
866
872 template< typename T >
873 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type match( T& literal, sal_Int32 fromIndex = 0 ) const
874 {
875 RTL_STRING_CONST_FUNCTION
876 assert(
878 return
880 pData->buffer + fromIndex, pData->length - fromIndex,
882 literal),
885 == 0;
886 }
887
904 bool matchL(
905 char const * str, sal_Int32 strLength, sal_Int32 fromIndex = 0)
906 const
907 {
909 pData->buffer + fromIndex, pData->length - fromIndex,
910 str, strLength, strLength) == 0;
911 }
912
913 // This overload is left undefined, to detect calls of matchL that
914 // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
915 // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
916 // platforms):
917#if SAL_TYPES_SIZEOFLONG == 8
918 void matchL(char const *, sal_Int32, rtl_TextEncoding) const;
919#endif
920
939#if defined LIBO_INTERNAL_ONLY
940 bool matchIgnoreAsciiCase( std::string_view str, sal_Int32 fromIndex = 0 ) const
941 {
942 return rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
943 str.data(), str.size(),
944 str.size() ) == 0;
945 }
946#else
947 bool matchIgnoreAsciiCase( const OString & str, sal_Int32 fromIndex = 0 ) const
948 {
949 return rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
950 str.pData->buffer, str.pData->length,
951 str.pData->length ) == 0;
952 }
953#endif
959 template< typename T >
961 {
962 RTL_STRING_CONST_FUNCTION
963 assert(
965 return
967 pData->buffer+fromIndex, pData->length-fromIndex,
969 literal),
972 == 0;
973 }
974
989#if defined LIBO_INTERNAL_ONLY
990 bool startsWith(std::string_view str, OString * rest = NULL) const {
991 bool b = match(str);
992 if (b && rest != NULL) {
993 *rest = copy(str.size());
994 }
995 return b;
996 }
997#else
998 bool startsWith(OString const & str, OString * rest = NULL) const {
999 bool b = match(str);
1000 if (b && rest != NULL) {
1001 *rest = copy(str.getLength());
1002 }
1003 return b;
1004 }
1005#endif
1006
1012 template< typename T >
1014 T & literal, OString * rest = NULL) const
1015 {
1016 RTL_STRING_CONST_FUNCTION
1017 bool b = match(literal, 0);
1018 if (b && rest != NULL) {
1019 *rest = copy(
1021 }
1022 return b;
1023 }
1024
1044#if defined LIBO_INTERNAL_ONLY
1045 bool startsWithIgnoreAsciiCase(std::string_view str, OString * rest = NULL)
1046 const
1047 {
1048 bool b = matchIgnoreAsciiCase(str);
1049 if (b && rest != NULL) {
1050 *rest = copy(str.size());
1051 }
1052 return b;
1053 }
1054#else
1055 bool startsWithIgnoreAsciiCase(OString const & str, OString * rest = NULL)
1056 const
1057 {
1058 bool b = matchIgnoreAsciiCase(str);
1059 if (b && rest != NULL) {
1060 *rest = copy(str.getLength());
1061 }
1062 return b;
1063 }
1064#endif
1065
1071 template< typename T >
1073 startsWithIgnoreAsciiCase(T & literal, OString * rest = NULL) const
1074 {
1075 RTL_STRING_CONST_FUNCTION
1076 assert(
1078 bool b = matchIgnoreAsciiCase(literal);
1079 if (b && rest != NULL) {
1080 *rest = copy(
1082 }
1083 return b;
1084 }
1085
1100#if defined LIBO_INTERNAL_ONLY
1101 bool endsWith(std::string_view str, OString * rest = NULL) const {
1102 bool b = str.size() <= sal_uInt32(getLength())
1103 && match(str, getLength() - str.size());
1104 if (b && rest != NULL) {
1105 *rest = copy(0, getLength() - str.size());
1106 }
1107 return b;
1108 }
1109#else
1110 bool endsWith(OString const & str, OString * rest = NULL) const {
1111 bool b = str.getLength() <= getLength()
1112 && match(str, getLength() - str.getLength());
1113 if (b && rest != NULL) {
1114 *rest = copy(0, getLength() - str.getLength());
1115 }
1116 return b;
1117 }
1118#endif
1119
1125 template< typename T >
1127 T & literal, OString * rest = NULL) const
1128 {
1129 RTL_STRING_CONST_FUNCTION
1130 assert(
1132 bool b
1134 <= sal_uInt32(getLength()))
1135 && match(
1137 literal),
1138 (getLength()
1140 if (b && rest != NULL) {
1141 *rest = copy(
1142 0,
1143 (getLength()
1145 }
1146 return b;
1147 }
1148
1162 bool endsWithL(char const * str, sal_Int32 strLength) const {
1163 return strLength <= getLength()
1164 && matchL(str, strLength, getLength() - strLength);
1165 }
1166
1167 friend bool operator == ( const OString& rStr1, const OString& rStr2 )
1168 { return rStr1.equals(rStr2); }
1169 friend bool operator != ( const OString& rStr1, const OString& rStr2 )
1170 { return !(operator == ( rStr1, rStr2 )); }
1171 friend bool operator < ( const OString& rStr1, const OString& rStr2 )
1172 { return rStr1.compareTo( rStr2 ) < 0; }
1173 friend bool operator > ( const OString& rStr1, const OString& rStr2 )
1174 { return rStr1.compareTo( rStr2 ) > 0; }
1175 friend bool operator <= ( const OString& rStr1, const OString& rStr2 )
1176 { return rStr1.compareTo( rStr2 ) <= 0; }
1177 friend bool operator >= ( const OString& rStr1, const OString& rStr2 )
1178 { return rStr1.compareTo( rStr2 ) >= 0; }
1179
1180 template< typename T >
1181 friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator==( const OString& rStr1, const T& value )
1182 {
1183 return
1185 rStr1.getStr(), rStr1.getLength(), value, rtl_str_getLength(value))
1186 == 0;
1187 }
1188
1189 template< typename T >
1191 {
1192 return
1194 rStr1.getStr(), rStr1.getLength(), value, rtl_str_getLength(value))
1195 == 0;
1196 }
1197
1198 template< typename T >
1199 friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator==( const T& value, const OString& rStr2 )
1200 {
1201 return
1203 value, rtl_str_getLength(value), rStr2.getStr(), rStr2.getLength())
1204 == 0;
1205 }
1206
1207 template< typename T >
1209 {
1210 return
1212 value, rtl_str_getLength(value), rStr2.getStr(), rStr2.getLength())
1213 == 0;
1214 }
1215
1221 template< typename T >
1223 {
1224 RTL_STRING_CONST_FUNCTION
1225 assert(
1227 return
1228 (rStr.getLength()
1231 rStr.pData->buffer, rStr.pData->length,
1233 literal),
1235 == 0);
1236 }
1237
1243 template< typename T >
1245 {
1246 RTL_STRING_CONST_FUNCTION
1247 assert(
1249 return
1250 (rStr.getLength()
1253 rStr.pData->buffer, rStr.pData->length,
1255 literal),
1257 == 0);
1258 }
1259
1260 template< typename T >
1261 friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=( const OString& rStr1, const T& value )
1262 {
1263 return !(operator == ( rStr1, value ));
1264 }
1265
1266 template< typename T >
1268 {
1269 return !(operator == ( rStr1, value ));
1270 }
1271
1272 template< typename T >
1273 friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=( const T& value, const OString& rStr2 )
1274 {
1275 return !(operator == ( value, rStr2 ));
1276 }
1277
1278 template< typename T >
1280 {
1281 return !(operator == ( value, rStr2 ));
1282 }
1283
1289 template< typename T >
1291 {
1292 return !( rStr == literal );
1293 }
1294
1300 template< typename T >
1302 {
1303 return !( literal == rStr );
1304 }
1305
1313 sal_Int32 hashCode() const
1314 {
1315 return rtl_str_hashCode_WithLength( pData->buffer, pData->length );
1316 }
1317
1331 sal_Int32 indexOf( char ch, sal_Int32 fromIndex = 0 ) const
1332 {
1333 sal_Int32 ret = rtl_str_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
1334 return (ret < 0 ? ret : ret+fromIndex);
1335 }
1336
1346 sal_Int32 lastIndexOf( char ch ) const
1347 {
1348 return rtl_str_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
1349 }
1350
1363 sal_Int32 lastIndexOf( char ch, sal_Int32 fromIndex ) const
1364 {
1365 return rtl_str_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
1366 }
1367
1383#if defined LIBO_INTERNAL_ONLY
1384 sal_Int32 indexOf( std::string_view str, sal_Int32 fromIndex = 0 ) const
1385 {
1386 sal_Int32 ret = rtl_str_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1387 str.data(), str.size() );
1388 return (ret < 0 ? ret : ret+fromIndex);
1389 }
1390#else
1391 sal_Int32 indexOf( const OString & str, sal_Int32 fromIndex = 0 ) const
1392 {
1393 sal_Int32 ret = rtl_str_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1394 str.pData->buffer, str.pData->length );
1395 return (ret < 0 ? ret : ret+fromIndex);
1396 }
1397#endif
1403 template< typename T >
1404 typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const
1405 {
1406 RTL_STRING_CONST_FUNCTION
1407 assert(
1409 sal_Int32 n = rtl_str_indexOfStr_WithLength(
1410 pData->buffer + fromIndex, pData->length - fromIndex,
1413 return n < 0 ? n : n + fromIndex;
1414 }
1415
1434 sal_Int32 indexOfL(char const * str, sal_Int32 len, sal_Int32 fromIndex = 0)
1435 const
1436 {
1437 sal_Int32 n = rtl_str_indexOfStr_WithLength(
1438 pData->buffer + fromIndex, pData->length - fromIndex, str, len);
1439 return n < 0 ? n : n + fromIndex;
1440 }
1441
1442 // This overload is left undefined, to detect calls of indexOfL that
1443 // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
1444 // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
1445 // platforms):
1446#if SAL_TYPES_SIZEOFLONG == 8
1447 void indexOfL(char const *, sal_Int32, rtl_TextEncoding) const;
1448#endif
1449
1465#if defined LIBO_INTERNAL_ONLY
1466 sal_Int32 lastIndexOf( std::string_view str ) const
1467 {
1468 return rtl_str_lastIndexOfStr_WithLength( pData->buffer, pData->length,
1469 str.data(), str.size() );
1470 }
1471#else
1472 sal_Int32 lastIndexOf( const OString & str ) const
1473 {
1474 return rtl_str_lastIndexOfStr_WithLength( pData->buffer, pData->length,
1475 str.pData->buffer, str.pData->length );
1476 }
1477#endif
1478
1496#if defined LIBO_INTERNAL_ONLY
1497 sal_Int32 lastIndexOf( std::string_view str, sal_Int32 fromIndex ) const
1498 {
1499 return rtl_str_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
1500 str.data(), str.size() );
1501 }
1502#else
1503 sal_Int32 lastIndexOf( const OString & str, sal_Int32 fromIndex ) const
1504 {
1505 return rtl_str_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
1506 str.pData->buffer, str.pData->length );
1507 }
1508#endif
1509
1520 SAL_WARN_UNUSED_RESULT OString copy( sal_Int32 beginIndex ) const
1521 {
1522 return copy(beginIndex, getLength() - beginIndex);
1523 }
1524
1537 SAL_WARN_UNUSED_RESULT OString copy( sal_Int32 beginIndex, sal_Int32 count ) const
1538 {
1539 rtl_String *pNew = NULL;
1540 rtl_string_newFromSubString( &pNew, pData, beginIndex, count );
1541 return OString( pNew, SAL_NO_ACQUIRE );
1542 }
1543
1544#if defined LIBO_INTERNAL_ONLY
1555 SAL_WARN_UNUSED_RESULT std::string_view subView( sal_Int32 beginIndex ) const
1556 {
1557 assert(beginIndex >= 0);
1558 assert(beginIndex <= getLength());
1559 return subView(beginIndex, getLength() - beginIndex);
1560 }
1561
1574 SAL_WARN_UNUSED_RESULT std::string_view subView( sal_Int32 beginIndex, sal_Int32 count ) const
1575 {
1576 assert(beginIndex >= 0);
1577 assert(count >= 0);
1578 assert(beginIndex <= getLength());
1579 assert(count <= getLength() - beginIndex);
1580 return std::string_view(*this).substr(beginIndex, count);
1581 }
1582#endif
1583
1584#ifndef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
1593 SAL_WARN_UNUSED_RESULT OString concat( const OString & str ) const
1594 {
1595 rtl_String* pNew = NULL;
1596 rtl_string_newConcat( &pNew, pData, str.pData );
1597 return OString( pNew, SAL_NO_ACQUIRE );
1598 }
1599#endif
1600
1601#ifndef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
1602 friend OString operator+( const OString & str1, const OString & str2 )
1603 {
1604 return str1.concat( str2 );
1605 }
1606#endif
1607
1608// hide this from internal code to avoid ambiguous lookup error
1609#ifndef LIBO_INTERNAL_ONLY
1623 SAL_WARN_UNUSED_RESULT OString replaceAt( sal_Int32 index, sal_Int32 count, const OString& newStr ) const
1624 {
1625 rtl_String* pNew = NULL;
1626 rtl_string_newReplaceStrAt( &pNew, pData, index, count, newStr.pData );
1627 return OString( pNew, SAL_NO_ACQUIRE );
1628 }
1629#endif
1630
1631#ifdef LIBO_INTERNAL_ONLY
1632 SAL_WARN_UNUSED_RESULT OString replaceAt( sal_Int32 index, sal_Int32 count, std::string_view newStr ) const
1633 {
1634 rtl_String* pNew = NULL;
1635 rtl_string_newReplaceStrAt_WithLength ( &pNew, pData, index, count, newStr.data(), newStr.size() );
1636 return OString( pNew, SAL_NO_ACQUIRE );
1637 }
1638#endif
1639
1653 SAL_WARN_UNUSED_RESULT OString replace( char oldChar, char newChar ) const
1654 {
1655 rtl_String* pNew = NULL;
1656 rtl_string_newReplace( &pNew, pData, oldChar, newChar );
1657 return OString( pNew, SAL_NO_ACQUIRE );
1658 }
1659
1679 OString const & from, OString const & to, sal_Int32 * index = NULL) const
1680 {
1681 rtl_String * s = NULL;
1682 sal_Int32 i = 0;
1684 &s, pData, from.pData->buffer, from.pData->length,
1685 to.pData->buffer, to.pData->length, index == NULL ? &i : index);
1686 return OString(s, SAL_NO_ACQUIRE);
1687 }
1688
1702 SAL_WARN_UNUSED_RESULT OString replaceAll(OString const & from, OString const & to) const {
1703 rtl_String * s = NULL;
1705 &s, pData, from.pData->buffer, from.pData->length,
1706 to.pData->buffer, to.pData->length);
1707 return OString(s, SAL_NO_ACQUIRE);
1708 }
1709
1721 {
1722 rtl_String* pNew = NULL;
1723 rtl_string_newToAsciiLowerCase( &pNew, pData );
1724 return OString( pNew, SAL_NO_ACQUIRE );
1725 }
1726
1738 {
1739 rtl_String* pNew = NULL;
1740 rtl_string_newToAsciiUpperCase( &pNew, pData );
1741 return OString( pNew, SAL_NO_ACQUIRE );
1742 }
1743
1756 {
1757 rtl_String* pNew = NULL;
1758 rtl_string_newTrim( &pNew, pData );
1759 return OString( pNew, SAL_NO_ACQUIRE );
1760 }
1761
1786 OString getToken( sal_Int32 token, char cTok, sal_Int32& index ) const
1787 {
1788 rtl_String * pNew = NULL;
1789 index = rtl_string_getToken( &pNew, pData, token, cTok, index );
1790 return OString( pNew, SAL_NO_ACQUIRE );
1791 }
1792
1806 OString getToken(sal_Int32 count, char separator) const {
1807 sal_Int32 n = 0;
1808 return getToken(count, separator, n);
1809 }
1810
1819 bool toBoolean() const
1820 {
1821 return rtl_str_toBoolean( pData->buffer );
1822 }
1823
1830 char toChar() const
1831 {
1832 return pData->buffer[0];
1833 }
1834
1845 sal_Int32 toInt32( sal_Int16 radix = 10 ) const
1846 {
1847 return rtl_str_toInt32( pData->buffer, radix );
1848 }
1849
1862 sal_uInt32 toUInt32( sal_Int16 radix = 10 ) const
1863 {
1864 return rtl_str_toUInt32( pData->buffer, radix );
1865 }
1866
1877 sal_Int64 toInt64( sal_Int16 radix = 10 ) const
1878 {
1879 return rtl_str_toInt64( pData->buffer, radix );
1880 }
1881
1894 sal_uInt64 toUInt64( sal_Int16 radix = 10 ) const
1895 {
1896 return rtl_str_toUInt64( pData->buffer, radix );
1897 }
1898
1907 float toFloat() const
1908 {
1909 return rtl_str_toFloat( pData->buffer );
1910 }
1911
1920 double toDouble() const
1921 {
1922 return rtl_str_toDouble( pData->buffer );
1923 }
1924
1925#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
1926
1927 static OStringNumber< int > number( int i, sal_Int16 radix = 10 )
1928 {
1929 return OStringNumber< int >( i, radix );
1930 }
1931 static OStringNumber< long long > number( long long ll, sal_Int16 radix = 10 )
1932 {
1933 return OStringNumber< long long >( ll, radix );
1934 }
1935 static OStringNumber< unsigned long long > number( unsigned long long ll, sal_Int16 radix = 10 )
1936 {
1937 return OStringNumber< unsigned long long >( ll, radix );
1938 }
1939 static OStringNumber< unsigned long long > number( unsigned int i, sal_Int16 radix = 10 )
1940 {
1941 return number( static_cast< unsigned long long >( i ), radix );
1942 }
1943 static OStringNumber< long long > number( long i, sal_Int16 radix = 10)
1944 {
1945 return number( static_cast< long long >( i ), radix );
1946 }
1947 static OStringNumber< unsigned long long > number( unsigned long i, sal_Int16 radix = 10 )
1948 {
1949 return number( static_cast< unsigned long long >( i ), radix );
1950 }
1951 static OStringNumber< float > number( float f )
1952 {
1953 return OStringNumber< float >( f );
1954 }
1955 static OStringNumber< double > number( double d )
1956 {
1957 return OStringNumber< double >( d );
1958 }
1959#else
1970 static OString number( int i, sal_Int16 radix = 10 )
1971 {
1972 char aBuf[RTL_STR_MAX_VALUEOFINT32];
1973 return OString(aBuf, rtl_str_valueOfInt32(aBuf, i, radix));
1974 }
1977 static OString number( unsigned int i, sal_Int16 radix = 10 )
1978 {
1979 return number( static_cast< unsigned long long >( i ), radix );
1980 }
1983 static OString number( long i, sal_Int16 radix = 10 )
1984 {
1985 return number( static_cast< long long >( i ), radix );
1986 }
1989 static OString number( unsigned long i, sal_Int16 radix = 10 )
1990 {
1991 return number( static_cast< unsigned long long >( i ), radix );
1992 }
1995 static OString number( long long ll, sal_Int16 radix = 10 )
1996 {
1997 char aBuf[RTL_STR_MAX_VALUEOFINT64];
1998 return OString(aBuf, rtl_str_valueOfInt64(aBuf, ll, radix));
1999 }
2002 static OString number( unsigned long long ll, sal_Int16 radix = 10 )
2003 {
2004 char aBuf[RTL_STR_MAX_VALUEOFUINT64];
2005 return OString(aBuf, rtl_str_valueOfUInt64(aBuf, ll, radix));
2006 }
2007
2017 static OString number( float f )
2018 {
2019 char aBuf[RTL_STR_MAX_VALUEOFFLOAT];
2020 return OString(aBuf, rtl_str_valueOfFloat(aBuf, f));
2021 }
2022
2032 static OString number( double d )
2033 {
2034 char aBuf[RTL_STR_MAX_VALUEOFDOUBLE];
2035 return OString(aBuf, rtl_str_valueOfDouble(aBuf, d));
2036 }
2037#endif
2038
2050 SAL_DEPRECATED("use boolean()") static OString valueOf( sal_Bool b )
2051 {
2052 return boolean(b);
2053 }
2054
2066 static OString boolean( bool b )
2067 {
2068 char aBuf[RTL_STR_MAX_VALUEOFBOOLEAN];
2069 return OString(aBuf, rtl_str_valueOfBoolean(aBuf, b));
2070 }
2071
2079 SAL_DEPRECATED("convert to OString or use directly") static OString valueOf( char c )
2080 {
2081 return OString( &c, 1 );
2082 }
2083
2094 SAL_DEPRECATED("use number()") static OString valueOf( sal_Int32 i, sal_Int16 radix = 10 )
2095 {
2096 return number( i, radix );
2097 }
2098
2109 SAL_DEPRECATED("use number()") static OString valueOf( sal_Int64 ll, sal_Int16 radix = 10 )
2110 {
2111 return number( ll, radix );
2112 }
2113
2123 SAL_DEPRECATED("use number()") static OString valueOf( float f )
2124 {
2125 return number(f);
2126 }
2127
2137 SAL_DEPRECATED("use number()") static OString valueOf( double d )
2138 {
2139 return number(d);
2140 }
2141
2142#if defined LIBO_INTERNAL_ONLY
2143 operator std::string_view() const { return {getStr(), sal_uInt32(getLength())}; }
2144#endif
2145
2146#if defined LIBO_INTERNAL_ONLY
2147 // A wrapper for the first expression in an
2148 //
2149 // OString::Concat(e1) + e2 + ...
2150 //
2151 // concatenation chain, when neither of the first two e1, e2 is one of our rtl string-related
2152 // classes (so something like
2153 //
2154 // OString s = "a" + (b ? std::string_view("c") : std::string_view("dd"));
2155 //
2156 // would not compile):
2157 template<typename T> [[nodiscard]] static
2158 typename std::enable_if_t<
2159 ToStringHelper<T>::allowOStringConcat, OStringConcat<OStringConcatMarker, T>>
2160 Concat(T const & value) { return OStringConcat<OStringConcatMarker, T>({}, value); }
2161
2162 // This overload is needed so that an argument of type 'char const[N]' ends up as
2163 // 'OStringConcat<rtl::OStringConcatMarker, char const[N]>' rather than as
2164 // 'OStringConcat<rtl::OStringConcatMarker, char[N]>':
2165 template<typename T, std::size_t N> [[nodiscard]] static
2166 typename std::enable_if_t<
2167 ToStringHelper<T[N]>::allowOStringConcat, OStringConcat<OStringConcatMarker, T[N]>>
2168 Concat(T (& value)[N]) { return OStringConcat<OStringConcatMarker, T[N]>({}, value); }
2169#endif
2170};
2171
2172#if defined LIBO_INTERNAL_ONLY
2173inline bool operator ==(OString const & lhs, OStringConcatenation const & rhs)
2174{ return lhs == std::string_view(rhs); }
2175inline bool operator !=(OString const & lhs, OStringConcatenation const & rhs)
2176{ return lhs != std::string_view(rhs); }
2177inline bool operator ==(OStringConcatenation const & lhs, OString const & rhs)
2178{ return std::string_view(lhs) == rhs; }
2179inline bool operator !=(OStringConcatenation const & lhs, OString const & rhs)
2180{ return std::string_view(lhs) != rhs; }
2181#endif
2182
2183/* ======================================================================= */
2184
2185#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2186
2190template<>
2191struct ToStringHelper< OString >
2192 {
2193 static std::size_t length( const OString& s ) { return s.getLength(); }
2194 static char* addData( char* buffer, const OString& s ) { return addDataHelper( buffer, s.getStr(), s.getLength()); }
2195 static const bool allowOStringConcat = true;
2196 static const bool allowOUStringConcat = false;
2197 };
2198
2202template<std::size_t N>
2203struct ToStringHelper< OStringLiteral<N> >
2204 {
2205 static constexpr std::size_t length( const OStringLiteral<N>& str ) { return str.getLength(); }
2206 static char* addData( char* buffer, const OStringLiteral<N>& str ) { return addDataHelper( buffer, str.getStr(), str.getLength() ); }
2207 static const bool allowOStringConcat = true;
2208 static const bool allowOUStringConcat = false;
2209 };
2210
2214template< typename charT, typename traits, typename T1, typename T2 >
2215inline std::basic_ostream<charT, traits> & operator <<(
2216 std::basic_ostream<charT, traits> & stream, OStringConcat< T1, T2 >&& concat)
2217{
2218 return stream << OString( std::move(concat) );
2219}
2220#endif
2221
2222
2229{
2239 size_t operator()( const OString& rString ) const
2240 { return static_cast<size_t>(rString.hashCode()); }
2241};
2242
2245{
2246 bool operator()( const char* p1, const char* p2) const
2247 { return rtl_str_compare(p1, p2) == 0; }
2248};
2249
2252{
2253 size_t operator()(const char* p) const
2254 { return rtl_str_hashCode(p); }
2255};
2256
2257/* ======================================================================= */
2258
2265template< typename charT, typename traits > std::basic_ostream<charT, traits> &
2266operator <<(
2267 std::basic_ostream<charT, traits> & stream, OString const & rString)
2268{
2269 return stream << rString.getStr();
2270 // best effort; potentially loses data due to embedded null characters
2271}
2272
2273} /* Namespace */
2274
2275#ifdef RTL_STRING_UNITTEST
2276namespace rtl
2277{
2278typedef rtlunittest::OString OString;
2279}
2280#undef RTL_STRING_CONST_FUNCTION
2281#endif
2282
2283#if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
2284using ::rtl::OString;
2285using ::rtl::OStringChar;
2286using ::rtl::OStringConcatenation;
2287using ::rtl::OStringHash;
2288using ::rtl::OStringLiteral;
2289#endif
2290
2292
2297#if defined LIBO_INTERNAL_ONLY
2298namespace std {
2299
2300template<>
2301struct hash<::rtl::OString>
2302{
2303 std::size_t operator()(::rtl::OString const & s) const
2304 { return std::size_t(s.hashCode()); }
2305};
2306
2307}
2308
2309#endif
2311
2312#endif // INCLUDED_RTL_STRING_HXX
2313
2314/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#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 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 sal_Int32 rtl_str_valueOfFloat(char *str, float f) SAL_THROW_EXTERN_C()
Create the string representation of a float.
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_valueOfDouble(char *str, double d) SAL_THROW_EXTERN_C()
Create the string representation of a double.
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
This String class provide base functionality for C++ like 8-Bit character array handling.
Definition: string.hxx:180
SAL_WARN_UNUSED_RESULT OString concat(const OString &str) const
Concatenates the specified string to the end of this string.
Definition: string.hxx:1593
OString(T &literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type=libreoffice_internal::Dummy())
New string from a string literal.
Definition: string.hxx:294
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:364
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:1126
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:1989
bool startsWith(OString const &str, OString *rest=NULL) const
Check whether this string starts with a given substring.
Definition: string.hxx:998
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:1222
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:1013
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:1244
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:1404
OString(const char *value, sal_Int32 length)
New string from a character buffer array.
Definition: string.hxx:321
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:2002
static OString number(int i, sal_Int16 radix=10)
Returns the string representation of the integer argument.
Definition: string.hxx:1970
sal_uInt64 toUInt64(sal_Int16 radix=10) const
Returns the uint64 value from this string.
Definition: string.hxx:1894
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:1434
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:449
sal_Int32 compareTo(const OString &str) const
Compares two strings.
Definition: string.hxx:631
OString & operator+=(const OString &str)
Append a string to this string.
Definition: string.hxx:471
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:794
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:1737
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:1073
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:1301
char toChar() const
Returns the first character from this string.
Definition: string.hxx:1830
bool toBoolean() const
Returns the Boolean value from this string.
Definition: string.hxx:1819
friend OString operator+(const OString &str1, const OString &str2)
Definition: string.hxx:1602
SAL_WARN_UNUSED_RESULT OString copy(sal_Int32 beginIndex) const
Returns a new string that is a substring of this string.
Definition: string.hxx:1520
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator!=(const OString &rStr1, T &value)
Definition: string.hxx:1267
OString(rtl_String *str)
New string from OString data.
Definition: string.hxx:226
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:1055
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:1995
sal_Int32 lastIndexOf(const OString &str) const
Returns the index within this string of the last occurrence of the specified substring,...
Definition: string.hxx:1472
void clear()
Clears the string, i.e, makes a zero-character string.
Definition: string.hxx:563
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:1678
OString getToken(sal_Int32 count, char separator) const
Returns a token from the string.
Definition: string.hxx:1806
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:1977
const char * getStr() const SAL_RETURNS_NONNULL
Returns a pointer to the characters of this string.
Definition: string.hxx:602
OString & operator=(const OString &str)
Assign a new string.
Definition: string.hxx:420
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:960
sal_Int32 compareTo(const OString &rObj, sal_Int32 maxLength) const
Compares two strings with an maximum count of characters.
Definition: string.hxx:650
bool isEmpty() const
Checks if a string is empty.
Definition: string.hxx:586
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator==(T &value, const OString &rStr2)
Definition: string.hxx:1208
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:270
OString getToken(sal_Int32 token, char cTok, sal_Int32 &index) const
Returns a token in the string.
Definition: string.hxx:1786
sal_Int32 reverseCompareTo(const OString &str) const
Compares two strings in reverse order.
Definition: string.hxx:668
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:1503
sal_Int32 lastIndexOf(char ch) const
Returns the index within this string of the last occurrence of the specified character,...
Definition: string.hxx:1346
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:1537
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=(const OString &rStr1, const T &value)
Definition: string.hxx:1261
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:1653
sal_Int32 hashCode() const
Returns a hashcode for this string.
Definition: string.hxx:1313
static OString boolean(bool b)
Returns the string representation of the boolean argument.
Definition: string.hxx:2066
bool matchL(char const *str, sal_Int32 strLength, sal_Int32 fromIndex=0) const
Match against a substring appearing in this string.
Definition: string.hxx:904
bool equalsL(const char *value, sal_Int32 length) const
Perform a comparison of two strings.
Definition: string.hxx:710
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:1755
OString(const OString &str)
New string from OString.
Definition: string.hxx:200
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:1702
bool endsWithL(char const *str, sal_Int32 strLength) const
Check whether this string ends with a given substring.
Definition: string.hxx:1162
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:1720
bool match(const OString &str, sal_Int32 fromIndex=0) const
Match against a substring appearing in this string.
Definition: string.hxx:860
float toFloat() const
Returns the float value from this string.
Definition: string.hxx:1907
OString()
New string containing no characters.
Definition: string.hxx:189
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:873
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator==(const T &value, const OString &rStr2)
Definition: string.hxx:1199
OString(char value)
New string from a single character.
Definition: string.hxx:249
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:1983
bool equalsIgnoreAsciiCase(const OString &str) const
Perform an ASCII lowercase comparison of two strings.
Definition: string.hxx:744
sal_Int64 toInt64(sal_Int16 radix=10) const
Returns the int64 value from this string.
Definition: string.hxx:1877
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:1391
sal_Int32 toInt32(sal_Int16 radix=10) const
Returns the int32 value from this string.
Definition: string.hxx:1845
~OString()
Release the string data.
Definition: string.hxx:410
libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type equalsIgnoreAsciiCase(T &asciiStr) const
Definition: string.hxx:783
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:1290
libreoffice_internal::CharPtrDetector< T, bool >::Type equalsIgnoreAsciiCase(const T &asciiStr) const
Perform an ASCII lowercase comparison of two strings.
Definition: string.hxx:777
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:1331
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:1623
sal_Int32 getLength() const
Returns the length of this string.
Definition: string.hxx:576
double toDouble() const
Returns the double value from this string.
Definition: string.hxx:1920
static OString number(double d)
Returns the string representation of the double argument.
Definition: string.hxx:2032
bool endsWith(OString const &str, OString *rest=NULL) const
Check whether this string ends with a given substring.
Definition: string.hxx:1110
bool equals(const OString &str) const
Perform a comparison of two strings.
Definition: string.hxx:685
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator==(const OString &rStr1, T &value)
Definition: string.hxx:1190
OString(rtl_String *str, __sal_NoAcquire)
New string from OString data without acquiring it.
Definition: string.hxx:239
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:1363
OString(T &value, typename libreoffice_internal::NonConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type=libreoffice_internal::Dummy())
Definition: string.hxx:277
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator==(const OString &rStr1, const T &value)
Definition: string.hxx:1181
sal_uInt32 toUInt32(sal_Int16 radix=10) const
Returns the uint32 value from this string.
Definition: string.hxx:1862
static OString number(float f)
Returns the string representation of the float argument.
Definition: string.hxx:2017
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=(const T &value, const OString &rStr2)
Definition: string.hxx:1273
bool equalsIgnoreAsciiCaseL(const char *asciiStr, sal_Int32 asciiStrLength) const
Perform an ASCII lowercase comparison of two strings.
Definition: string.hxx:829
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:947
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator!=(T &value, const OString &rStr2)
Definition: string.hxx:1279
A helper to use OStrings with hash maps.
Definition: string.hxx:2229
size_t operator()(const OString &rString) const
Compute a hash code for a string.
Definition: string.hxx:2239
Equality functor for classic c-strings (i.e., null-terminated char* strings).
Definition: string.hxx:2245
bool operator()(const char *p1, const char *p2) const
Definition: string.hxx:2246
Hashing functor for classic c-strings (i.e., null-terminated char* strings).
Definition: string.hxx:2252
size_t operator()(const char *p) const
Definition: string.hxx:2253
Definition: stringutils.hxx:140
Definition: stringutils.hxx:143