LibreOffice: rtl/string.hxx Source File

LibreOffice LibreOffice 26.2 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 <algorithm>
40#include <string_view>
41#include <type_traits>
42#endif
43
44#include "rtl/math.h"
45#include "rtl/textenc.h"
46#include "rtl/string.h"
47#include "rtl/stringutils.hxx"
48
49#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
50#include "config_global.h"
51#include "rtl/stringconcat.hxx"
52#endif
53
54#ifdef RTL_STRING_UNITTEST
55extern bool rtl_string_unittest_const_literal;
56extern bool rtl_string_unittest_const_literal_function;
57#endif
58
59// The unittest uses slightly different code to help check that the proper
60// calls are made. The class is put into a different namespace to make
61// sure the compiler generates a different (if generating also non-inline)
62// copy of the function and does not merge them together. The class
63// is "brought" into the proper rtl namespace by a typedef below.
64#ifdef RTL_STRING_UNITTEST
65#define rtl rtlunittest
66#endif
67
68namespace rtl
69{
70
72#ifdef RTL_STRING_UNITTEST
73#undef rtl
74// helper macro to make functions appear more readable
75#define RTL_STRING_CONST_FUNCTION rtl_string_unittest_const_literal_function = true;
76#else
77#define RTL_STRING_CONST_FUNCTION
78#endif
80
81#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
82
89template<std::size_t N> class SAL_WARN_UNUSED OStringLiteral {
90 static_assert(N != 0);
91 static_assert(N - 1 <= std::numeric_limits<sal_Int32>::max(), "literal too long");
92
93public:
94#if HAVE_CPP_CONSTEVAL
95 consteval
96#else
97 constexpr
98#endif
99 OStringLiteral(char const (&literal)[N]) {
100 assertLayout();
101 assert(literal[N - 1] == '\0');
102 std::copy_n(literal, N, more.buffer);
103 }
104
105#if !(defined _MSC_VER && _MSC_VER >= 1930 && _MSC_VER <= 1939 && defined _MANAGED)
106#if HAVE_CPP_CONSTEVAL
107 consteval
108#else
109 constexpr
110#endif
111 OStringLiteral(char8_t const (&literal)[N]) {
112 assertLayout();
113 assert(literal[N - 1] == '\0');
114 std::copy_n(literal, N, more.buffer);
115 }
116#endif
117
118 constexpr sal_Int32 getLength() const { return more.length; }
119
120 constexpr char const * getStr() const SAL_RETURNS_NONNULL { return more.buffer; }
121
122 constexpr operator std::string_view() const { return {more.buffer, sal_uInt32(more.length)}; }
123
124private:
125 static constexpr void assertLayout() {
126 // These static_asserts verifying the layout compatibility with rtl_String cannot be class
127 // member declarations, as offsetof requires a complete type, so defer them to here:
128 static_assert(std::is_standard_layout_v<OStringLiteral>);
129 static_assert(offsetof(OStringLiteral, str.refCount) == offsetof(OStringLiteral, more.refCount));
130 static_assert(offsetof(OStringLiteral, str.length) == offsetof(OStringLiteral, more.length));
131 static_assert(offsetof(OStringLiteral, str.buffer) == offsetof(OStringLiteral, more.buffer));
132 }
133
134 struct Data {
135 Data() = default;
136
137 oslInterlockedCount refCount = 0x40000000; // SAL_STRING_STATIC_FLAG (sal/rtl/strimp.hxx)
138 sal_Int32 length = N - 1;
139 char buffer[N];
140 };
141
142public:
143 // (Data members must be public so that OStringLiteral is a structural type that can be used as
144 // a non-type template parameter type for operator ""_ostr and rtl::detail::OStringHolder:)
145 union {
146 rtl_String str;
147 Data more = {};
148 };
149};
150
151#if !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
152
153namespace detail {
154
155template<OStringLiteral L> struct OStringHolder {
156 static constexpr auto & literal = L;
157};
158
159}
160
161#endif
162
163#endif
164
165/* ======================================================================= */
166
190
191// coverity[ missing_move_assignment : SUPPRESS] - don't report the suppressed move assignment
192 class SAL_WARN_UNUSED SAL_DLLPUBLIC_RTTI OString
193{
194public:
196 rtl_String * pData;
198
202#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
203 constexpr
204#endif
205 OString()
206 {
207#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
208 pData = const_cast<rtl_String *>(&empty.str);
209#else
210 pData = NULL;
211 rtl_string_new( &pData );
212#endif
213 }
214
220#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
221 constexpr
222#endif
223 OString( const OString & str )
224 {
225 pData = str.pData;
226#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
227 if (std::is_constant_evaluated()) {
228 //TODO: We would want to
229 //
230 // assert(SAL_STRING_IS_STATIC(pData));
231 //
232 // here, but that wouldn't work because read of member `str` of OUStringLiteral's
233 // anonymous union with active member `more` is not allowed in a constant expression.
234 } else
235#endif
236 rtl_string_acquire( pData );
237 }
238
239#if defined LIBO_INTERNAL_ONLY
240#if !defined(__COVERITY__) // suppress COPY_INSTEAD_OF_MOVE suggestions
247#if !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
248 constexpr
249#endif
250 OString( OString && str ) noexcept
251 {
252 pData = str.pData;
253#if !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
254 if (std::is_constant_evaluated()) {
255 //TODO: We would want to
256 //
257 // assert(SAL_STRING_IS_STATIC(pData));
258 //
259 // here, but that wouldn't work because read of member `str` of OUStringLiteral's
260 // anonymous union with active member `more` is not allowed in a constant expression.
261 return;
262 }
263#endif
264 str.pData = nullptr;
265 rtl_string_new( &str.pData );
266 }
267#endif
268#endif
269
275 OString( rtl_String * str )
276 {
277 pData = str;
278 rtl_string_acquire( pData );
279 }
280
288 OString( rtl_String * str, __sal_NoAcquire )
289 {
290 pData = str;
291 }
292
298 explicit OString( char value )
299 : pData (NULL)
300 {
301 rtl_string_newFromStr_WithLength( &pData, &value, 1 );
302 }
303
304#if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST_CONCAT
305 // Catch inadvertent conversions to the above ctor (e.g., from sal_[u]Int8, aka [un]signed
306 // char):
307 OString(int) = delete;
308#endif
309
318 template< typename T >
319 OString( const T& value, typename libreoffice_internal::CharPtrDetector< T, libreoffice_internal::Dummy >::Type = libreoffice_internal::Dummy() )
320 {
321 pData = NULL;
322 rtl_string_newFromStr( &pData, value );
323 }
324
325 template< typename T >
326 OString( T& value, typename libreoffice_internal::NonConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type = libreoffice_internal::Dummy() )
327 {
328 pData = NULL;
329 rtl_string_newFromStr( &pData, value );
330 }
331
332#if __cplusplus > 202002L // C++23 P2266R3 "Simpler implicit move"
333 template< typename T >
334 OString( T&& value, typename libreoffice_internal::NonConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type = libreoffice_internal::Dummy() )
335 {
336 pData = NULL;
337 rtl_string_newFromStr( &pData, value );
338 }
339#endif
340
351 template< typename T >
352 OString( T& literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type = libreoffice_internal::Dummy() )
353 {
354 assert(
355 libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
356 pData = NULL;
357 if (libreoffice_internal::ConstCharArrayDetector<T>::length == 0) {
358 rtl_string_new(&pData);
359 } else {
360 rtl_string_newFromLiteral(
361 &pData,
362 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
363 literal),
364 libreoffice_internal::ConstCharArrayDetector<T>::length, 0);
365 }
366#ifdef RTL_STRING_UNITTEST
367 rtl_string_unittest_const_literal = true;
368#endif
369 }
370
379 OString( const char * value, sal_Int32 length )
380 {
381 pData = NULL;
382 rtl_string_newFromStr_WithLength( &pData, value, length );
383 }
384
385#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
387
392 template<std::size_t N> constexpr OString(OStringLiteral<N> const & literal):
393 pData(const_cast<rtl_String *>(&literal.str)) {}
394 template<std::size_t N> OString(OStringLiteral<N> &&) = delete;
396#endif
397
398#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
399 // For operator ""_tstr:
400 template<OStringLiteral L> constexpr OString(detail::OStringHolder<L> const & holder):
401 pData(const_cast<rtl_String *>(&holder.literal.str)) {}
402#endif
403
404#if defined LIBO_INTERNAL_ONLY
405 explicit OString(std::string_view sv) {
406 if (sv.size() > sal_uInt32(std::numeric_limits<sal_Int32>::max())) {
407 throw std::bad_alloc();
408 }
409 pData = nullptr;
410 rtl_string_newFromStr_WithLength(&pData, sv.data(), sv.size());
411 }
412#endif
413
428 OString( const sal_Unicode * value, sal_Int32 length,
429 rtl_TextEncoding encoding,
430 sal_uInt32 convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS )
431 {
432 pData = NULL;
433 rtl_uString2String( &pData, value, length, encoding, convertFlags );
434 if (pData == NULL) {
435 throw std::bad_alloc();
436 }
437 }
438
439#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
444 template< typename T1, typename T2 >
445 OString( OStringConcat< T1, T2 >&& c )
446 {
447 const sal_Int32 l = c.length();
448 pData = rtl_string_alloc( l );
449 if (l != 0)
450 {
451 char* end = c.addData( pData->buffer );
452 pData->length = l;
453 *end = '\0';
454 }
455 }
456
461 template< std::size_t N >
462 OString( OStringNumber< N >&& n )
463 : OString( n.buf, n.length )
464 {}
465#endif
466
467#ifdef LIBO_INTERNAL_ONLY
468 OString(std::nullptr_t) = delete;
469#endif
470
474#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
475 constexpr
476#endif
477 ~OString()
478 {
479#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
480 if (std::is_constant_evaluated()) {
481 //TODO: We would want to
482 //
483 // assert(SAL_STRING_IS_STATIC(pData));
484 //
485 // here, but that wouldn't work because read of member `str` of OUStringLiteral's
486 // anonymous union with active member `more` is not allowed in a constant expression.
487 } else
488#endif
489 rtl_string_release( pData );
490 }
491
492#if defined LIBO_INTERNAL_ONLY
504 static OString const & unacquired( rtl_String * const * ppHandle )
505 { return * reinterpret_cast< OString const * >( ppHandle ); }
506#endif
507
513 OString & operator=( const OString & str )
514 {
515 rtl_string_assign( &pData, str.pData );
516 return *this;
517 }
518
519#if defined LIBO_INTERNAL_ONLY
520#if !defined(__COVERITY__) // suppress COPY_INSTEAD_OF_MOVE suggestions
527 OString & operator=( OString && str ) noexcept
528 {
529 rtl_string_release( pData );
530 pData = str.pData;
531 str.pData = nullptr;
532 rtl_string_new( &str.pData );
533 return *this;
534 }
535#endif
536#endif
537
543 template< typename T >
544 typename libreoffice_internal::ConstCharArrayDetector< T, OString& >::Type operator=( T& literal )
545 {
546 RTL_STRING_CONST_FUNCTION
547 assert(
548 libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
549 if (libreoffice_internal::ConstCharArrayDetector<T>::length == 0) {
550 rtl_string_new(&pData);
551 } else {
552 rtl_string_newFromLiteral(
553 &pData,
554 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
555 literal),
556 libreoffice_internal::ConstCharArrayDetector<T>::length, 0);
557 }
558 return *this;
559 }
560
566 OString & operator+=( const OString & str )
567#if defined LIBO_INTERNAL_ONLY
568 &
569#endif
570 {
571 rtl_string_newConcat( &pData, pData, str.pData );
572 return *this;
573 }
574#if defined LIBO_INTERNAL_ONLY
575 void operator+=(OString const &) && = delete;
576#endif
577
578#if defined LIBO_INTERNAL_ONLY
579 template<typename T> typename libreoffice_internal::CharPtrDetector<T, OString &>::Type
580 operator +=(T const & value) & { return operator +=(std::string_view(value)); }
581 template<typename T> typename libreoffice_internal::CharPtrDetector<T, OString &>::Type
582 operator +=(T const &) && = delete;
583
584 template<typename T>
585 typename libreoffice_internal::NonConstCharArrayDetector<T, OString &>::Type
586 operator +=(T & value) & { return operator +=(std::string_view(value)); }
587 template<typename T>
588 typename libreoffice_internal::NonConstCharArrayDetector<T, OString &>::Type operator +=(T &) &&
589 = delete;
590
591 template<typename T> typename libreoffice_internal::ConstCharArrayDetector<T, OString &>::Type
592 operator +=(T & literal) & {
593 assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
594 return operator +=(
595 std::string_view(
596 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
597 libreoffice_internal::ConstCharArrayDetector<T>::length));
598 }
599 template<typename T> typename libreoffice_internal::ConstCharArrayDetector<T, OString &>::Type
600 operator +=(T &) && = delete;
601
602 template<std::size_t N> OString & operator +=(OStringLiteral<N> const & literal) &
603 { return operator +=(std::string_view(literal.getStr(), literal.getLength())); }
604 template<std::size_t N> void operator +=(OStringLiteral<N> const &) && = delete;
605
606 OString & operator +=(std::string_view sv) & {
607 if (sv.empty()) {
608 return *this;
609 }
610 if (sv.size() > sal_uInt32(std::numeric_limits<sal_Int32>::max() - pData->length)) {
611 throw std::bad_alloc();
612 }
613 auto const l = pData->length + sv.size();
614 rtl_string_ensureCapacity(&pData, l);
615 *addDataHelper(pData->buffer + pData->length, sv.data(), sv.size()) = '\0';
616 pData->length = l;
617 return *this;
618 }
619 void operator +=(std::string_view) && = delete;
620#endif
621
622#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
627 template< typename T1, typename T2 >
628 OString& operator+=( OStringConcat< T1, T2 >&& c ) & {
629 sal_Int32 l = c.length();
630 if( l == 0 )
631 return *this;
632 l += pData->length;
633 rtl_string_ensureCapacity( &pData, l );
634 char* end = c.addData( pData->buffer + pData->length );
635 *end = '\0';
636 pData->length = l;
637 return *this;
638 }
639 template<typename T1, typename T2> void operator +=(
640 OStringConcat<T1, T2> &&) && = delete;
641
646 template< std::size_t N >
647 OString& operator+=( OStringNumber< N >&& n ) & {
648 return operator +=(std::string_view(n.buf, n.length));
649 }
650 template<std::size_t N> void operator +=(
651 OStringNumber<N> &&) && = delete;
652#endif
653
658 void clear()
659 {
660 rtl_string_new( &pData );
661 }
662
671 sal_Int32 getLength() const { return pData->length; }
672
681 bool isEmpty() const
682 {
683 return pData->length == 0;
684 }
685
697 const char * getStr() const SAL_RETURNS_NONNULL { return pData->buffer; }
698
708 char operator [](sal_Int32 index) const {
709 // silence spurious -Werror=strict-overflow warnings from GCC 4.8.2
710 assert(index >= 0 && static_cast<sal_uInt32>(index) < static_cast<sal_uInt32>(getLength()));
711 return getStr()[index];
712 }
713
726 sal_Int32 compareTo( const OString & str ) const
727 {
728 return rtl_str_compare_WithLength( pData->buffer, pData->length,
729 str.pData->buffer, str.pData->length );
730 }
731
745 sal_Int32 compareTo( const OString & rObj, sal_Int32 maxLength ) const
746 {
747 return rtl_str_shortenedCompare_WithLength( pData->buffer, pData->length,
748 rObj.pData->buffer, rObj.pData->length, maxLength );
749 }
750
763 sal_Int32 reverseCompareTo( const OString & str ) const
764 {
765 return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
766 str.pData->buffer, str.pData->length );
767 }
768
780 bool equals( const OString & str ) const
781 {
782 if ( pData->length != str.pData->length )
783 return false;
784 if ( pData == str.pData )
785 return true;
786 return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
787 str.pData->buffer, str.pData->length ) == 0;
788 }
789
804 bool equalsL( const char* value, sal_Int32 length ) const
805 {
806 if ( pData->length != length )
807 return false;
808
809 return rtl_str_reverseCompare_WithLength( pData->buffer, pData->length,
810 value, length ) == 0;
811 }
812
827#if defined LIBO_INTERNAL_ONLY
828 bool equalsIgnoreAsciiCase( std::string_view str ) const
829 {
830 if ( sal_uInt32(pData->length) != str.size() )
831 return false;
832 if ( pData->buffer == str.data() )
833 return true;
834 return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
835 str.data(), str.size() ) == 0;
836 }
837#else
838 bool equalsIgnoreAsciiCase( const OString & str ) const
839 {
840 if ( pData->length != str.pData->length )
841 return false;
842 if ( pData == str.pData )
843 return true;
844 return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
845 str.pData->buffer, str.pData->length ) == 0;
846 }
847#endif
848
870 template< typename T >
871 typename libreoffice_internal::CharPtrDetector< T, bool >::Type equalsIgnoreAsciiCase( const T& asciiStr ) const
872 {
873 return rtl_str_compareIgnoreAsciiCase( pData->buffer, asciiStr ) == 0;
874 }
875
876 template< typename T >
877 typename libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type equalsIgnoreAsciiCase( T& asciiStr ) const
878 {
879 return rtl_str_compareIgnoreAsciiCase( pData->buffer, asciiStr ) == 0;
880 }
881
887 template< typename T >
888 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type equalsIgnoreAsciiCase( T& literal ) const
889 {
890 RTL_STRING_CONST_FUNCTION
891 assert(
892 libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
893 return
894 (pData->length
895 == libreoffice_internal::ConstCharArrayDetector<T>::length)
896 && (rtl_str_compareIgnoreAsciiCase_WithLength(
897 pData->buffer, pData->length,
898 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
899 literal),
900 libreoffice_internal::ConstCharArrayDetector<T>::length)
901 == 0);
902 }
903
923 bool equalsIgnoreAsciiCaseL( const char * asciiStr, sal_Int32 asciiStrLength ) const
924 {
925 if ( pData->length != asciiStrLength )
926 return false;
927
928 return rtl_str_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
929 asciiStr, asciiStrLength ) == 0;
930 }
931
947#if defined LIBO_INTERNAL_ONLY
948 bool match( std::string_view str, sal_Int32 fromIndex = 0 ) const
949 {
950 assert(fromIndex >= 0);
951 return rtl_str_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
952 str.data(), str.size(), str.size() ) == 0;
953 }
954#else
955 bool match( const OString & str, sal_Int32 fromIndex = 0 ) const
956 {
957 assert(fromIndex >= 0);
958 return rtl_str_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
959 str.pData->buffer, str.pData->length, str.pData->length ) == 0;
960 }
961#endif
962
968 template< typename T >
969 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type match( T& literal, sal_Int32 fromIndex = 0 ) const
970 {
971 RTL_STRING_CONST_FUNCTION
972 assert(
973 libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
974 assert(fromIndex >= 0);
975 return
976 rtl_str_shortenedCompare_WithLength(
977 pData->buffer + fromIndex, pData->length - fromIndex,
978 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
979 literal),
980 libreoffice_internal::ConstCharArrayDetector<T>::length,
981 libreoffice_internal::ConstCharArrayDetector<T>::length)
982 == 0;
983 }
984
1001 bool matchL(
1002 char const * str, sal_Int32 strLength, sal_Int32 fromIndex = 0)
1003 const
1004 {
1005 assert(fromIndex >= 0);
1006 return rtl_str_shortenedCompare_WithLength(
1007 pData->buffer + fromIndex, pData->length - fromIndex,
1008 str, strLength, strLength) == 0;
1009 }
1010
1011 // This overload is left undefined, to detect calls of matchL that
1012 // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
1013 // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
1014 // platforms):
1015#if SAL_TYPES_SIZEOFLONG == 8
1016 void matchL(char const *, sal_Int32, rtl_TextEncoding) const;
1017#endif
1018
1037#if defined LIBO_INTERNAL_ONLY
1038 bool matchIgnoreAsciiCase( std::string_view str, sal_Int32 fromIndex = 0 ) const
1039 {
1040 assert(fromIndex >= 0);
1041 return rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1042 str.data(), str.size(),
1043 str.size() ) == 0;
1044 }
1045#else
1046 bool matchIgnoreAsciiCase( const OString & str, sal_Int32 fromIndex = 0 ) const
1047 {
1048 assert(fromIndex >= 0);
1049 return rtl_str_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1050 str.pData->buffer, str.pData->length,
1051 str.pData->length ) == 0;
1052 }
1053#endif
1059 template< typename T >
1060 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type matchIgnoreAsciiCase( T& literal, sal_Int32 fromIndex = 0 ) const
1061 {
1062 RTL_STRING_CONST_FUNCTION
1063 assert(
1064 libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
1065 assert(fromIndex >= 0);
1066 return
1067 rtl_str_shortenedCompareIgnoreAsciiCase_WithLength(
1068 pData->buffer+fromIndex, pData->length-fromIndex,
1069 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
1070 literal),
1071 libreoffice_internal::ConstCharArrayDetector<T>::length,
1072 libreoffice_internal::ConstCharArrayDetector<T>::length)
1073 == 0;
1074 }
1075
1076#if defined LIBO_INTERNAL_ONLY
1087 bool startsWith(std::string_view str) const {
1088 return match(str);
1089 }
1103 bool startsWith(std::string_view str, OString * rest) const {
1104 assert(rest);
1105 bool b = startsWith(str);
1106 if (b) {
1107 *rest = copy(str.size());
1108 }
1109 return b;
1110 }
1124 bool startsWith(std::string_view str, std::string_view * rest) const {
1125 assert(rest);
1126 bool b = startsWith(str);
1127 if (b) {
1128 *rest = subView(str.size());
1129 }
1130 return b;
1131 }
1132#else
1147 bool startsWith(OString const & str, OString * rest = NULL) const {
1148 bool b = match(str);
1149 if (b && rest != NULL) {
1150 *rest = copy(str.getLength());
1151 }
1152 return b;
1153 }
1154#endif
1155
1156#if defined LIBO_INTERNAL_ONLY
1162 template< typename T >
1163 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWith(
1164 T & literal) const
1165 {
1166 RTL_STRING_CONST_FUNCTION
1167 return match(literal, 0);
1168 }
1174 template< typename T >
1175 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWith(
1176 T & literal, OString * rest) const
1177 {
1178 RTL_STRING_CONST_FUNCTION
1179 assert(rest);
1180 bool b = startsWith(literal);
1181 if (b) {
1182 *rest = copy(
1183 libreoffice_internal::ConstCharArrayDetector<T>::length);
1184 }
1185 return b;
1186 }
1191 template< typename T >
1192 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWith(
1193 T & literal, std::string_view * rest) const
1194 {
1195 RTL_STRING_CONST_FUNCTION
1196 assert(rest);
1197 bool b = startsWith(literal);
1198 if (b) {
1199 *rest = subView(
1200 libreoffice_internal::ConstCharArrayDetector<T>::length);
1201 }
1202 return b;
1203 }
1204#else
1210 template< typename T >
1211 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWith(
1212 T & literal, OString * rest = NULL) const
1213 {
1214 RTL_STRING_CONST_FUNCTION
1215 bool b = match(literal, 0);
1216 if (b && rest != NULL) {
1217 *rest = copy(
1218 libreoffice_internal::ConstCharArrayDetector<T>::length);
1219 }
1220 return b;
1221 }
1222#endif
1223
1224#if defined LIBO_INTERNAL_ONLY
1241 bool startsWithIgnoreAsciiCase(std::string_view str)
1242 const
1243 {
1244 return matchIgnoreAsciiCase(str);
1245 }
1265 bool startsWithIgnoreAsciiCase(std::string_view str, OString * rest)
1266 const
1267 {
1268 assert(rest);
1269 bool b = startsWithIgnoreAsciiCase(str);
1270 if (b) {
1271 *rest = copy(str.size());
1272 }
1273 return b;
1274 }
1294 bool startsWithIgnoreAsciiCase(std::string_view str, std::string_view * rest)
1295 const
1296 {
1297 assert(rest);
1298 bool b = startsWithIgnoreAsciiCase(str);
1299 if (b) {
1300 *rest = subView(str.size());
1301 }
1302 return b;
1303 }
1304#else
1324 bool startsWithIgnoreAsciiCase(OString const & str, OString * rest = NULL)
1325 const
1326 {
1327 bool b = matchIgnoreAsciiCase(str);
1328 if (b && rest != NULL) {
1329 *rest = copy(str.getLength());
1330 }
1331 return b;
1332 }
1333#endif
1334
1335#if defined LIBO_INTERNAL_ONLY
1341 template< typename T >
1342 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
1343 startsWithIgnoreAsciiCase(T & literal) const
1344 {
1345 RTL_STRING_CONST_FUNCTION
1346 assert(
1347 libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
1348 return matchIgnoreAsciiCase(literal);
1349 }
1355 template< typename T >
1356 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
1357 startsWithIgnoreAsciiCase(T & literal, OString * rest) const
1358 {
1359 RTL_STRING_CONST_FUNCTION
1360 assert(rest);
1361 bool b = startsWithIgnoreAsciiCase(literal);
1362 if (b) {
1363 *rest = copy(
1364 libreoffice_internal::ConstCharArrayDetector<T>::length);
1365 }
1366 return b;
1367 }
1368 template< typename T >
1369 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
1370 startsWithIgnoreAsciiCase(T & literal, std::string_view * rest) const
1371 {
1372 RTL_STRING_CONST_FUNCTION
1373 assert(rest);
1374 bool b = startsWithIgnoreAsciiCase(literal);
1375 if (b) {
1376 *rest = subView(
1377 libreoffice_internal::ConstCharArrayDetector<T>::length);
1378 }
1379 return b;
1380 }
1381#else
1387 template< typename T >
1388 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
1389 startsWithIgnoreAsciiCase(T & literal, OString * rest = NULL) const
1390 {
1391 RTL_STRING_CONST_FUNCTION
1392 assert(
1393 libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
1394 bool b = matchIgnoreAsciiCase(literal);
1395 if (b && rest != NULL) {
1396 *rest = copy(
1397 libreoffice_internal::ConstCharArrayDetector<T>::length);
1398 }
1399 return b;
1400 }
1401#endif
1402
1403#if defined LIBO_INTERNAL_ONLY
1414 bool endsWith(std::string_view str) const {
1415 return str.size() <= sal_uInt32(getLength())
1416 && match(str, getLength() - str.size());
1417 }
1432 bool endsWith(std::string_view str, OString * rest) const {
1433 assert(rest);
1434 bool b = endsWith(str);
1435 if (b) {
1436 *rest = copy(0, getLength() - str.size());
1437 }
1438 return b;
1439 }
1453 bool endsWith(std::string_view str, std::string_view * rest) const {
1454 assert(rest);
1455 bool b = endsWith(str);
1456 if (b) {
1457 *rest = subView(0, getLength() - str.size());
1458 }
1459 return b;
1460 }
1461#else
1476 bool endsWith(OString const & str, OString * rest = NULL) const {
1477 bool b = str.getLength() <= getLength()
1478 && match(str, getLength() - str.getLength());
1479 if (b && rest != NULL) {
1480 *rest = copy(0, getLength() - str.getLength());
1481 }
1482 return b;
1483 }
1484#endif
1485
1486#if defined LIBO_INTERNAL_ONLY
1492 template< typename T >
1493 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type endsWith(
1494 T & literal) const
1495 {
1496 RTL_STRING_CONST_FUNCTION
1497 assert(
1498 libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
1499 bool b
1500 = (libreoffice_internal::ConstCharArrayDetector<T>::length
1501 <= sal_uInt32(getLength()))
1502 && match(
1503 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
1504 literal),
1505 (getLength()
1506 - libreoffice_internal::ConstCharArrayDetector<T>::length));
1507 return b;
1508 }
1514 template< typename T >
1515 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type endsWith(
1516 T & literal, OString * rest) const
1517 {
1518 RTL_STRING_CONST_FUNCTION
1519 assert(rest);
1520 bool b = endsWith(literal);
1521 if (b) {
1522 *rest = copy(
1523 0,
1524 (getLength()
1525 - libreoffice_internal::ConstCharArrayDetector<T>::length));
1526 }
1527 return b;
1528 }
1534 template< typename T >
1535 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type endsWith(
1536 T & literal, std::string_view * rest) const
1537 {
1538 RTL_STRING_CONST_FUNCTION
1539 assert(rest);
1540 bool b = endsWith(literal);
1541 if (b) {
1542 *rest = subView(
1543 0,
1544 (getLength()
1545 - libreoffice_internal::ConstCharArrayDetector<T>::length));
1546 }
1547 return b;
1548 }
1549#else
1555 template< typename T >
1556 typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type endsWith(
1557 T & literal, OString * rest = NULL) const
1558 {
1559 RTL_STRING_CONST_FUNCTION
1560 assert(
1561 libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
1562 bool b
1563 = (libreoffice_internal::ConstCharArrayDetector<T>::length
1564 <= sal_uInt32(getLength()))
1565 && match(
1566 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
1567 literal),
1568 (getLength()
1569 - libreoffice_internal::ConstCharArrayDetector<T>::length));
1570 if (b && rest != NULL) {
1571 *rest = copy(
1572 0,
1573 (getLength()
1574 - libreoffice_internal::ConstCharArrayDetector<T>::length));
1575 }
1576 return b;
1577 }
1578#endif
1579
1593 bool endsWithL(char const * str, sal_Int32 strLength) const {
1594 return strLength <= getLength()
1595 && matchL(str, strLength, getLength() - strLength);
1596 }
1597
1598 friend bool operator == ( const OString& rStr1, const OString& rStr2 )
1599 { return rStr1.equals(rStr2); }
1600 friend bool operator != ( const OString& rStr1, const OString& rStr2 )
1601 { return !(operator == ( rStr1, rStr2 )); }
1602 friend bool operator < ( const OString& rStr1, const OString& rStr2 )
1603 { return rStr1.compareTo( rStr2 ) < 0; }
1604 friend bool operator > ( const OString& rStr1, const OString& rStr2 )
1605 { return rStr1.compareTo( rStr2 ) > 0; }
1606 friend bool operator <= ( const OString& rStr1, const OString& rStr2 )
1607 { return rStr1.compareTo( rStr2 ) <= 0; }
1608 friend bool operator >= ( const OString& rStr1, const OString& rStr2 )
1609 { return rStr1.compareTo( rStr2 ) >= 0; }
1610
1611 template< typename T >
1612 friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator==( const OString& rStr1, const T& value )
1613 {
1614 return
1615 rtl_str_compare_WithLength(
1616 rStr1.getStr(), rStr1.getLength(), value, rtl_str_getLength(value))
1617 == 0;
1618 }
1619
1620 template< typename T >
1621 friend typename libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator==( const OString& rStr1, T& value )
1622 {
1623 return
1624 rtl_str_compare_WithLength(
1625 rStr1.getStr(), rStr1.getLength(), value, rtl_str_getLength(value))
1626 == 0;
1627 }
1628
1629 template< typename T >
1630 friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator==( const T& value, const OString& rStr2 )
1631 {
1632 return
1633 rtl_str_compare_WithLength(
1634 value, rtl_str_getLength(value), rStr2.getStr(), rStr2.getLength())
1635 == 0;
1636 }
1637
1638 template< typename T >
1639 friend typename libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator==( T& value, const OString& rStr2 )
1640 {
1641 return
1642 rtl_str_compare_WithLength(
1643 value, rtl_str_getLength(value), rStr2.getStr(), rStr2.getLength())
1644 == 0;
1645 }
1646
1652 template< typename T >
1653 friend typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator==( const OString& rStr, T& literal )
1654 {
1655 RTL_STRING_CONST_FUNCTION
1656 assert(
1657 libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
1658 return
1659 (rStr.getLength()
1660 == libreoffice_internal::ConstCharArrayDetector<T>::length)
1661 && (rtl_str_compare_WithLength(
1662 rStr.pData->buffer, rStr.pData->length,
1663 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
1664 literal),
1665 libreoffice_internal::ConstCharArrayDetector<T>::length)
1666 == 0);
1667 }
1668
1674 template< typename T >
1675 friend typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator==( T& literal, const OString& rStr )
1676 {
1677 RTL_STRING_CONST_FUNCTION
1678 assert(
1679 libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
1680 return
1681 (rStr.getLength()
1682 == libreoffice_internal::ConstCharArrayDetector<T>::length)
1683 && (rtl_str_compare_WithLength(
1684 rStr.pData->buffer, rStr.pData->length,
1685 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
1686 literal),
1687 libreoffice_internal::ConstCharArrayDetector<T>::length)
1688 == 0);
1689 }
1690
1691 template< typename T >
1692 friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=( const OString& rStr1, const T& value )
1693 {
1694 return !(operator == ( rStr1, value ));
1695 }
1696
1697 template< typename T >
1698 friend typename libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator!=( const OString& rStr1, T& value )
1699 {
1700 return !(operator == ( rStr1, value ));
1701 }
1702
1703 template< typename T >
1704 friend typename libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=( const T& value, const OString& rStr2 )
1705 {
1706 return !(operator == ( value, rStr2 ));
1707 }
1708
1709 template< typename T >
1710 friend typename libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator!=( T& value, const OString& rStr2 )
1711 {
1712 return !(operator == ( value, rStr2 ));
1713 }
1714
1720 template< typename T >
1721 friend typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator!=( const OString& rStr, T& literal )
1722 {
1723 return !( rStr == literal );
1724 }
1725
1731 template< typename T >
1732 friend typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator!=( T& literal, const OString& rStr )
1733 {
1734 return !( literal == rStr );
1735 }
1736
1744 sal_Int32 hashCode() const
1745 {
1746 return rtl_str_hashCode_WithLength( pData->buffer, pData->length );
1747 }
1748
1762 sal_Int32 indexOf( char ch, sal_Int32 fromIndex = 0 ) const
1763 {
1764 assert(fromIndex >= 0);
1765 sal_Int32 ret = rtl_str_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
1766 return (ret < 0 ? ret : ret+fromIndex);
1767 }
1768
1778 sal_Int32 lastIndexOf( char ch ) const
1779 {
1780 return rtl_str_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
1781 }
1782
1795 sal_Int32 lastIndexOf( char ch, sal_Int32 fromIndex ) const
1796 {
1797 return rtl_str_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
1798 }
1799
1815#if defined LIBO_INTERNAL_ONLY
1816 sal_Int32 indexOf( std::string_view str, sal_Int32 fromIndex = 0 ) const
1817 {
1818 assert(fromIndex >= 0);
1819 sal_Int32 ret = rtl_str_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1820 str.data(), str.size() );
1821 return (ret < 0 ? ret : ret+fromIndex);
1822 }
1823#else
1824 sal_Int32 indexOf( const OString & str, sal_Int32 fromIndex = 0 ) const
1825 {
1826 assert(fromIndex >= 0);
1827 sal_Int32 ret = rtl_str_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
1828 str.pData->buffer, str.pData->length );
1829 return (ret < 0 ? ret : ret+fromIndex);
1830 }
1831#endif
1837 template< typename T >
1838 typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const
1839 {
1840 RTL_STRING_CONST_FUNCTION
1841 assert(
1842 libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
1843 assert(fromIndex >= 0);
1844 sal_Int32 n = rtl_str_indexOfStr_WithLength(
1845 pData->buffer + fromIndex, pData->length - fromIndex,
1846 libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
1847 libreoffice_internal::ConstCharArrayDetector<T>::length);
1848 return n < 0 ? n : n + fromIndex;
1849 }
1850
1869 sal_Int32 indexOfL(char const * str, sal_Int32 len, sal_Int32 fromIndex = 0)
1870 const
1871 {
1872 assert(fromIndex >= 0);
1873 sal_Int32 n = rtl_str_indexOfStr_WithLength(
1874 pData->buffer + fromIndex, pData->length - fromIndex, str, len);
1875 return n < 0 ? n : n + fromIndex;
1876 }
1877
1878 // This overload is left undefined, to detect calls of indexOfL that
1879 // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
1880 // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
1881 // platforms):
1882#if SAL_TYPES_SIZEOFLONG == 8
1883 void indexOfL(char const *, sal_Int32, rtl_TextEncoding) const;
1884#endif
1885
1901#if defined LIBO_INTERNAL_ONLY
1902 sal_Int32 lastIndexOf( std::string_view str ) const
1903 {
1904 return rtl_str_lastIndexOfStr_WithLength( pData->buffer, pData->length,
1905 str.data(), str.size() );
1906 }
1907#else
1908 sal_Int32 lastIndexOf( const OString & str ) const
1909 {
1910 return rtl_str_lastIndexOfStr_WithLength( pData->buffer, pData->length,
1911 str.pData->buffer, str.pData->length );
1912 }
1913#endif
1914
1932#if defined LIBO_INTERNAL_ONLY
1933 sal_Int32 lastIndexOf( std::string_view str, sal_Int32 fromIndex ) const
1934 {
1935 return rtl_str_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
1936 str.data(), str.size() );
1937 }
1938#else
1939 sal_Int32 lastIndexOf( const OString & str, sal_Int32 fromIndex ) const
1940 {
1941 return rtl_str_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
1942 str.pData->buffer, str.pData->length );
1943 }
1944#endif
1945
1956 SAL_WARN_UNUSED_RESULT OString copy( sal_Int32 beginIndex ) const
1957 {
1958 return copy(beginIndex, getLength() - beginIndex);
1959 }
1960
1973 SAL_WARN_UNUSED_RESULT OString copy( sal_Int32 beginIndex, sal_Int32 count ) const
1974 {
1975 rtl_String *pNew = NULL;
1976 rtl_string_newFromSubString( &pNew, pData, beginIndex, count );
1977 return OString( pNew, SAL_NO_ACQUIRE );
1978 }
1979
1980#if defined LIBO_INTERNAL_ONLY
1991 SAL_WARN_UNUSED_RESULT std::string_view subView( sal_Int32 beginIndex ) const
1992 {
1993 assert(beginIndex >= 0);
1994 assert(beginIndex <= getLength());
1995 return subView(beginIndex, getLength() - beginIndex);
1996 }
1997
2010 SAL_WARN_UNUSED_RESULT std::string_view subView( sal_Int32 beginIndex, sal_Int32 count ) const
2011 {
2012 assert(beginIndex >= 0);
2013 assert(count >= 0);
2014 assert(beginIndex <= getLength());
2015 assert(count <= getLength() - beginIndex);
2016 return std::string_view(*this).substr(beginIndex, count);
2017 }
2018#endif
2019
2020#ifndef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2029 SAL_WARN_UNUSED_RESULT OString concat( const OString & str ) const
2030 {
2031 rtl_String* pNew = NULL;
2032 rtl_string_newConcat( &pNew, pData, str.pData );
2033 return OString( pNew, SAL_NO_ACQUIRE );
2034 }
2035#endif
2036
2037#ifndef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2038 friend OString operator+( const OString & str1, const OString & str2 )
2039 {
2040 return str1.concat( str2 );
2041 }
2042#endif
2043
2044// hide this from internal code to avoid ambiguous lookup error
2045#ifndef LIBO_INTERNAL_ONLY
2059 SAL_WARN_UNUSED_RESULT OString replaceAt( sal_Int32 index, sal_Int32 count, const OString& newStr ) const
2060 {
2061 rtl_String* pNew = NULL;
2062 rtl_string_newReplaceStrAt( &pNew, pData, index, count, newStr.pData );
2063 return OString( pNew, SAL_NO_ACQUIRE );
2064 }
2065#endif
2066
2067#ifdef LIBO_INTERNAL_ONLY
2068 SAL_WARN_UNUSED_RESULT OString replaceAt( sal_Int32 index, sal_Int32 count, std::string_view newStr ) const
2069 {
2070 rtl_String* pNew = NULL;
2071 rtl_string_newReplaceStrAt_WithLength ( &pNew, pData, index, count, newStr.data(), newStr.size() );
2072 return OString( pNew, SAL_NO_ACQUIRE );
2073 }
2074#endif
2075
2089 SAL_WARN_UNUSED_RESULT OString replace( char oldChar, char newChar ) const
2090 {
2091 rtl_String* pNew = NULL;
2092 rtl_string_newReplace( &pNew, pData, oldChar, newChar );
2093 return OString( pNew, SAL_NO_ACQUIRE );
2094 }
2095
2114 SAL_WARN_UNUSED_RESULT OString replaceFirst(
2115 OString const & from, OString const & to, sal_Int32 * index = NULL) const
2116 {
2117 rtl_String * s = NULL;
2118 sal_Int32 i = 0;
2119 rtl_string_newReplaceFirst(
2120 &s, pData, from.pData->buffer, from.pData->length,
2121 to.pData->buffer, to.pData->length, index == NULL ? &i : index);
2122 return OString(s, SAL_NO_ACQUIRE);
2123 }
2124
2138 SAL_WARN_UNUSED_RESULT OString replaceAll(OString const & from, OString const & to) const {
2139 rtl_String * s = NULL;
2140 rtl_string_newReplaceAll(
2141 &s, pData, from.pData->buffer, from.pData->length,
2142 to.pData->buffer, to.pData->length);
2143 return OString(s, SAL_NO_ACQUIRE);
2144 }
2145
2156 SAL_WARN_UNUSED_RESULT OString toAsciiLowerCase() const
2157 {
2158 rtl_String* pNew = NULL;
2159 rtl_string_newToAsciiLowerCase( &pNew, pData );
2160 return OString( pNew, SAL_NO_ACQUIRE );
2161 }
2162
2173 SAL_WARN_UNUSED_RESULT OString toAsciiUpperCase() const
2174 {
2175 rtl_String* pNew = NULL;
2176 rtl_string_newToAsciiUpperCase( &pNew, pData );
2177 return OString( pNew, SAL_NO_ACQUIRE );
2178 }
2179
2191 SAL_WARN_UNUSED_RESULT OString trim() const
2192 {
2193 rtl_String* pNew = NULL;
2194 rtl_string_newTrim( &pNew, pData );
2195 return OString( pNew, SAL_NO_ACQUIRE );
2196 }
2197
2222 OString getToken( sal_Int32 token, char cTok, sal_Int32& index ) const
2223 {
2224 rtl_String * pNew = NULL;
2225 index = rtl_string_getToken( &pNew, pData, token, cTok, index );
2226 return OString( pNew, SAL_NO_ACQUIRE );
2227 }
2228
2242 OString getToken(sal_Int32 count, char separator) const {
2243 sal_Int32 n = 0;
2244 return getToken(count, separator, n);
2245 }
2246
2255 bool toBoolean() const
2256 {
2257 return rtl_str_toBoolean( pData->buffer );
2258 }
2259
2266 char toChar() const
2267 {
2268 return pData->buffer[0];
2269 }
2270
2281 sal_Int32 toInt32( sal_Int16 radix = 10 ) const
2282 {
2283 return rtl_str_toInt32( pData->buffer, radix );
2284 }
2285
2298 sal_uInt32 toUInt32( sal_Int16 radix = 10 ) const
2299 {
2300 return rtl_str_toUInt32( pData->buffer, radix );
2301 }
2302
2313 sal_Int64 toInt64( sal_Int16 radix = 10 ) const
2314 {
2315 return rtl_str_toInt64( pData->buffer, radix );
2316 }
2317
2330 sal_uInt64 toUInt64( sal_Int16 radix = 10 ) const
2331 {
2332 return rtl_str_toUInt64( pData->buffer, radix );
2333 }
2334
2343 float toFloat() const
2344 {
2345 return rtl_str_toFloat( pData->buffer );
2346 }
2347
2356 double toDouble() const
2357 {
2358 return rtl_str_toDouble( pData->buffer );
2359 }
2360
2361#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2362
2363 static auto number( int i, sal_Int16 radix = 10 )
2364 {
2365 return OStringNumber<RTL_STR_MAX_VALUEOFINT32>(rtl_str_valueOfInt32, i, radix);
2366 }
2367 static auto number( long long ll, sal_Int16 radix = 10 )
2368 {
2369 return OStringNumber<RTL_STR_MAX_VALUEOFINT64>(rtl_str_valueOfInt64, ll, radix);
2370 }
2371 static auto number( unsigned long long ll, sal_Int16 radix = 10 )
2372 {
2373 return OStringNumber<RTL_STR_MAX_VALUEOFUINT64>(rtl_str_valueOfUInt64, ll, radix);
2374 }
2375 static auto number( unsigned int i, sal_Int16 radix = 10 )
2376 {
2377 return number( static_cast< unsigned long long >( i ), radix );
2378 }
2379 static auto number( long i, sal_Int16 radix = 10)
2380 {
2381 return number( static_cast< long long >( i ), radix );
2382 }
2383 static auto number( unsigned long i, sal_Int16 radix = 10 )
2384 {
2385 return number( static_cast< unsigned long long >( i ), radix );
2386 }
2387#else
2398 static OString number( int i, sal_Int16 radix = 10 )
2399 {
2400 char aBuf[RTL_STR_MAX_VALUEOFINT32];
2401 return OString(aBuf, rtl_str_valueOfInt32(aBuf, i, radix));
2402 }
2403
2405 static OString number( unsigned int i, sal_Int16 radix = 10 )
2406 {
2407 return number( static_cast< unsigned long long >( i ), radix );
2408 }
2409
2411 static OString number( long i, sal_Int16 radix = 10 )
2412 {
2413 return number( static_cast< long long >( i ), radix );
2414 }
2415
2417 static OString number( unsigned long i, sal_Int16 radix = 10 )
2418 {
2419 return number( static_cast< unsigned long long >( i ), radix );
2420 }
2421
2423 static OString number( long long ll, sal_Int16 radix = 10 )
2424 {
2425 char aBuf[RTL_STR_MAX_VALUEOFINT64];
2426 return OString(aBuf, rtl_str_valueOfInt64(aBuf, ll, radix));
2427 }
2428
2430 static OString number( unsigned long long ll, sal_Int16 radix = 10 )
2431 {
2432 char aBuf[RTL_STR_MAX_VALUEOFUINT64];
2433 return OString(aBuf, rtl_str_valueOfUInt64(aBuf, ll, radix));
2434 }
2435#endif
2436
2446 static OString number( float f )
2447 {
2448 rtl_String* pNew = NULL;
2449 // Same as rtl::str::valueOfFP, used for rtl_str_valueOfFloat
2450 rtl_math_doubleToString(&pNew, NULL, 0, f, rtl_math_StringFormat_G,
2451 RTL_STR_MAX_VALUEOFFLOAT - SAL_N_ELEMENTS("-x.E-xxx") + 1, '.',
2452 NULL, 0, true);
2453 if (pNew == NULL)
2454 throw std::bad_alloc();
2455
2456 return OString(pNew, SAL_NO_ACQUIRE);
2457 }
2458
2468 static OString number( double d )
2469 {
2470 rtl_String* pNew = NULL;
2471 // Same as rtl::str::valueOfFP, used for rtl_str_valueOfDouble
2472 rtl_math_doubleToString(&pNew, NULL, 0, d, rtl_math_StringFormat_G,
2473 RTL_STR_MAX_VALUEOFDOUBLE - SAL_N_ELEMENTS("-x.E-xxx") + 1, '.',
2474 NULL, 0, true);
2475 if (pNew == NULL)
2476 throw std::bad_alloc();
2477
2478 return OString(pNew, SAL_NO_ACQUIRE);
2479 }
2480
2481#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2482 static auto boolean(bool b)
2483 {
2484 return OStringNumber<RTL_STR_MAX_VALUEOFBOOLEAN>(rtl_str_valueOfBoolean, b);
2485 }
2486#else
2498 SAL_DEPRECATED("use boolean()") static OString valueOf( sal_Bool b )
2499 {
2500 return boolean(b);
2501 }
2502
2514 static OString boolean( bool b )
2515 {
2516 char aBuf[RTL_STR_MAX_VALUEOFBOOLEAN];
2517 return OString(aBuf, rtl_str_valueOfBoolean(aBuf, b));
2518 }
2519#endif
2520
2528 SAL_DEPRECATED("convert to OString or use directly") static OString valueOf( char c )
2529 {
2530 return OString( &c, 1 );
2531 }
2532
2543 SAL_DEPRECATED("use number()") static OString valueOf( sal_Int32 i, sal_Int16 radix = 10 )
2544 {
2545 return number( i, radix );
2546 }
2547
2558 SAL_DEPRECATED("use number()") static OString valueOf( sal_Int64 ll, sal_Int16 radix = 10 )
2559 {
2560 return number( ll, radix );
2561 }
2562
2572 SAL_DEPRECATED("use number()") static OString valueOf( float f )
2573 {
2574 return number(f);
2575 }
2576
2586 SAL_DEPRECATED("use number()") static OString valueOf( double d )
2587 {
2588 return number(d);
2589 }
2590
2591#if defined LIBO_INTERNAL_ONLY
2592 operator std::string_view() const { return {getStr(), sal_uInt32(getLength())}; }
2593#endif
2594
2595#if defined LIBO_INTERNAL_ONLY
2596 // A wrapper for the first expression in an
2597 //
2598 // OString::Concat(e1) + e2 + ...
2599 //
2600 // concatenation chain, when neither of the first two e1, e2 is one of our rtl string-related
2601 // classes (so something like
2602 //
2603 // OString s = "a" + (b ? std::string_view("c") : std::string_view("dd"));
2604 //
2605 // would not compile):
2606 template<typename T> [[nodiscard]] static
2607 OStringConcat<OStringConcatMarker, T>
2608 Concat(T const & value) { return OStringConcat<OStringConcatMarker, T>(value); }
2609
2610 // This overload is needed so that an argument of type 'char const[N]' ends up as
2611 // 'OStringConcat<rtl::OStringConcatMarker, char const[N]>' rather than as
2612 // 'OStringConcat<rtl::OStringConcatMarker, char[N]>':
2613 template<typename T, std::size_t N> [[nodiscard]] static
2614 OStringConcat<OStringConcatMarker, T[N]>
2615 Concat(T (& value)[N]) { return OStringConcat<OStringConcatMarker, T[N]>(value); }
2616#endif
2617
2618private:
2619#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
2620 static constexpr auto empty = OStringLiteral(""); // [-loplugin:ostr]
2621#endif
2622};
2623
2624#if defined LIBO_INTERNAL_ONLY
2625inline bool operator ==(OString const & lhs, StringConcatenation<char> const & rhs)
2626{ return lhs == std::string_view(rhs); }
2627inline bool operator !=(OString const & lhs, StringConcatenation<char> const & rhs)
2628{ return lhs != std::string_view(rhs); }
2629inline bool operator ==(StringConcatenation<char> const & lhs, OString const & rhs)
2630{ return std::string_view(lhs) == rhs; }
2631inline bool operator !=(StringConcatenation<char> const & lhs, OString const & rhs)
2632{ return std::string_view(lhs) != rhs; }
2633#endif
2634
2635/* ======================================================================= */
2636
2637#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
2638
2642template<>
2643struct ToStringHelper< OString >
2644{
2645 static std::size_t length( const OString& s ) { return s.getLength(); }
2646 char* operator()( char* buffer, const OString& s ) const { return addDataHelper( buffer, s.getStr(), s.getLength()); }
2647};
2648
2652template<std::size_t N>
2653struct ToStringHelper< OStringLiteral<N> >
2654{
2655 static constexpr std::size_t length( const OStringLiteral<N>& str ) { return str.getLength(); }
2656 char* operator()( char* buffer, const OStringLiteral<N>& str ) const { return addDataHelper( buffer, str.getStr(), str.getLength() ); }
2657};
2658
2662template< typename charT, typename traits, typename T1, typename T2 >
2663inline std::basic_ostream<charT, traits> & operator <<(
2664 std::basic_ostream<charT, traits> & stream, OStringConcat< T1, T2 >&& concat)
2665{
2666 return stream << OString( std::move(concat) );
2667}
2668#endif
2669
2670
2676 struct OStringHash
2677{
2687 size_t operator()( const OString& rString ) const
2688 { return static_cast<size_t>(rString.hashCode()); }
2689};
2690
2692 struct CStringEqual
2693{
2694 bool operator()( const char* p1, const char* p2) const
2695 { return rtl_str_compare(p1, p2) == 0; }
2696};
2697
2699 struct CStringHash
2700{
2701 size_t operator()(const char* p) const
2702 { return rtl_str_hashCode(p); }
2703};
2704
2705/* ======================================================================= */
2706
2713template< typename charT, typename traits > std::basic_ostream<charT, traits> &
2714 operator <<(
2715 std::basic_ostream<charT, traits> & stream, OString const & rString)
2716{
2717 return stream << rString.getStr();
2718 // best effort; potentially loses data due to embedded null characters
2719}
2720
2721} /* Namespace */
2722
2723#ifdef RTL_STRING_UNITTEST
2724namespace rtl
2725{
2726typedef rtlunittest::OString OString;
2727}
2728#undef RTL_STRING_CONST_FUNCTION
2729#endif
2730
2731#if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
2732using ::rtl::OString;
2733using ::rtl::OStringChar;
2734using ::rtl::Concat2View;
2735using ::rtl::OStringHash;
2736using ::rtl::OStringLiteral;
2737using RepeatedChar = ::rtl::RepeatedChar_t<char>;
2738#endif
2739
2740#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
2741
2742template<
2743#if defined RTL_STRING_UNITTEST
2744 rtlunittest::
2745#endif
2746 OStringLiteral L>
2747constexpr
2748#if defined RTL_STRING_UNITTEST
2749 rtlunittest::
2750#endif
2751 OString
2752operator ""_ostr() { return L; }
2753
2754template<
2755#if defined RTL_STRING_UNITTEST
2756 rtlunittest::
2757#endif
2758 OStringLiteral L>
2759constexpr
2760#if defined RTL_STRING_UNITTEST
2761rtlunittest
2762#else
2763 rtl
2764#endif
2765::detail::OStringHolder<L> operator ""_tstr() {
2766 return
2767#if defined RTL_STRING_UNITTEST
2768 rtlunittest
2769#else
2770 rtl
2771#endif
2772 ::detail::OStringHolder<L>();
2773}
2774
2775#endif
2776
2778
2783#if defined LIBO_INTERNAL_ONLY
2784namespace std {
2785
2786template<>
2787struct hash<::rtl::OString>
2788{
2789 std::size_t operator()(::rtl::OString const & s) const
2790 {
2791 if constexpr (sizeof(std::size_t) == 8)
2792 {
2793 // return a hash that uses the full 64-bit range instead of a 32-bit value
2794 size_t n = s.getLength();
2795 for (sal_Int32 i = 0, len = s.getLength(); i < len; ++i)
2796 n = 37 * n + s[i];
2797 return n;
2798 }
2799 else
2800 return std::size_t(s.hashCode());
2801 }
2802};
2803
2804}
2805
2806#endif
2808
2809#endif // INCLUDED_RTL_STRING_HXX
2810
2811/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
config.h
SAL_N_ELEMENTS
#define SAL_N_ELEMENTS(arr)
Definition macros.h:51
SAL_DEPRECATED
#define SAL_DEPRECATED(message)
Use as follows: SAL_DEPRECATED("Don't use, it's evil.") void doit(int nPara);.
Definition types.h:492
__sal_NoAcquire
__sal_NoAcquire
Definition types.h:371
SAL_NO_ACQUIRE
@ SAL_NO_ACQUIRE
definition of a no acquire enum for ctors
Definition types.h:374
sal_Bool
unsigned char sal_Bool
Definition types.h:38
sal_Unicode
sal_uInt16 sal_Unicode
Definition types.h:123
SAL_WARN_UNUSED_RESULT
#define SAL_WARN_UNUSED_RESULT
Use this as markup for functions and methods whose return value must be used.
Definition types.h:288
SAL_WARN_UNUSED
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition types.h:611
math.h
rtl_math_StringFormat_G
@ rtl_math_StringFormat_G
Like sprintf() G, 'F' or 'E' format is used depending on which one is more compact.
Definition math.h:53
rtl_math_doubleToString
SAL_DLLPUBLIC void rtl_math_doubleToString(rtl_String **pResult, sal_Int32 *pResultCapacity, sal_Int32 nResultOffset, double fValue, enum rtl_math_StringFormat eFormat, sal_Int32 nDecPlaces, char cDecSeparator, sal_Int32 const *pGroups, char cGroupSeparator, sal_Bool bEraseTrailingDecZeros) SAL_THROW_EXTERN_C()
Conversions analogous to sprintf() using internal rounding.
string.h
rtl_str_toDouble
SAL_DLLPUBLIC double rtl_str_toDouble(const char *str) SAL_THROW_EXTERN_C()
Interpret a string as a double.
rtl_str_compare
SAL_DLLPUBLIC sal_Int32 rtl_str_compare(const char *first, const char *second) SAL_THROW_EXTERN_C()
Compare two strings.
rtl_str_hashCode_WithLength
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.
rtl_string_newReplaceStrAt
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.
rtl_str_toBoolean
SAL_DLLPUBLIC sal_Bool rtl_str_toBoolean(const char *str) SAL_THROW_EXTERN_C()
Interpret a string as a boolean.
RTL_STR_MAX_VALUEOFDOUBLE
#define RTL_STR_MAX_VALUEOFDOUBLE
Definition string.h:715
RTL_STR_MAX_VALUEOFINT32
#define RTL_STR_MAX_VALUEOFINT32
Definition string.h:631
rtl_string_acquire
SAL_DLLPUBLIC void rtl_string_acquire(rtl_String *str) SAL_THROW_EXTERN_C()
Increment the reference count of a string.
rtl_string_alloc
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.
rtl_string_newConcat
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.
rtl_str_toUInt32
SAL_DLLPUBLIC sal_uInt32 rtl_str_toUInt32(const char *str, sal_Int16 radix) SAL_THROW_EXTERN_C()
Interpret a string as an unsigned integer.
rtl_str_compareIgnoreAsciiCase
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.
rtl_string_assign
SAL_DLLPUBLIC void rtl_string_assign(rtl_String **str, rtl_String *rightValue) SAL_THROW_EXTERN_C()
Assign a new value to a string.
rtl_str_lastIndexOfStr_WithLength
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.
rtl_string_newReplaceAll
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.
rtl_str_reverseCompare_WithLength
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.
rtl_str_toUInt64
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.
rtl_string_getToken
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.
rtl_str_valueOfInt64
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.
rtl_string_newReplaceFirst
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.
rtl_string_newFromStr
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.
rtl_str_shortenedCompare_WithLength
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.
rtl_string_new
SAL_DLLPUBLIC void rtl_string_new(rtl_String **newStr) SAL_THROW_EXTERN_C()
Allocate a new string containing no characters.
rtl_str_shortenedCompareIgnoreAsciiCase_WithLength
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.
rtl_str_indexOfChar_WithLength
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.
rtl_uString2String
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.
rtl_str_valueOfBoolean
SAL_DLLPUBLIC sal_Int32 rtl_str_valueOfBoolean(char *str, sal_Bool b) SAL_THROW_EXTERN_C()
Create the string representation of a boolean.
OUSTRING_TO_OSTRING_CVTFLAGS
#define OUSTRING_TO_OSTRING_CVTFLAGS
Definition string.h:1350
rtl_string_newFromLiteral
SAL_DLLPUBLIC void rtl_string_newFromLiteral(rtl_String **newStr, const char *value, sal_Int32 len, sal_Int32 allocExtra) SAL_THROW_EXTERN_C()
RTL_STR_MAX_VALUEOFBOOLEAN
#define RTL_STR_MAX_VALUEOFBOOLEAN
Definition string.h:589
RTL_STR_MAX_VALUEOFFLOAT
#define RTL_STR_MAX_VALUEOFFLOAT
Definition string.h:696
rtl_str_hashCode
SAL_DLLPUBLIC sal_Int32 rtl_str_hashCode(const char *str) SAL_THROW_EXTERN_C()
Return a hash code for a string.
rtl_str_valueOfInt32
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.
rtl_str_getLength
SAL_DLLPUBLIC sal_Int32 rtl_str_getLength(const char *str) SAL_THROW_EXTERN_C()
Return the length of a string.
RTL_STR_MAX_VALUEOFUINT64
#define RTL_STR_MAX_VALUEOFUINT64
Definition string.h:677
rtl_string_newToAsciiLowerCase
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.
rtl_string_newFromStr_WithLength
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.
rtl_string_newTrim
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.
rtl_str_toInt32
SAL_DLLPUBLIC sal_Int32 rtl_str_toInt32(const char *str, sal_Int16 radix) SAL_THROW_EXTERN_C()
Interpret a string as an integer.
RTL_STR_MAX_VALUEOFINT64
#define RTL_STR_MAX_VALUEOFINT64
Definition string.h:654
rtl_string_ensureCapacity
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.
rtl_string_release
SAL_DLLPUBLIC void rtl_string_release(rtl_String *str) SAL_THROW_EXTERN_C()
Decrement the reference count of a string.
rtl_string_newFromSubString
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.
rtl_str_indexOfStr_WithLength
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.
rtl_str_valueOfUInt64
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.
rtl_string_newToAsciiUpperCase
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.
rtl_str_toFloat
SAL_DLLPUBLIC float rtl_str_toFloat(const char *str) SAL_THROW_EXTERN_C()
Interpret a string as a float.
rtl_string_newReplace
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.
rtl_str_toInt64
SAL_DLLPUBLIC sal_Int64 rtl_str_toInt64(const char *str, sal_Int16 radix) SAL_THROW_EXTERN_C()
Interpret a string as a long integer.
rtl_str_compareIgnoreAsciiCase_WithLength
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.
rtl_str_compare_WithLength
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.
rtl_str_lastIndexOfChar_WithLength
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.
stringutils.hxx
textenc.h
rtl_TextEncoding
sal_uInt16 rtl_TextEncoding
The various supported text encodings.
Definition textenc.h:37
oslInterlockedCount
sal_Int32 oslInterlockedCount
Definition interlck.h:44
rtl
Definition bootstrap.hxx:34
rtl::operator<<
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:2714
rtl::OString
This String class provide base functionality for C++ like 8-Bit character array handling.
Definition string.hxx:193
rtl::OString::concat
SAL_WARN_UNUSED_RESULT OString concat(const OString &str) const
Concatenates the specified string to the end of this string.
Definition string.hxx:2029
rtl::OString::OString
OString(T &literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type=libreoffice_internal::Dummy())
New string from a string literal.
Definition string.hxx:352
rtl::OString::OString
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:428
rtl::OString::endsWith
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:1556
rtl::OString::number
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:2417
rtl::OString::startsWith
bool startsWith(OString const &str, OString *rest=NULL) const
Check whether this string starts with a given substring.
Definition string.hxx:1147
rtl::OString::operator==
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:1653
rtl::OString::startsWith
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:1211
rtl::OString::operator==
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:1675
rtl::OString::valueOf
static OString valueOf(sal_Bool b)
Returns the string representation of the sal_Bool argument.
Definition string.hxx:2498
rtl::OString::indexOf
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:1838
rtl::OString::OString
OString(const char *value, sal_Int32 length)
New string from a character buffer array.
Definition string.hxx:379
rtl::OString::number
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:2430
rtl::OString::number
static OString number(int i, sal_Int16 radix=10)
Returns the string representation of the integer argument.
Definition string.hxx:2398
rtl::OString::toUInt64
sal_uInt64 toUInt64(sal_Int16 radix=10) const
Returns the uint64 value from this string.
Definition string.hxx:2330
rtl::OString::indexOfL
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:1869
rtl::OString::operator=
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:544
rtl::OString::compareTo
sal_Int32 compareTo(const OString &str) const
Compares two strings.
Definition string.hxx:726
rtl::OString::operator+=
OString & operator+=(const OString &str)
Append a string to this string.
Definition string.hxx:566
rtl::OString::equalsIgnoreAsciiCase
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:888
rtl::OString::toAsciiUpperCase
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:2173
rtl::OString::startsWithIgnoreAsciiCase
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:1389
rtl::OString::operator!=
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:1732
rtl::OString::toChar
char toChar() const
Returns the first character from this string.
Definition string.hxx:2266
rtl::OString::toBoolean
bool toBoolean() const
Returns the Boolean value from this string.
Definition string.hxx:2255
rtl::OString::operator+
friend OString operator+(const OString &str1, const OString &str2)
Definition string.hxx:2038
rtl::OString::copy
SAL_WARN_UNUSED_RESULT OString copy(sal_Int32 beginIndex) const
Returns a new string that is a substring of this string.
Definition string.hxx:1956
rtl::OString::operator!=
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator!=(const OString &rStr1, T &value)
Definition string.hxx:1698
rtl::OString::OString
OString(rtl_String *str)
New string from OString data.
Definition string.hxx:275
rtl::OString::startsWithIgnoreAsciiCase
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:1324
rtl::OString::number
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:2423
rtl::OString::lastIndexOf
sal_Int32 lastIndexOf(const OString &str) const
Returns the index within this string of the last occurrence of the specified substring,...
Definition string.hxx:1908
rtl::OString::clear
void clear()
Clears the string, i.e, makes a zero-character string.
Definition string.hxx:658
rtl::OString::replaceFirst
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:2114
rtl::OString::getToken
OString getToken(sal_Int32 count, char separator) const
Returns a token from the string.
Definition string.hxx:2242
rtl::OString::number
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:2405
rtl::OString::getStr
const char * getStr() const SAL_RETURNS_NONNULL
Returns a pointer to the characters of this string.
Definition string.hxx:697
rtl::OString::operator=
OString & operator=(const OString &str)
Assign a new string.
Definition string.hxx:513
rtl::OString::matchIgnoreAsciiCase
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:1060
rtl::OString::compareTo
sal_Int32 compareTo(const OString &rObj, sal_Int32 maxLength) const
Compares two strings with an maximum count of characters.
Definition string.hxx:745
rtl::OString::isEmpty
bool isEmpty() const
Checks if a string is empty.
Definition string.hxx:681
rtl::OString::operator==
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator==(T &value, const OString &rStr2)
Definition string.hxx:1639
rtl::OString::OString
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:319
rtl::OString::getToken
OString getToken(sal_Int32 token, char cTok, sal_Int32 &index) const
Returns a token in the string.
Definition string.hxx:2222
rtl::OString::reverseCompareTo
sal_Int32 reverseCompareTo(const OString &str) const
Compares two strings in reverse order.
Definition string.hxx:763
rtl::OString::lastIndexOf
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:1939
rtl::OString::lastIndexOf
sal_Int32 lastIndexOf(char ch) const
Returns the index within this string of the last occurrence of the specified character,...
Definition string.hxx:1778
rtl::OString::copy
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:1973
rtl::OString::operator!=
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=(const OString &rStr1, const T &value)
Definition string.hxx:1692
rtl::OString::replace
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:2089
rtl::OString::hashCode
sal_Int32 hashCode() const
Returns a hashcode for this string.
Definition string.hxx:1744
rtl::OString::boolean
static OString boolean(bool b)
Returns the string representation of the boolean argument.
Definition string.hxx:2514
rtl::OString::matchL
bool matchL(char const *str, sal_Int32 strLength, sal_Int32 fromIndex=0) const
Match against a substring appearing in this string.
Definition string.hxx:1001
rtl::OString::equalsL
bool equalsL(const char *value, sal_Int32 length) const
Perform a comparison of two strings.
Definition string.hxx:804
rtl::OString::trim
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:2191
rtl::OString::OString
OString(const OString &str)
New string from OString.
Definition string.hxx:223
rtl::OString::replaceAll
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:2138
rtl::OString::endsWithL
bool endsWithL(char const *str, sal_Int32 strLength) const
Check whether this string ends with a given substring.
Definition string.hxx:1593
rtl::OString::toAsciiLowerCase
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:2156
rtl::OString::match
bool match(const OString &str, sal_Int32 fromIndex=0) const
Match against a substring appearing in this string.
Definition string.hxx:955
rtl::OString::toFloat
float toFloat() const
Returns the float value from this string.
Definition string.hxx:2343
rtl::OString::OString
OString()
New string containing no characters.
Definition string.hxx:205
rtl::OString::match
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:969
rtl::OString::operator==
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator==(const T &value, const OString &rStr2)
Definition string.hxx:1630
rtl::OString::OString
OString(char value)
New string from a single character.
Definition string.hxx:298
rtl::OString::number
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:2411
rtl::OString::equalsIgnoreAsciiCase
bool equalsIgnoreAsciiCase(const OString &str) const
Perform an ASCII lowercase comparison of two strings.
Definition string.hxx:838
rtl::OString::toInt64
sal_Int64 toInt64(sal_Int16 radix=10) const
Returns the int64 value from this string.
Definition string.hxx:2313
rtl::OString::indexOf
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:1824
rtl::OString::toInt32
sal_Int32 toInt32(sal_Int16 radix=10) const
Returns the int32 value from this string.
Definition string.hxx:2281
rtl::OString::~OString
~OString()
Release the string data.
Definition string.hxx:477
rtl::OString::equalsIgnoreAsciiCase
libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type equalsIgnoreAsciiCase(T &asciiStr) const
Definition string.hxx:877
rtl::OString::operator!=
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:1721
rtl::OString::equalsIgnoreAsciiCase
libreoffice_internal::CharPtrDetector< T, bool >::Type equalsIgnoreAsciiCase(const T &asciiStr) const
Perform an ASCII lowercase comparison of two strings.
Definition string.hxx:871
rtl::OString::indexOf
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:1762
rtl::OString::replaceAt
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:2059
rtl::OString::getLength
sal_Int32 getLength() const
Returns the length of this string.
Definition string.hxx:671
rtl::OString::toDouble
double toDouble() const
Returns the double value from this string.
Definition string.hxx:2356
rtl::OString::number
static OString number(double d)
Returns the string representation of the double argument.
Definition string.hxx:2468
rtl::OString::endsWith
bool endsWith(OString const &str, OString *rest=NULL) const
Check whether this string ends with a given substring.
Definition string.hxx:1476
rtl::OString::equals
bool equals(const OString &str) const
Perform a comparison of two strings.
Definition string.hxx:780
rtl::OString::operator==
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator==(const OString &rStr1, T &value)
Definition string.hxx:1621
rtl::OString::OString
OString(rtl_String *str, __sal_NoAcquire)
New string from OString data without acquiring it.
Definition string.hxx:288
rtl::OString::lastIndexOf
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:1795
rtl::OString::OString
OString(T &value, typename libreoffice_internal::NonConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type=libreoffice_internal::Dummy())
Definition string.hxx:326
rtl::OString::operator==
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator==(const OString &rStr1, const T &value)
Definition string.hxx:1612
rtl::OString::toUInt32
sal_uInt32 toUInt32(sal_Int16 radix=10) const
Returns the uint32 value from this string.
Definition string.hxx:2298
rtl::OString::number
static OString number(float f)
Returns the string representation of the float argument.
Definition string.hxx:2446
rtl::OString::operator!=
friend libreoffice_internal::CharPtrDetector< T, bool >::Type operator!=(const T &value, const OString &rStr2)
Definition string.hxx:1704
rtl::OString::equalsIgnoreAsciiCaseL
bool equalsIgnoreAsciiCaseL(const char *asciiStr, sal_Int32 asciiStrLength) const
Perform an ASCII lowercase comparison of two strings.
Definition string.hxx:923
rtl::OString::matchIgnoreAsciiCase
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:1046
rtl::OString::operator!=
friend libreoffice_internal::NonConstCharArrayDetector< T, bool >::Type operator!=(T &value, const OString &rStr2)
Definition string.hxx:1710
rtl::OStringHash
A helper to use OStrings with hash maps.
Definition string.hxx:2677
rtl::OStringHash::operator()
size_t operator()(const OString &rString) const
Compute a hash code for a string.
Definition string.hxx:2687
rtl::CStringEqual
Equality functor for classic c-strings (i.e., null-terminated char* strings).
Definition string.hxx:2693
rtl::CStringEqual::operator()
bool operator()(const char *p1, const char *p2) const
Definition string.hxx:2694
rtl::CStringHash
Hashing functor for classic c-strings (i.e., null-terminated char* strings).
Definition string.hxx:2700
rtl::CStringHash::operator()
size_t operator()(const char *p) const
Definition string.hxx:2701
rtl::libreoffice_internal::Dummy
Definition stringutils.hxx:178
rtl::libreoffice_internal::CharPtrDetector
Definition stringutils.hxx:181
rtl::libreoffice_internal::NonConstCharArrayDetector
Definition stringutils.hxx:205
rtl::libreoffice_internal::ConstCharArrayDetector
Definition stringutils.hxx:233