LibreOffice
LibreOffice 7.1 SDK C/C++ API Reference
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#ifndef INCLUDED_RTL_STRING_HXX
21#define INCLUDED_RTL_STRING_HXX
22
23#include "sal/config.h"
24
25#include <cassert>
26#include <cstddef>
27#include <cstdlib>
28#include <limits>
29#include <new>
30#include <ostream>
31#include <utility>
32#include <string.h>
33
34#if defined LIBO_INTERNAL_ONLY
35#include <string_view>
36#include <type_traits>
37#endif
38
39#include "rtl/textenc.h"
40#include "rtl/string.h"
41#include "rtl/stringutils.hxx"
42
43#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
44#include "config_global.h"
45#include "rtl/stringconcat.hxx"
46#endif
47
48#ifdef RTL_STRING_UNITTEST
49extern bool rtl_string_unittest_const_literal;
50extern bool rtl_string_unittest_const_literal_function;
51#endif
52
53// The unittest uses slightly different code to help check that the proper
54// calls are made. The class is put into a different namespace to make
55// sure the compiler generates a different (if generating also non-inline)
56// copy of the function and does not merge them together. The class
57// is "brought" into the proper rtl namespace by a typedef below.
58#ifdef RTL_STRING_UNITTEST
59#define rtl rtlunittest
60#endif
61
62namespace rtl
63{
64
66#ifdef RTL_STRING_UNITTEST
67#undef rtl
68// helper macro to make functions appear more readable
69#define RTL_STRING_CONST_FUNCTION rtl_string_unittest_const_literal_function = true;
70#else
71#define RTL_STRING_CONST_FUNCTION
72#endif
74
75#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
82template<std::size_t N> class SAL_WARN_UNUSED OStringLiteral {
83 static_assert(N != 0);
84 static_assert(N - 1 <= std::numeric_limits<sal_Int32>::max(), "literal too long");
85
86public:
87#if HAVE_CPP_CONSTEVAL
88 consteval
89#else
90 constexpr
91#endif
92 explicit OStringLiteral(char const (&literal)[N]) {
93 assertLayout();
94 assert(literal[N - 1] == '\0');
95 //TODO: Use C++20 constexpr std::copy_n (P0202R3):
96 for (std::size_t i = 0; i != N; ++i) {
97 buffer[i] = literal[i];
98 }
99 }
100
101#if defined __cpp_char8_t
102#if HAVE_CPP_CONSTEVAL
103 consteval
104#else
105 constexpr
106#endif
107 explicit OStringLiteral(char8_t const (&literal)[N]) {
108 assertLayout();
109 assert(literal[N - 1] == '\0');
110 //TODO: Use C++20 constexpr std::copy_n (P0202R3):
111 for (std::size_t i = 0; i != N; ++i) {
112 buffer[i] = literal[i];
113 }
114 }
115#endif
116
117 constexpr sal_Int32 getLength() const { return length; }
118
119 constexpr char const * getStr() const SAL_RETURNS_NONNULL { return buffer; }
120
121private:
122 static constexpr void assertLayout() {
123 // These static_asserts verifying the layout compatibility with rtl_String cannot be class
124 // member declarations, as offsetof requires a complete type, so defer them to here:
125 static_assert(offsetof(OStringLiteral, refCount) == offsetof(rtl_String, refCount));
126 static_assert(
127 std::is_same_v<decltype(refCount), decltype(rtl_String::refCount)>);
128 static_assert(offsetof(OStringLiteral, length) == offsetof(rtl_String, length));
129 static_assert(std::is_same_v<decltype(length), decltype(rtl_String::length)>);
130 static_assert(offsetof(OStringLiteral, buffer) == offsetof(rtl_String, buffer));
131 static_assert(
132 std::is_same_v<
133 std::remove_extent_t<decltype(buffer)>,
134 std::remove_extent_t<decltype(rtl_String::buffer)>>);
135 }
136
137 // Same layout as rtl_String (include/rtl/string.h):
138 oslInterlockedCount refCount = 0x40000000; // SAL_STRING_STATIC_FLAG (sal/rtl/strimp.hxx)
139 sal_Int32 length = N - 1;
140 char buffer[N] = {}; //TODO: drop initialization for C++20 (P1331R2)
141};
142#endif
143
144/* ======================================================================= */
145
170class SAL_WARN_UNUSED SAL_DLLPUBLIC_RTTI OString
171{
172public:
174 rtl_String * pData;
176
181 {
182 pData = NULL;
183 rtl_string_new( &pData );
184 }
185
191 OString( const OString & str )
192 {
193 pData = str.pData;
194 rtl_string_acquire( pData );
195 }
196
197#if defined LIBO_INTERNAL_ONLY
204 OString( OString && str ) noexcept
205 {
206 pData = str.pData;
207 str.pData = nullptr;
208 rtl_string_new( &str.pData );
209 }
210#endif
211
217 OString( rtl_String * str )
218 {
219 pData = str;
220 rtl_string_acquire( pData );
221 }
222
230 OString( rtl_String * str, __sal_NoAcquire )
231 {
232 pData = str;
233 }
234
240 explicit OString( char value )
241 : pData (NULL)
242 {
243 rtl_string_newFromStr_WithLength( &pData, &value, 1 );
244 }
245
254 template< typename T >
256 {
257 pData = NULL;
258 rtl_string_newFromStr( &pData, value );
259 }
260
261 template< typename T >
263 {
264 pData = NULL;
265 rtl_string_newFromStr( &pData, value );
266 }
267
278 template< typename T >
280 {
281 assert(
283 pData = NULL;
285 rtl_string_new(&pData);
286 } else {
288 &pData,
290 literal),
292 }
293#ifdef RTL_STRING_UNITTEST
294 rtl_string_unittest_const_literal = true;
295#endif
296 }
297
306 OString( const char * value, sal_Int32 length )
307 {
308 pData = NULL;
309 rtl_string_newFromStr_WithLength( &pData, value, length );
310 }
311
312#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
314
319 template<std::size_t N> OString(OStringLiteral<N> const & literal):
320 pData(const_cast<rtl_String *>(reinterpret_cast<rtl_String const *>(&literal))) {}
321 template<std::size_t N> OString(OStringLiteral<N> &&) = delete;
323#endif
324
325#if defined LIBO_INTERNAL_ONLY
326 OString(std::string_view sv) {
327 if (sv.size() > sal_uInt32(std::numeric_limits<sal_Int32>::max())) {
328 throw std::bad_alloc();
329 }
330 pData = nullptr;
331 rtl_string_newFromStr_WithLength(&pData, sv.data(), sv.size());
332 }
333#endif
334
349 OString( const sal_Unicode * value, sal_Int32 length,
350 rtl_TextEncoding encoding,
351 sal_uInt32 convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS )
352 {
353 pData = NULL;
354 rtl_uString2String( &pData, value, length, encoding, convertFlags );
355 if (pData == NULL) {
356 throw std::bad_alloc();
357 }
358 }
359
360#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
365 template< typename T1, typename T2 >
366 OString( OStringConcat< T1, T2 >&& c )
367 {
368 const sal_Int32 l = c.length();
369 pData = rtl_string_alloc( l );
370 if (l != 0)
371 {
372 char* end = c.addData( pData->buffer );
373 pData->length = l;
374 *end = '\0';
375 }
376 }
377
382 template< typename T >
383 OString( OStringNumber< T >&& n )
384 : OString( n.buf, n.length )
385 {}
386#endif
387
388#ifdef LIBO_INTERNAL_ONLY
389 OString(std::nullptr_t) = delete;
390#endif
391
396 {
397 rtl_string_release( pData );
398 }
399
405 OString & operator=( const OString & str )
406 {
407 rtl_string_assign( &pData, str.pData );
408 return *this;
409 }
410
411#if defined LIBO_INTERNAL_ONLY
418 OString & operator=( OString && str ) noexcept
419 {
420 rtl_string_release( pData );
421 pData = str.pData;
422 str.pData = nullptr;
423 rtl_string_new( &str.pData );
424 return *this;
425 }
426#endif
427
433 template< typename T >
435 {
436 RTL_STRING_CONST_FUNCTION
437 assert(
440 rtl_string_new(&pData);
441 } else {
443 &pData,
445 literal),
447 }
448 return *this;
449 }
450
456 OString & operator+=( const OString & str )
457#if defined LIBO_INTERNAL_ONLY
458 &
459#endif
460 {
461 rtl_string_newConcat( &pData, pData, str.pData );
462 return *this;
463 }
464#if defined LIBO_INTERNAL_ONLY
465 void operator+=(OString const &) && = delete;
466#endif
467
468#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
473 template< typename T1, typename T2 >
474 OString& operator+=( OStringConcat< T1, T2 >&& c ) & {
475 sal_Int32 l = c.length();
476 if( l == 0 )
477 return *this;
478 l += pData->length;
479 rtl_string_ensureCapacity( &pData, l );
480 char* end = c.addData( pData->buffer + pData->length );
481 *end = '\0';
482 pData->length = l;
483 return *this;
484 }
485 template<typename T1, typename T2> void operator +=(
486 OStringConcat<T1, T2> &&) && = delete;
487
492 template< typename T >
493 OString& operator+=( OStringNumber< T >&& n ) & {
494 sal_Int32 l = n.length;
495 if( l == 0 )
496 return *this;
497 l += pData->length;
498 rtl_string_ensureCapacity( &pData, l );
499 char* end = addDataHelper( pData->buffer + pData->length, n.buf, n.length );
500 *end = '\0';
501 pData->length = l;
502 return *this;
503 }
504 template<typename T> void operator +=(
505 OStringNumber<T> &&) && = delete;
506#endif
507
512 void clear()
513 {
514 rtl_string_new( &pData );
515 }
516
525 sal_Int32 getLength() const { return pData->length; }
526
535 bool isEmpty() const
536 {
537 return pData->length == 0;
538 }
539
551 const char * getStr() const SAL_RETURNS_NONNULL { return pData->buffer; }
552
562 char operator [](sal_Int32 index) const {
563 // silence spurious -Werror=strict-overflow warnings from GCC 4.8.2
564 assert(index >= 0 && static_cast<sal_uInt32>(index) < static_cast<sal_uInt32>(getLength()));
565 return getStr()[index];
566 }
567
580 sal_Int32 compareTo( const OString & str ) const
581 {
582 return rtl_str_compare_WithLength( pData->buffer, pData->length,
583 str.pData->buffer, str.pData->length );
584 }
585
599 sal_Int32 compareTo( const OString & rObj, sal_Int32 maxLength ) const
600 {
601 return rtl_str_shortenedCompare_WithLength( pData->buffer, pData->length,
602 rObj.pData->buffer, rObj.pData->length, maxLength );
603 }
604
617 sal_Int32 reverseCompareTo( const OString & str ) const
618 {
619 return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
620 str.pData->buffer, str.pData->length );
621 }
622
634 bool equals( const OString & str ) const
635 {
636 if ( pData->length != str.pData->length )
637 return false;
638 if ( pData == str.pData )
639 return true;
640 return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
641 str.pData->buffer, str.pData->length ) == 0;
642 }
643
659 bool equalsL( const char* value, sal_Int32 length ) const
660 {
661 if ( pData->length != length )
662 return false;
663
664 return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
665 value, length ) == 0;
666 }
667
682 bool equalsIgnoreAsciiCase( const OString & str ) const
683 {
684 if ( pData->length != str.pData->length )
685 return false;
686 if ( pData == str.pData )
687 return true;
688 return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
689 str.pData->buffer, str.pData->length ) == 0;
690 }
691
713 template< typename T >
715 {
716 return rtl_str_compareIgnoreAsciiCase( pData->buffer, asciiStr ) == 0;
717 }
718
719 template< typename T >
721 {
722 return rtl_str_compareIgnoreAsciiCase( pData->buffer, asciiStr ) == 0;
723 }
724
730 template< typename T >
732 {
733 RTL_STRING_CONST_FUNCTION
734 assert(
736 return
737 (pData->length
740 pData->buffer, pData->length,
742 literal),
744 == 0);
745 }
746
766 bool equalsIgnoreAsciiCaseL( const char * asciiStr, sal_Int32 asciiStrLength ) const
767 {
768 if ( pData->length != asciiStrLength )
769 return false;
770
771 return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
772 asciiStr, asciiStrLength ) == 0;
773 }
774
790 bool match( const OString & str, sal_Int32 fromIndex = 0 ) const
791 {
792 return rtl_str_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
793 str.pData->buffer, str.pData->length, str.pData->length ) == 0;
794 }
795
801 template< typename T >
802 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type match( T& literal, sal_Int32 fromIndex = 0 ) const
803 {
804 RTL_STRING_CONST_FUNCTION
805 assert(
807 return
809 pData->buffer + fromIndex, pData->length - fromIndex,
811 literal),
814 == 0;
815 }
816
833 bool matchL(
834 char const * str, sal_Int32 strLength, sal_Int32 fromIndex = 0)
835 const
836 {
838 pData->buffer + fromIndex, pData->length - fromIndex,
839 str, strLength, strLength) == 0;
840 }
841
842 // This overload is left undefined, to detect calls of matchL that
843 // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
844 // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
845 // platforms):
846#if SAL_TYPES_SIZEOFLONG == 8
847 void matchL(char const *, sal_Int32, rtl_TextEncoding) const;
848#endif
849
868 bool matchIgnoreAsciiCase( const OString & str, sal_Int32 fromIndex = 0 ) const
869 {
870 return rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
871 str.pData->buffer, str.pData->length,
872 str.pData->length ) == 0;
873 }
874
880 template< typename T >
882 {
883 RTL_STRING_CONST_FUNCTION
884 assert(
886 return
888 pData->buffer+fromIndex, pData->length-fromIndex,
890 literal),
893 == 0;
894 }
895
910 bool startsWith(OString const & str, OString * rest = NULL) const {
911 bool b = match(str);
912 if (b && rest != NULL) {
913 *rest = copy(str.getLength());
914 }
915 return b;
916 }
917
923 template< typename T >
925 T & literal, OString * rest = NULL) const
926 {
927 RTL_STRING_CONST_FUNCTION
928 bool b = match(literal, 0);
929 if (b && rest != NULL) {
930 *rest = copy(
932 }
933 return b;
934 }
935
955 bool startsWithIgnoreAsciiCase(OString const & str, OString * rest = NULL)
956 const
957 {
958 bool b = matchIgnoreAsciiCase(str);
959 if (b && rest != NULL) {
960 *rest = copy(str.getLength());
961 }
962 return b;
963 }
964
970 template< typename T >
972 startsWithIgnoreAsciiCase(T & literal, OString * rest = NULL) const
973 {
974 RTL_STRING_CONST_FUNCTION
975 assert(
977 bool b = matchIgnoreAsciiCase(literal);
978 if (b && rest != NULL) {
979 *rest = copy(
981 }
982 return b;
983 }
984
999 bool endsWith(OString const & str, OString * rest = NULL) const {
1000 bool b = str.getLength() <= getLength()
1001 && match(str, getLength() - str.getLength());
1002 if (b && rest != NULL) {
1003 *rest = copy(0, getLength() - str.getLength());
1004 }
1005 return b;
1006 }
1007
1013 template< typename T >
1015 T & literal, OString * rest = NULL) const
1016 {
1017 RTL_STRING_CONST_FUNCTION
1018 assert(
1020 bool b
1022 <= sal_uInt32(getLength()))
1023 && match(
1025 literal),
1026 (getLength()
1028 if (b && rest != NULL) {
1029 *rest = copy(
1030 0,
1031 (getLength()
1033 }
1034 return b;
1035 }
1036
1050 bool endsWithL(char const * str, sal_Int32 strLength) const {
1051 return strLength <= getLength()
1052 && matchL(str, strLength, getLength() - strLength);
1053 }
1054
1055 friend bool operator == ( const OString& rStr1, const OString& rStr2 )
1056 { return rStr1.equals(rStr2); }
1057 friend bool operator != ( const OString& rStr1, const OString& rStr2 )
1058 { return !(operator == ( rStr1, rStr2 )); }
1059 friend bool operator < ( const OString& rStr1, const OString& rStr2 )
1060 { return rStr1.compareTo( rStr2 ) < 0; }
1061 friend bool operator > ( const OString& rStr1, const OString& rStr2 )
1062 { return rStr1.compareTo( rStr2 ) > 0; }
1063 friend bool operator <= ( const OString& rStr1, const OString& rStr2 )
1064 { return rStr1.compareTo( rStr2 ) <= 0; }
1065 friend bool operator >= ( const OString& rStr1, const OString& rStr2 )
1066 { return rStr1.compareTo( rStr2 ) >= 0; }
1067
1068 template< typename T >
1069 friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator==( const OString& rStr1, const T& value )
1070 {
1071 return rStr1.compareTo( value ) == 0;
1072 }
1073
1074 template< typename T >
1076 {
1077 return rStr1.compareTo( value ) == 0;
1078 }
1079
1080 template< typename T >
1081 friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator==( const T& value, const OString& rStr2 )
1082 {
1083 return rStr2.compareTo( value ) == 0;
1084 }
1085
1086 template< typename T >
1088 {
1089 return rStr2.compareTo( value ) == 0;
1090 }
1091
1097 template< typename T >
1099 {
1100 RTL_STRING_CONST_FUNCTION
1101 assert(
1103 return
1104 (rStr.getLength()
1107 rStr.pData->buffer, rStr.pData->length,
1109 literal),
1111 == 0);
1112 }
1113
1119 template< typename T >
1121 {
1122 RTL_STRING_CONST_FUNCTION
1123 assert(
1125 return
1126 (rStr.getLength()
1129 rStr.pData->buffer, rStr.pData->length,
1131 literal),
1133 == 0);
1134 }
1135
1136 template< typename T >
1137 friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=( const OString& rStr1, const T& value )
1138 {
1139 return !(operator == ( rStr1, value ));
1140 }
1141
1142 template< typename T >
1144 {
1145 return !(operator == ( rStr1, value ));
1146 }
1147
1148 template< typename T >
1149 friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=( const T& value, const OString& rStr2 )
1150 {
1151 return !(operator == ( value, rStr2 ));
1152 }
1153
1154 template< typename T >
1156 {
1157 return !(operator == ( value, rStr2 ));
1158 }
1159
1165 template< typename T >
1167 {
1168 return !( rStr == literal );
1169 }
1170
1176 template< typename T >
1178 {
1179 return !( literal == rStr );
1180 }
1181
1189 sal_Int32 hashCode() const
1190 {
1191 return rtl_str_hashCode_WithLength( pData->buffer, pData->length );
1192 }
1193
1207 sal_Int32 indexOf( char ch, sal_Int32 fromIndex = 0 ) const
1208 {
1209 sal_Int32 ret = rtl_str_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
1210 return (ret < 0 ? ret : ret+fromIndex);
1211 }
1212
1222 sal_Int32 lastIndexOf( char ch ) const
1223 {
1224 return rtl_str_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
1225 }
1226
1239 sal_Int32 lastIndexOf( char ch, sal_Int32 fromIndex ) const
1240 {
1241 return rtl_str_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
1242 }
1243
1259 sal_Int32 indexOf( const OString & str, sal_Int32 fromIndex = 0 ) const
1260 {
1261 sal_Int32 ret = rtl_str_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1262 str.pData->buffer, str.pData->length );
1263 return (ret < 0 ? ret : ret+fromIndex);
1264 }
1265
1271 template< typename T >
1272 typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const
1273 {
1274 RTL_STRING_CONST_FUNCTION
1275 assert(
1277 sal_Int32 n = rtl_str_indexOfStr_WithLength(
1278 pData->buffer + fromIndex, pData->length - fromIndex,
1281 return n < 0 ? n : n + fromIndex;
1282 }
1283
1302 sal_Int32 indexOfL(char const * str, sal_Int32 len, sal_Int32 fromIndex = 0)
1303 const
1304 {
1305 sal_Int32 n = rtl_str_indexOfStr_WithLength(
1306 pData->buffer + fromIndex, pData->length - fromIndex, str, len);
1307 return n < 0 ? n : n + fromIndex;
1308 }
1309
1310 // This overload is left undefined, to detect calls of indexOfL that
1311 // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
1312 // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
1313 // platforms):
1314#if SAL_TYPES_SIZEOFLONG == 8
1315 void indexOfL(char const *, sal_Int32, rtl_TextEncoding) const;
1316#endif
1317
1333 sal_Int32 lastIndexOf( const OString & str ) const
1334 {
1335 return rtl_str_lastIndexOfStr_WithLength( pData->buffer, pData->length,
1336 str.pData->buffer, str.pData->length );
1337 }
1338
1356 sal_Int32 lastIndexOf( const OString & str, sal_Int32 fromIndex ) const
1357 {
1358 return rtl_str_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
1359 str.pData->buffer, str.pData->length );
1360 }
1361
1372 SAL_WARN_UNUSED_RESULT OString copy( sal_Int32 beginIndex ) const
1373 {
1374 return copy(beginIndex, getLength() - beginIndex);
1375 }
1376
1389 SAL_WARN_UNUSED_RESULT OString copy( sal_Int32 beginIndex, sal_Int32 count ) const
1390 {
1391 rtl_String *pNew = NULL;
1392 rtl_string_newFromSubString( &pNew, pData, beginIndex, count );
1393 return OString( pNew, SAL_NO_ACQUIRE );
1394 }
1395
1396#if defined LIBO_INTERNAL_ONLY
1407 SAL_WARN_UNUSED_RESULT std::string_view subView( sal_Int32 beginIndex ) const
1408 {
1409 assert(beginIndex >= 0);
1410 assert(beginIndex <= getLength());
1411 return subView(beginIndex, getLength() - beginIndex);
1412 }
1413
1426 SAL_WARN_UNUSED_RESULT std::string_view subView( sal_Int32 beginIndex, sal_Int32 count ) const
1427 {
1428 assert(beginIndex >= 0);
1429 assert(count >= 0);
1430 assert(beginIndex <= getLength());
1431 assert(count <= getLength() - beginIndex);
1432 return std::string_view(*this).substr(beginIndex, count);
1433 }
1434#endif
1435
1436#ifndef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
1445 SAL_WARN_UNUSED_RESULT OString concat( const OString & str ) const
1446 {
1447 rtl_String* pNew = NULL;
1448 rtl_string_newConcat( &pNew, pData, str.pData );
1449 return OString( pNew, SAL_NO_ACQUIRE );
1450 }
1451#endif
1452
1453#ifndef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
1454 friend OString operator+( const OString & str1, const OString & str2 )
1455 {
1456 return str1.concat( str2 );
1457 }
1458#endif
1459
1473 SAL_WARN_UNUSED_RESULT OString replaceAt( sal_Int32 index, sal_Int32 count, const OString& newStr ) const
1474 {
1475 rtl_String* pNew = NULL;
1476 rtl_string_newReplaceStrAt( &pNew, pData, index, count, newStr.pData );
1477 return OString( pNew, SAL_NO_ACQUIRE );
1478 }
1479
1493 SAL_WARN_UNUSED_RESULT OString replace( char oldChar, char newChar ) const
1494 {
1495 rtl_String* pNew = NULL;
1496 rtl_string_newReplace( &pNew, pData, oldChar, newChar );
1497 return OString( pNew, SAL_NO_ACQUIRE );
1498 }
1499
1519 OString const & from, OString const & to, sal_Int32 * index = NULL) const
1520 {
1521 rtl_String * s = NULL;
1522 sal_Int32 i = 0;
1524 &s, pData, from.pData->buffer, from.pData->length,
1525 to.pData->buffer, to.pData->length, index == NULL ? &i : index);
1526 return OString(s, SAL_NO_ACQUIRE);
1527 }
1528
1542 SAL_WARN_UNUSED_RESULT OString replaceAll(OString const & from, OString const & to) const {
1543 rtl_String * s = NULL;
1545 &s, pData, from.pData->buffer, from.pData->length,
1546 to.pData->buffer, to.pData->length);
1547 return OString(s, SAL_NO_ACQUIRE);
1548 }
1549
1561 {
1562 rtl_String* pNew = NULL;
1563 rtl_string_newToAsciiLowerCase( &pNew, pData );
1564 return OString( pNew, SAL_NO_ACQUIRE );
1565 }
1566
1578 {
1579 rtl_String* pNew = NULL;
1580 rtl_string_newToAsciiUpperCase( &pNew, pData );
1581 return OString( pNew, SAL_NO_ACQUIRE );
1582 }
1583
1596 {
1597 rtl_String* pNew = NULL;
1598 rtl_string_newTrim( &pNew, pData );
1599 return OString( pNew, SAL_NO_ACQUIRE );
1600 }
1601
1626 OString getToken( sal_Int32 token, char cTok, sal_Int32& index ) const
1627 {
1628 rtl_String * pNew = NULL;
1629 index = rtl_string_getToken( &pNew, pData, token, cTok, index );
1630 return OString( pNew, SAL_NO_ACQUIRE );
1631 }
1632
1646 OString getToken(sal_Int32 count, char separator) const {
1647 sal_Int32 n = 0;
1648 return getToken(count, separator, n);
1649 }
1650
1659 bool toBoolean() const
1660 {
1661 return rtl_str_toBoolean( pData->buffer );
1662 }
1663
1670 char toChar() const
1671 {
1672 return pData->buffer[0];
1673 }
1674
1685 sal_Int32 toInt32( sal_Int16 radix = 10 ) const
1686 {
1687 return rtl_str_toInt32( pData->buffer, radix );
1688 }
1689
1702 sal_uInt32 toUInt32( sal_Int16 radix = 10 ) const
1703 {
1704 return rtl_str_toUInt32( pData->buffer, radix );
1705 }
1706
1717 sal_Int64 toInt64( sal_Int16 radix = 10 ) const
1718 {
1719 return rtl_str_toInt64( pData->buffer, radix );
1720 }
1721
1734 sal_uInt64 toUInt64( sal_Int16 radix = 10 ) const
1735 {
1736 return rtl_str_toUInt64( pData->buffer, radix );
1737 }
1738
1747 float toFloat() const
1748 {
1749 return rtl_str_toFloat( pData->buffer );
1750 }
1751
1760 double toDouble() const
1761 {
1762 return rtl_str_toDouble( pData->buffer );
1763 }
1764
1765#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
1766
1767 static OStringNumber< int > number( int i, sal_Int16 radix = 10 )
1768 {
1769 return OStringNumber< int >( i, radix );
1770 }
1771 static OStringNumber< long long > number( long long ll, sal_Int16 radix = 10 )
1772 {
1773 return OStringNumber< long long >( ll, radix );
1774 }
1775 static OStringNumber< unsigned long long > number( unsigned long long ll, sal_Int16 radix = 10 )
1776 {
1777 return OStringNumber< unsigned long long >( ll, radix );
1778 }
1779 static OStringNumber< unsigned long long > number( unsigned int i, sal_Int16 radix = 10 )
1780 {
1781 return number( static_cast< unsigned long long >( i ), radix );
1782 }
1783 static OStringNumber< long long > number( long i, sal_Int16 radix = 10)
1784 {
1785 return number( static_cast< long long >( i ), radix );
1786 }
1787 static OStringNumber< unsigned long long > number( unsigned long i, sal_Int16 radix = 10 )
1788 {
1789 return number( static_cast< unsigned long long >( i ), radix );
1790 }
1791 static OStringNumber< float > number( float f )
1792 {
1793 return OStringNumber< float >( f );
1794 }
1795 static OStringNumber< double > number( double d )
1796 {
1797 return OStringNumber< double >( d );
1798 }
1799#else
1810 static OString number( int i, sal_Int16 radix = 10 )
1811 {
1812 char aBuf[RTL_STR_MAX_VALUEOFINT32];
1813 return OString(aBuf, rtl_str_valueOfInt32(aBuf, i, radix));
1814 }
1817 static OString number( unsigned int i, sal_Int16 radix = 10 )
1818 {
1819 return number( static_cast< unsigned long long >( i ), radix );
1820 }
1823 static OString number( long i, sal_Int16 radix = 10 )
1824 {
1825 return number( static_cast< long long >( i ), radix );
1826 }
1829 static OString number( unsigned long i, sal_Int16 radix = 10 )
1830 {
1831 return number( static_cast< unsigned long long >( i ), radix );
1832 }
1835 static OString number( long long ll, sal_Int16 radix = 10 )
1836 {
1837 char aBuf[RTL_STR_MAX_VALUEOFINT64];
1838 return OString(aBuf, rtl_str_valueOfInt64(aBuf, ll, radix));
1839 }
1842 static OString number( unsigned long long ll, sal_Int16 radix = 10 )
1843 {
1844 char aBuf[RTL_STR_MAX_VALUEOFUINT64];
1845 return OString(aBuf, rtl_str_valueOfUInt64(aBuf, ll, radix));
1846 }
1847
1857 static OString number( float f )
1858 {
1859 char aBuf[RTL_STR_MAX_VALUEOFFLOAT];
1860 return OString(aBuf, rtl_str_valueOfFloat(aBuf, f));
1861 }
1862
1872 static OString number( double d )
1873 {
1874 char aBuf[RTL_STR_MAX_VALUEOFDOUBLE];
1875 return OString(aBuf, rtl_str_valueOfDouble(aBuf, d));
1876 }
1877#endif
1878
1890 SAL_DEPRECATED("use boolean()") static OString valueOf( sal_Bool b )
1891 {
1892 return boolean(b);
1893 }
1894
1906 static OString boolean( bool b )
1907 {
1908 char aBuf[RTL_STR_MAX_VALUEOFBOOLEAN];
1909 return OString(aBuf, rtl_str_valueOfBoolean(aBuf, b));
1910 }
1911
1919 SAL_DEPRECATED("convert to OString or use directly") static OString valueOf( char c )
1920 {
1921 return OString( &c, 1 );
1922 }
1923
1934 SAL_DEPRECATED("use number()") static OString valueOf( sal_Int32 i, sal_Int16 radix = 10 )
1935 {
1936 return number( i, radix );
1937 }
1938
1949 SAL_DEPRECATED("use number()") static OString valueOf( sal_Int64 ll, sal_Int16 radix = 10 )
1950 {
1951 return number( ll, radix );
1952 }
1953
1963 SAL_DEPRECATED("use number()") static OString valueOf( float f )
1964 {
1965 return number(f);
1966 }
1967
1977 SAL_DEPRECATED("use number()") static OString valueOf( double d )
1978 {
1979 return number(d);
1980 }
1981
1982#if defined LIBO_INTERNAL_ONLY
1983 operator std::string_view() const { return {getStr(), sal_uInt32(getLength())}; }
1984#endif
1985
1986#if defined LIBO_INTERNAL_ONLY
1987 // A wrapper for the first expression in an
1988 //
1989 // OString::Concat(e1) + e2 + ...
1990 //
1991 // concatenation chain, when neither of the first two e1, e2 is one of our rtl string-related
1992 // classes (so something like
1993 //
1994 // OString s = "a" + (b ? std::string_view("c") : std::string_view("dd"));
1995 //
1996 // would not compile):
1997 template<typename T> [[nodiscard]] static
1998 typename std::enable_if_t<
1999 ToStringHelper<T>::allowOStringConcat, OStringConcat<OStringConcatMarker, T>>
2000 Concat(T const & value) { return OStringConcat<OStringConcatMarker, T>({}, value); }
2001
2002 // This overload is needed so that an argument of type 'char const[N]' ends up as
2003 // 'OStringConcat<rtl::OStringConcatMarker, char const[N]>' rather than as
2004 // 'OStringConcat<rtl::OStringConcatMarker, char[N]>':
2005 template<typename T, std::size_t N> [[nodiscard]] static
2006 typename std::enable_if_t<
2007 ToStringHelper<T[N]>::allowOStringConcat, OStringConcat<OStringConcatMarker, T[N]>>
2008 Concat(T (& value)[N]) { return OStringConcat<OStringConcatMarker, T[N]>({}, value); }
2009#endif
2010};
2011
2012/* ======================================================================= */
2013
2014#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2015
2019template<>
2020struct ToStringHelper< OString >
2021 {
2022 static std::size_t length( const OString& s ) { return s.getLength(); }
2023 static char* addData( char* buffer, const OString& s ) { return addDataHelper( buffer, s.getStr(), s.getLength()); }
2024 static const bool allowOStringConcat = true;
2025 static const bool allowOUStringConcat = false;
2026 };
2027
2031template<std::size_t N>
2032struct ToStringHelper< OStringLiteral<N> >
2033 {
2034 static constexpr std::size_t length( const OStringLiteral<N>& str ) { return str.getLength(); }
2035 static char* addData( char* buffer, const OStringLiteral<N>& str ) { return addDataHelper( buffer, str.getStr(), str.getLength() ); }
2036 static const bool allowOStringConcat = true;
2037 static const bool allowOUStringConcat = false;
2038 };
2039
2043template< typename charT, typename traits, typename T1, typename T2 >
2044inline std::basic_ostream<charT, traits> & operator <<(
2045 std::basic_ostream<charT, traits> & stream, OStringConcat< T1, T2 >&& concat)
2046{
2047 return stream << OString( std::move(concat) );
2048}
2049#endif
2050
2051
2058{
2068 size_t operator()( const OString& rString ) const
2069 { return static_cast<size_t>(rString.hashCode()); }
2070};
2071
2074{
2075 bool operator()( const char* p1, const char* p2) const
2076 { return rtl_str_compare(p1, p2) == 0; }
2077};
2078
2081{
2082 size_t operator()(const char* p) const
2083 { return rtl_str_hashCode(p); }
2084};
2085
2086/* ======================================================================= */
2087
2094template< typename charT, typename traits > std::basic_ostream<charT, traits> &
2096 std::basic_ostream<charT, traits> & stream, OString const & rString)
2097{
2098 return stream << rString.getStr();
2099 // best effort; potentially loses data due to embedded null characters
2100}
2101
2102} /* Namespace */
2103
2104#ifdef RTL_STRING_UNITTEST
2105namespace rtl
2106{
2107typedef rtlunittest::OString OString;
2108}
2109#undef RTL_STRING_CONST_FUNCTION
2110#endif
2111
2112#if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
2113using ::rtl::OString;
2114using ::rtl::OStringChar;
2115using ::rtl::OStringHash;
2116using ::rtl::OStringLiteral;
2117#endif
2118
2120
2125#if defined LIBO_INTERNAL_ONLY
2126namespace std {
2127
2128template<>
2129struct hash<::rtl::OString>
2130{
2131 std::size_t operator()(::rtl::OString const & s) const
2132 { return std::size_t(s.hashCode()); }
2133};
2134
2135}
2136
2137#endif
2139
2140#endif // INCLUDED_RTL_STRING_HXX
2141
2142/* 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:445
__sal_NoAcquire
Definition: types.h:349
@ SAL_NO_ACQUIRE
definition of a no acquire enum for ctors
Definition: types.h:352
unsigned char sal_Bool
Definition: types.h:34
sal_uInt16 sal_Unicode
Definition: types.h:119
#define SAL_WARN_UNUSED_RESULT
Use this as markup for functions and methods whose return value must be checked.
Definition: types.h:280
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:558
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:711
#define RTL_STR_MAX_VALUEOFINT32
Definition: string.h:627
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:1350
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:585
#define RTL_STR_MAX_VALUEOFFLOAT
Definition: string.h:692
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.
#define RTL_STR_MAX_VALUEOFUINT64
Definition: string.h:673
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:650
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:33
sal_Int32 oslInterlockedCount
Definition: interlck.h:40
bool operator!=(const Any &rAny, const C &value)
Template inequality operator: compares set value of left side any to right side value.
Definition: Any.hxx:664
Definition: unotype.hxx:43
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:2095
bool operator<(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:90
bool operator>(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:100
bool operator==(const TTimeValue &rTimeA, const TTimeValue &rTimeB)
Definition: timer.hxx:110
This String class provide base functionality for C++ like 8-Bit character array handling.
Definition: string.hxx:171
SAL_WARN_UNUSED_RESULT OString concat(const OString &str) const
Concatenates the specified string to the end of this string.
Definition: string.hxx:1445
OString(T &literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type=libreoffice_internal::Dummy())
New string from a string literal.
Definition: string.hxx:279
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:349
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:1014
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:1829
bool startsWith(OString const &str, OString *rest=NULL) const
Check whether this string starts with a given substring.
Definition: string.hxx:910
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:1098
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:924
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:1120
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:1272
OString(const char *value, sal_Int32 length)
New string from a character buffer array.
Definition: string.hxx:306
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:1842
static OString number(int i, sal_Int16 radix=10)
Returns the string representation of the integer argument.
Definition: string.hxx:1810
sal_uInt64 toUInt64(sal_Int16 radix=10) const
Returns the uint64 value from this string.
Definition: string.hxx:1734
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:1302
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:434
sal_Int32 compareTo(const OString &str) const
Compares two strings.
Definition: string.hxx:580
OString & operator+=(const OString &str)
Append a string to this string.
Definition: string.hxx:456
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:731
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:1577
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:972
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:1177
char toChar() const
Returns the first character from this string.
Definition: string.hxx:1670
bool toBoolean() const
Returns the Boolean value from this string.
Definition: string.hxx:1659
friend OString operator+(const OString &str1, const OString &str2)
Definition: string.hxx:1454
SAL_WARN_UNUSED_RESULT OString copy(sal_Int32 beginIndex) const
Returns a new string that is a substring of this string.
Definition: string.hxx:1372
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator!=(const OString &rStr1, T &value)
Definition: string.hxx:1143
OString(rtl_String *str)
New string from OString data.
Definition: string.hxx:217
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:955
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:1835
sal_Int32 lastIndexOf(const OString &str) const
Returns the index within this string of the last occurrence of the specified substring,...
Definition: string.hxx:1333
void clear()
Clears the string, i.e, makes a zero-character string.
Definition: string.hxx:512
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:1518
OString getToken(sal_Int32 count, char separator) const
Returns a token from the string.
Definition: string.hxx:1646
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:1817
const char * getStr() const SAL_RETURNS_NONNULL
Returns a pointer to the characters of this string.
Definition: string.hxx:551
OString & operator=(const OString &str)
Assign a new string.
Definition: string.hxx:405
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:881
sal_Int32 compareTo(const OString &rObj, sal_Int32 maxLength) const
Compares two strings with an maximum count of characters.
Definition: string.hxx:599
bool isEmpty() const
Checks if a string is empty.
Definition: string.hxx:535
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator==(T &value, const OString &rStr2)
Definition: string.hxx:1087
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:255
OString getToken(sal_Int32 token, char cTok, sal_Int32 &index) const
Returns a token in the string.
Definition: string.hxx:1626
sal_Int32 reverseCompareTo(const OString &str) const
Compares two strings in reverse order.
Definition: string.hxx:617
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:1356
sal_Int32 lastIndexOf(char ch) const
Returns the index within this string of the last occurrence of the specified character,...
Definition: string.hxx:1222
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:1389
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=(const OString &rStr1, const T &value)
Definition: string.hxx:1137
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:1493
sal_Int32 hashCode() const
Returns a hashcode for this string.
Definition: string.hxx:1189
static OString boolean(bool b)
Returns the string representation of the boolean argument.
Definition: string.hxx:1906
bool matchL(char const *str, sal_Int32 strLength, sal_Int32 fromIndex=0) const
Match against a substring appearing in this string.
Definition: string.hxx:833
bool equalsL(const char *value, sal_Int32 length) const
Perform a comparison of two strings.
Definition: string.hxx:659
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:1595
OString(const OString &str)
New string from OString.
Definition: string.hxx:191
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:1542
bool endsWithL(char const *str, sal_Int32 strLength) const
Check whether this string ends with a given substring.
Definition: string.hxx:1050
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:1560
bool match(const OString &str, sal_Int32 fromIndex=0) const
Match against a substring appearing in this string.
Definition: string.hxx:790
float toFloat() const
Returns the float value from this string.
Definition: string.hxx:1747
OString()
New string containing no characters.
Definition: string.hxx:180
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:802
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator==(const T &value, const OString &rStr2)
Definition: string.hxx:1081
OString(char value)
New string from a single character.
Definition: string.hxx:240
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:1823
bool equalsIgnoreAsciiCase(const OString &str) const
Perform an ASCII lowercase comparison of two strings.
Definition: string.hxx:682
sal_Int64 toInt64(sal_Int16 radix=10) const
Returns the int64 value from this string.
Definition: string.hxx:1717
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:1259
sal_Int32 toInt32(sal_Int16 radix=10) const
Returns the int32 value from this string.
Definition: string.hxx:1685
~OString()
Release the string data.
Definition: string.hxx:395
libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type equalsIgnoreAsciiCase(T &asciiStr) const
Definition: string.hxx:720
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:1166
libreoffice_internal::CharPtrDetector< T, bool >::Type equalsIgnoreAsciiCase(const T &asciiStr) const
Perform an ASCII lowercase comparison of two strings.
Definition: string.hxx:714
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:1207
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:1473
sal_Int32 getLength() const
Returns the length of this string.
Definition: string.hxx:525
double toDouble() const
Returns the double value from this string.
Definition: string.hxx:1760
static OString number(double d)
Returns the string representation of the double argument.
Definition: string.hxx:1872
bool endsWith(OString const &str, OString *rest=NULL) const
Check whether this string ends with a given substring.
Definition: string.hxx:999
bool equals(const OString &str) const
Perform a comparison of two strings.
Definition: string.hxx:634
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator==(const OString &rStr1, T &value)
Definition: string.hxx:1075
OString(rtl_String *str, __sal_NoAcquire)
New string from OString data without acquiring it.
Definition: string.hxx:230
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:1239
OString(T &value, typename libreoffice_internal::NonConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type=libreoffice_internal::Dummy())
Definition: string.hxx:262
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator==(const OString &rStr1, const T &value)
Definition: string.hxx:1069
sal_uInt32 toUInt32(sal_Int16 radix=10) const
Returns the uint32 value from this string.
Definition: string.hxx:1702
static OString number(float f)
Returns the string representation of the float argument.
Definition: string.hxx:1857
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=(const T &value, const OString &rStr2)
Definition: string.hxx:1149
bool equalsIgnoreAsciiCaseL(const char *asciiStr, sal_Int32 asciiStrLength) const
Perform an ASCII lowercase comparison of two strings.
Definition: string.hxx:766
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:868
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator!=(T &value, const OString &rStr2)
Definition: string.hxx:1155
A helper to use OStrings with hash maps.
Definition: string.hxx:2058
size_t operator()(const OString &rString) const
Compute a hash code for a string.
Definition: string.hxx:2068
Equality functor for classic c-strings (i.e., null-terminated char* strings).
Definition: string.hxx:2074
bool operator()(const char *p1, const char *p2) const
Definition: string.hxx:2075
Hashing functor for classic c-strings (i.e., null-terminated char* strings).
Definition: string.hxx:2081
size_t operator()(const char *p) const
Definition: string.hxx:2082
Definition: stringutils.hxx:131
Definition: stringutils.hxx:134