Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/LibreOffice/include/rtl/   (Office von Apache Version 25.8.3.2©)  Datei vom 5.10.2025 mit Größe 144 kB image not shown  

Quelle  ustring.hxx   Sprache: C

 
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */


/*
 * This file is part of LibreOffice published API.
 */


#ifndef INCLUDED_RTL_USTRING_HXX
#define INCLUDED_RTL_USTRING_HXX

#include "sal/config.h"

#include <cassert>
#include <cstddef>
#include <cstdlib>
#include <limits>
#include <new>
#include <ostream>
#include <utility>

#if defined LIBO_INTERNAL_ONLY
#include <algorithm>
#include <string_view>
#include <type_traits>
#endif

#include "rtl/math.h"
#include "rtl/ustring.h"
#include "rtl/string.hxx"
#include "rtl/stringutils.hxx"
#include "rtl/textenc.h"

#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
#include "config_global.h"
#include "o3tl/safeint.hxx"
#include "rtl/stringconcat.hxx"
#endif

#ifdef RTL_STRING_UNITTEST
extern bool rtl_string_unittest_invalid_conversion;
#endif

// The unittest uses slightly different code to help check that the proper
// calls are made. The class is put into a different namespace to make
// sure the compiler generates a different (if generating also non-inline)
// copy of the function and does not merge them together. The class
// is "brought" into the proper rtl namespace by a typedef below.
#ifdef RTL_STRING_UNITTEST
#define rtl rtlunittest
#endif

namespace rtl
{

class OUStringBuffer;

#ifdef RTL_STRING_UNITTEST
#undef rtl
#endif

#if defined LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
/// @cond INTERNAL

/**
A wrapper dressing a string literal as a static-refcount rtl_uString.

This class is not part of public API and is meant to be used only in LibreOffice code.
@since LibreOffice 4.0
*/

template<std::size_t N> class SAL_WARN_UNUSED OUStringLiteral {
    static_assert(N != 0);
    static_assert(N - 1 <= std::numeric_limits<sal_Int32>::max(), "literal too long");

public:
#if HAVE_CPP_CONSTEVAL
    consteval
#else
    constexpr
#endif
    OUStringLiteral(char16_t const (&literal)[N]) {
        assertLayout();
        assert(literal[N - 1] == '\0');
        std::copy_n(literal, N, more.buffer);
    }

    constexpr sal_Int32 getLength() const { return more.length; }

    constexpr sal_Unicode const * getStr() const SAL_RETURNS_NONNULL { return more.buffer; }

    constexpr operator std::u16string_view() const { return {more.buffer, sal_uInt32(more.length)}; }

private:
    static constexpr void assertLayout() {
        // These static_asserts verifying the layout compatibility with rtl_uString cannot be class
        // member declarations, as offsetof requires a complete type, so defer them to here:
        static_assert(std::is_standard_layout_v<OUStringLiteral>);
        static_assert(offsetof(OUStringLiteral, str.refCount) == offsetof(OUStringLiteral, more.refCount));
        static_assert(offsetof(OUStringLiteral, str.length) == offsetof(OUStringLiteral, more.length));
        static_assert(offsetof(OUStringLiteral, str.buffer) == offsetof(OUStringLiteral, more.buffer));
    }

    struct Data {
        Data() = default;

        oslInterlockedCount refCount = 0x40000000; // SAL_STRING_STATIC_FLAG (sal/rtl/strimp.hxx)
        sal_Int32 length = N - 1;
        sal_Unicode buffer[N];
    };

public:
    // (Data members must be public so that OUStringLiteral is a structural type that can be used as
    // a non-type template parameter type for operator ""_ustr:)
    union {
        rtl_uString str;
        Data more = {};
    };
};

#if defined RTL_STRING_UNITTEST
namespace libreoffice_internal {
template<std::size_t N> struct ExceptConstCharArrayDetector<OUStringLiteral<N>> {};
template<std::size_t N> struct ExceptCharArrayDetector<OUStringLiteral<N>> {};
}
#endif

/// @endcond
#endif

/* ======================================================================= */

/**
  This String class provides base functionality for C++ like Unicode
  character array handling. The advantage of this class is that it
  handles all the memory management for you - and it does it
  more efficiently. If you assign a string to another string, the
  data of both strings are shared (without any copy operation or
  memory allocation) as long as you do not change the string. This class
  also stores the length of the string, so that many operations are
  faster than the C-str-functions.

  This class provides only readonly string handling. So you could create
  a string and you could only query the content from this string.
  It provides also functionality to change the string, but this results
  in every case in a new string instance (in the most cases with a
  memory allocation). You don't have functionality to change the
  content of the string. If you want to change the string content, then
  you should use the OStringBuffer class, which provides these
  functionalities and avoids too much memory allocation.

  The design of this class is similar to the string classes in Java so
  less people should have understanding problems when they use this class.
*/


// coverity[ missing_move_assignment : SUPPRESS] - don't report the suppressed move assignment
class SAL_WARN_UNUSED SAL_DLLPUBLIC_RTTI OUString
{
public:
    /// @cond INTERNAL
    rtl_uString * pData;
    /// @endcond

    /**
      New string containing no characters.
    */

    OUString()
    {
        pData = NULL;
        rtl_uString_new( &pData );
    }

    /**
      New string from OUString.

      @param    str         an OUString.
    */

#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
    constexpr
#endif
    OUString( const OUString & str )
    {
        pData = str.pData;
#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
        if (std::is_constant_evaluated()) {
            //TODO: We would want to
            //
            //   assert(SAL_STRING_IS_STATIC(pData));
            //
            // here, but that wouldn't work because read of member `str` of OUStringLiteral's
            // anonymous union with active member `more` is not allowed in a constant expression.
        } else
#endif
            rtl_uString_acquire( pData );
    }

#if defined LIBO_INTERNAL_ONLY
#if !defined(__COVERITY__) // suppress COPY_INSTEAD_OF_MOVE suggestions
    /**
      Move constructor.

      @param    str         an OUString.
      @since LibreOffice 5.2
    */

#if !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
    constexpr
#endif
    OUString( OUString && str ) noexcept
    {
        pData = str.pData;
#if !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
        if (std::is_constant_evaluated()) {
            //TODO: We would want to
            //
            //   assert(SAL_STRING_IS_STATIC(pData));
            //
            // here, but that wouldn't work because read of member `str` of OUStringLiteral's
            // anonymous union with active member `more` is not allowed in a constant expression.
            return;
        }
#endif
        str.pData = nullptr;
        rtl_uString_new( &str.pData );
    }
#endif
#endif

    /**
      New string from OUString data.

      @param    str         an OUString data.
    */

    OUString( rtl_uString * str )
    {
        pData = str;
        rtl_uString_acquire( pData );
    }

#if defined LIBO_INTERNAL_ONLY
    /// @cond INTERNAL
    // Catch inadvertent conversions to the above ctor:
    OUString(std::nullptr_t) = delete;
    /// @endcond
#endif

    /** New OUString from OUString data without acquiring it.  Takeover of ownership.

        The SAL_NO_ACQUIRE dummy parameter is only there to distinguish this
        from other constructors.

        @param str
               OUString data
    */

    OUString( rtl_uString * str, __sal_NoAcquire )
        { pData = str; }

    /**
      New string from a single Unicode character.

      @param    value       a Unicode character.
    */

    explicit OUString( sal_Unicode value )
        : pData (NULL)
    {
        rtl_uString_newFromStr_WithLength( &pData, &value, 1 );
    }

#if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST_CONCAT
    /// @cond INTERNAL
    // Catch inadvertent conversions to the above ctor (but still allow
    // construction from char literals):
    OUString(int) = delete;
    explicit OUString(char c):
        OUString(sal_Unicode(static_cast<unsigned char>(c)))
    {}
    /// @endcond
#endif

#if defined LIBO_INTERNAL_ONLY

    template<typename T> explicit OUString(
        T const & value,
        typename libreoffice_internal::CharPtrDetector<T, libreoffice_internal::Dummy>::TypeUtf16
            = libreoffice_internal::Dummy()):
        pData(nullptr)
    { rtl_uString_newFromStr(&pData, value); }

    template<typename T> explicit OUString(
        T & value,
        typename
        libreoffice_internal::NonConstCharArrayDetector<T, libreoffice_internal::Dummy>::TypeUtf16
            = libreoffice_internal::Dummy()):
        pData(nullptr)
    { rtl_uString_newFromStr(&pData, value); }

#else

    /**
      New string from a Unicode character buffer array.

      @param    value       a NULL-terminated Unicode character array.
    */

    OUString( const sal_Unicode * value )
    {
        pData = NULL;
        rtl_uString_newFromStr( &pData, value );
    }

#endif

    /**
      New string from a Unicode character buffer array.

      @param    value       a Unicode character array.
      @param    length      the number of character which should be copied.
                            The character array length must be greater than
                            or equal to this value.
    */

    OUString( const sal_Unicode * value, sal_Int32 length )
    {
        pData = NULL;
        rtl_uString_newFromStr_WithLength( &pData, value, length );
    }

    /**
      New string from an 8-Bit string literal that is expected to contain only
      characters in the ASCII set (i.e. first 128 characters). This constructor
      allows an efficient and convenient way to create OUString
      instances from ASCII literals. When creating strings from data that
      is not pure ASCII, it needs to be converted to OUString by explicitly
      providing the encoding to use for the conversion.

      If there are any embedded \0's in the string literal, the result is undefined.
      Use the overload that explicitly accepts length.

      @param    literal         the 8-bit ASCII string literal

      @since LibreOffice 3.6
    */

    templatetypename T >
    OUString( T& literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type = libreoffice_internal::Dummy() )
    {
        assert(
            libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
        pData = NULL;
        if SAL_CONSTEXPR (libreoffice_internal::ConstCharArrayDetector<T>::length == 0) {
            rtl_uString_new(&pData);
        } else {
            rtl_uString_newFromLiteral(
                &pData,
                libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
                    literal),
                libreoffice_internal::ConstCharArrayDetector<T>::length, 0);
        }
#ifdef RTL_STRING_UNITTEST
        rtl_string_unittest_const_literal = true;
#endif
    }

#if defined LIBO_INTERNAL_ONLY
    // Rather use a u""_ustr literal (but don't remove this entirely, to avoid implicit support for
    // it via std::u16string_view from kicking in):
    template<typename T> OUString(
        T &,
        typename libreoffice_internal::ConstCharArrayDetector<
            T, libreoffice_internal::Dummy>::TypeUtf16
                = libreoffice_internal::Dummy()) = delete;

    OUString(OUStringChar c): pData(nullptr) { rtl_uString_newFromStr_WithLength(&pData, &c.c,&nbsp;1); }
#endif

#if defined LIBO_INTERNAL_ONLY && defined RTL_STRING_UNITTEST
    /// @cond INTERNAL
    /**
     * Only used by unittests to detect incorrect conversions.
     * @internal
     */

    templatetypename T >
    OUString( T&, typename libreoffice_internal::ExceptConstCharArrayDetector< T >::Type = libreoffice_internal::Dummy() )
    {
        pData = NULL;
        rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
        rtl_string_unittest_invalid_conversion = true;
    }
    /**
     * Only used by unittests to detect incorrect conversions.
     * @internal
     */

    templatetypename T >
    OUString( const T&, typename libreoffice_internal::ExceptCharArrayDetector< T >::Type = libreoffice_internal::Dummy() )
    {
        pData = NULL;
        rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
        rtl_string_unittest_invalid_conversion = true;
    }
    /// @endcond
#endif

#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
    /// @cond INTERNAL
    /**
      New string from a string literal.

      @since LibreOffice 5.0
    */

    template<std::size_t N> constexpr OUString(OUStringLiteral<N> const & literal):
        pData(const_cast<rtl_uString *>(&literal.str)) {}
    template<std::size_t N> OUString(OUStringLiteral<N> &&) = delete;
    /// @endcond
#endif

#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
    // For operator ""_tstr:
    template<OStringLiteral L> OUString(detail::OStringHolder<L> const & holder) {
        pData = nullptr;
        if (holder.literal.getLength() == 0) {
            rtl_uString_new(&pData);
        } else {
            rtl_uString_newFromLiteral(
                &pData, holder.literal.getStr(), holder.literal.getLength(), 0);
        }
    }
#endif

    /**
      New string from an 8-Bit character buffer array.

      @param    value           An 8-Bit character array.
      @param    length          The number of character which should be converted.
                                The 8-Bit character array length must be
                                greater than or equal to this value.
      @param    encoding        The text encoding from which the 8-Bit character
                                sequence should be converted.
      @param    convertFlags    Flags which control the conversion.
                                see RTL_TEXTTOUNICODE_FLAGS_...

      @exception std::bad_alloc is thrown if an out-of-memory condition occurs
    */

    OUString( const char * value, sal_Int32 length,
              rtl_TextEncoding encoding,
              sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS )
    {
        pData = NULL;
        rtl_string2UString( &pData, value, length, encoding, convertFlags );
        if (pData == NULL) {
            throw std::bad_alloc();
        }
    }

    /** Create a new string from an array of Unicode code points.

        @param codePoints
        an array of at least codePointCount code points, which each must be in
        the range from 0 to 0x10FFFF, inclusive.  May be null if codePointCount
        is zero.

        @param codePointCount
        the non-negative number of code points.

        @exception std::bad_alloc
        is thrown if either an out-of-memory condition occurs or the resulting
        number of UTF-16 code units would have been larger than SAL_MAX_INT32.

        @since UDK 3.2.7
    */

    explicit OUString(
        sal_uInt32 const * codePoints, sal_Int32 codePointCount):
        pData(NULL)
    {
        rtl_uString_newFromCodePoints(&pData, codePoints, codePointCount);
        if (pData == NULL) {
            throw std::bad_alloc();
        }
    }

#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
    /**
     @overload
     @internal
    */

    templatetypename T1, typename T2 >
    OUString( OUStringConcat< T1, T2 >&& c )
    {
        const sal_Int32 l = c.length();
        pData = rtl_uString_alloc( l );
        if (l != 0)
        {
            sal_Unicode* end = c.addData( pData->buffer );
            pData->length = l;
            *end = '\0';
        }
    }

    /**
     @overload
     @internal
    */

    template< std::size_t N >
    OUString( OUStringNumber< N >&& n )
        : OUString( n.buf, n.length )
    {}
#endif

#if defined LIBO_INTERNAL_ONLY
    explicit OUString(std::u16string_view sv) {
        if (sv.size() > sal_uInt32(std::numeric_limits<sal_Int32>::max())) {
            throw std::bad_alloc();
        }
        pData = nullptr;
        rtl_uString_newFromStr_WithLength(&pData, sv.data(), sv.size());
    }
#endif

    /**
      Release the string data.
    */

#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
    constexpr
#endif
    ~OUString()
    {
#if defined LIBO_INTERNAL_ONLY && !(defined _MSC_VER && _MSC_VER <= 1929 && defined _MANAGED)
        if (std::is_constant_evaluated()) {
           //TODO: We would want to
           //
           //   assert(SAL_STRING_IS_STATIC(pData));
           //
           // here, but that wouldn't work because read of member `str` of OUStringLiteral's
           // anonymous union with active member `more` is not allowed in a constant expression.
        } else
#endif
            rtl_uString_release( pData );
    }

    /** Provides an OUString const & passing a storage pointer of an
        rtl_uString * handle.
        It is more convenient to use C++ OUString member functions when dealing
        with rtl_uString * handles.  Using this function avoids unnecessary
        acquire()/release() calls for a temporary OUString object.

        @param ppHandle
               pointer to storage
        @return
               OUString const & based on given storage
    */

    static OUString const & unacquired( rtl_uString * const * ppHandle )
        { return * reinterpret_cast< OUString const * >( ppHandle ); }

#if defined LIBO_INTERNAL_ONLY
    /** Provides an OUString const & passing an OUStringBuffer const reference.
        It is more convenient to use C++ OUString member functions when checking
        current buffer content. Use this function instead of toString (that
        allocates a new OUString from buffer data) when the result is used in
        comparisons.

        @param str
               an OUStringBuffer
        @return
               OUString const & based on given storage
        @since LibreOffice 7.4
    */

    static OUString const& unacquired(const OUStringBuffer& str);
#endif

    /**
      Assign a new string.

      @param    str         an OUString.
    */

    OUString & operator=( const OUString & str )
    {
        rtl_uString_assign( &pData, str.pData );
        return *this;
    }

#if defined LIBO_INTERNAL_ONLY
#if !defined(__COVERITY__) // suppress COPY_INSTEAD_OF_MOVE suggestions
    /**
      Move assign a new string.

      @param    str         an OUString.
      @since LibreOffice 5.2
    */

    OUString & operator=( OUString && str ) noexcept
    {
        std::swap(pData, str.pData);
        return *this;
    }
#endif
#endif

    /**
      Assign a new string from an 8-Bit string literal that is expected to contain only
      characters in the ASCII set (i.e. first 128 characters). This operator
      allows an efficient and convenient way to assign OUString
      instances from ASCII literals. When assigning strings from data that
      is not pure ASCII, it needs to be converted to OUString by explicitly
      providing the encoding to use for the conversion.

      @param    literal         the 8-bit ASCII string literal

      @since LibreOffice 3.6
    */

    templatetypename T >
    typename libreoffice_internal::ConstCharArrayDetector< T, OUString& >::Type operator=( T& literal )
    {
        assert(
            libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
        if SAL_CONSTEXPR (libreoffice_internal::ConstCharArrayDetector<T>::length == 0) {
            rtl_uString_new(&pData);
        } else {
            rtl_uString_newFromLiteral(
                &pData,
                libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
                    literal),
                libreoffice_internal::ConstCharArrayDetector<T>::length, 0);
        }
        return *this;
    }

#if defined LIBO_INTERNAL_ONLY
    // Rather assign from a u""_ustr literal (but don't remove this entirely, to avoid implicit
    // support for it via std::u16string_view from kicking in):
    template<typename T>
    typename
        libreoffice_internal::ConstCharArrayDetector<T, OUString &>::TypeUtf16
    operator =(T &) = delete;

    OUString & operator =(OUStringChar c) {
        rtl_uString_newFromStr_WithLength(&pData, &c.c, 1);
        return *this;
    }

    /** @overload @since LibreOffice 5.4 */
    template<std::size_t N> OUString & operator =(OUStringLiteral<N> const & literal) {
        rtl_uString_release(pData);
        pData = const_cast<rtl_uString *>(&literal.str);
        return *this;
    }
    template<std::size_t N> OUString & operator =(OUStringLiteral<N> &&) = delete;

    template <std::size_t N>
    OUString & operator =(OUStringNumber<N> && n) {
        // n.length should never be zero, so no need to add an optimization for that case
        rtl_uString_newFromStr_WithLength(&pData, n.buf, n.length);
        return *this;
    }

    OUString & operator =(std::u16string_view sv) {
        if (sv.empty()) {
            rtl_uString_new(&pData);
        } else {
            rtl_uString_newFromStr_WithLength(&pData, sv.data(), sv.size());
        }
        return *this;
    }
#endif

#if defined LIBO_INTERNAL_ONLY
    /**
      Append the contents of an OUStringBuffer to this string.

      @param    str         an OUStringBuffer.

      @exception std::bad_alloc is thrown if an out-of-memory condition occurs
      @since LibreOffice 6.2
    */

    inline OUString & operator+=( const OUStringBuffer & str ) &;
#endif

    /**
      Append a string to this string.

      @param    str         an OUString.

      @exception std::bad_alloc is thrown if an out-of-memory condition occurs
    */

    OUString & operator+=( const OUString & str )
#if defined LIBO_INTERNAL_ONLY
        &
#endif
    {
        return internalAppend(str.pData);
    }
#if defined LIBO_INTERNAL_ONLY
    void operator+=(OUString const &) && = delete;
#endif

    /** Append an ASCII string literal to this string.

        @param literal  an 8-bit ASCII-only string literal

        @since LibreOffice 5.1
    */

    template<typename T>
    typename libreoffice_internal::ConstCharArrayDetector<T, OUString &>::Type
    operator +=(T & literal)
#if defined LIBO_INTERNAL_ONLY
        &
#endif
    {
        assert(
            libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
        rtl_uString_newConcatAsciiL(
            &pData, pData,
            libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
            libreoffice_internal::ConstCharArrayDetector<T>::length);
        return *this;
    }
#if defined LIBO_INTERNAL_ONLY
    template<typename T>
    typename libreoffice_internal::ConstCharArrayDetector<T, OUString &>::Type
    operator +=(T &) && = delete;
#endif

#if defined LIBO_INTERNAL_ONLY
    /** @overload @since LibreOffice 5.3 */
    template<typename T>
    typename
        libreoffice_internal::ConstCharArrayDetector<T, OUString &>::TypeUtf16
    operator +=(T & literal) & {
        rtl_uString_newConcatUtf16L(
            &pData, pData,
            libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
            libreoffice_internal::ConstCharArrayDetector<T>::length);
        return *this;
    }
    template<typename T>
    typename
        libreoffice_internal::ConstCharArrayDetector<T, OUString &>::TypeUtf16
    operator +=(T &) && = delete;

    /** @overload @since LibreOffice 5.4 */
    template<std::size_t N> OUString & operator +=(OUStringLiteral<N> const & literal) &&nbsp;{
        rtl_uString_newConcatUtf16L(&pData, pData, literal.getStr(), literal.getLength());
        return *this;
    }
    template<std::size_t N> void operator +=(OUStringLiteral<N> const &) && = delete;

    OUString & operator +=(std::u16string_view sv) & {
        if (sv.size() > sal_uInt32(std::numeric_limits<sal_Int32>::max())) {
            throw std::bad_alloc();
        }
        rtl_uString_newConcatUtf16L(&pData, pData, sv.data(), sv.size());
        return *this;
    }
    void operator +=(std::u16string_view) && = delete;
#endif

#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
    /**
     @overload
     @internal
    */

    templatetypename T1, typename T2 >
    OUString& operator+=( OUStringConcat< T1, T2 >&& c ) & {
        sal_Int32 l = c.length();
        if( l == 0 )
            return *this;
        l += pData->length;
        rtl_uString_ensureCapacity( &pData, l );
        sal_Unicode* end = c.addData( pData->buffer + pData->length );
        *end = '\0';
        pData->length = l;
        return *this;
    }
    template<typename T1, typename T2> void operator +=(
        OUStringConcat<T1, T2> &&) && = delete;

    /**
     @overload
     @internal
    */

    template< std::size_t N >
    OUString& operator+=( OUStringNumber< N >&& n ) & {
        sal_Int32 l = n.length;
        if( l == 0 )
            return *this;
        l += pData->length;
        rtl_uString_ensureCapacity( &pData, l );
        sal_Unicode* end = addDataHelper( pData->buffer + pData->length, n.buf, n.length );
        *end = '\0';
        pData->length = l;
        return *this;
    }
    template<std::size_t N> void operator +=(
        OUStringNumber<N> &&) && = delete;
#endif

    /**
      Clears the string, i.e, makes a zero-character string
      @since LibreOffice 4.4
    */

    void clear()
    {
        rtl_uString_new( &pData );
    }

    /**
      Returns the length of this string.

      The length is equal to the number of Unicode characters in this string.

      @return   the length of the sequence of characters represented by this
                object.
    */

    sal_Int32 getLength() const { return pData->length; }

    /**
      Checks if a string is empty.

      @return   true if the string is empty;
                false, otherwise.

      @since LibreOffice 3.4
    */

    bool isEmpty() const
    {
        return pData->length == 0;
    }

    /**
      Returns a pointer to the Unicode character buffer for this string.

      It isn't necessarily NULL terminated.

      @return   a pointer to the Unicode characters buffer for this object.
    */

    const sal_Unicode * getStr() const SAL_RETURNS_NONNULL { return pData->buffer; }

    /**
      Access to individual characters.

      @param index must be non-negative and less than length.

      @return the character at the given index.

      @since LibreOffice 3.5
    */

    sal_Unicode operator [](sal_Int32 index) const {
        // silence spurious -Werror=strict-overflow warnings from GCC 4.8.2
        assert(index >= 0 && static_cast<sal_uInt32>(index) < static_cast<sal_uInt32>(getLength()));
        return getStr()[index];
    }

    /**
      Compares two strings.

      The comparison is based on the numeric value of each character in
      the strings and return a value indicating their relationship.
      This function can't be used for language specific sorting.

      @param    str         the object to be compared.
      @return   0 - if both strings are equal
                < 0 - if this string is less than the string argument
                > 0 - if this string is greater than the string argument
    */

#if defined LIBO_INTERNAL_ONLY
    sal_Int32 compareTo( std::u16string_view str ) const
    {
        return rtl_ustr_compare_WithLength( pData->buffer, pData->length,
                                            str.data(), str.length() );
    }
#else
    sal_Int32 compareTo( const OUString & str ) const
    {
        return rtl_ustr_compare_WithLength( pData->buffer, pData->length,
                                            str.pData->buffer, str.pData->length );
    }
#endif

    /**
      Compares two strings with a maximum count of characters.

      The comparison is based on the numeric value of each character in
      the strings and return a value indicating their relationship.
      This function can't be used for language specific sorting.

      @param    str         the object to be compared.
      @param    maxLength   the maximum count of characters to be compared.
      @return   0 - if both strings are equal
                < 0 - if this string is less than the string argument
                > 0 - if this string is greater than the string argument

      @since UDK 3.2.7
    */

#if defined LIBO_INTERNAL_ONLY
    sal_Int32 compareTo( std::u16string_view str, sal_Int32 maxLength ) const
    {
        return rtl_ustr_shortenedCompare_WithLength( pData->buffer, pData->length,
                                                     str.data(), str.length(), maxLength );
    }
#else
    sal_Int32 compareTo( const OUString & str, sal_Int32 maxLength ) const
    {
        return rtl_ustr_shortenedCompare_WithLength( pData->buffer, pData->length,
                                                     str.pData->buffer, str.pData->length, maxLength );
    }
#endif

    /**
      Compares two strings in reverse order.

      The comparison is based on the numeric value of each character in
      the strings and return a value indicating their relationship.
      This function can't be used for language specific sorting.

      @param    str         the object to be compared.
      @return   0 - if both strings are equal
                < 0 - if this string is less than the string argument
                > 0 - if this string is greater than the string argument
    */

#if defined LIBO_INTERNAL_ONLY
    sal_Int32 reverseCompareTo(std::u16string_view sv) const {
        return rtl_ustr_reverseCompare_WithLength(
            pData->buffer, pData->length, sv.data(), sv.size());
    }
#else
    sal_Int32 reverseCompareTo( const OUString & str ) const
    {
        return rtl_ustr_reverseCompare_WithLength( pData->buffer, pData->length,
                                                   str.pData->buffer, str.pData->length );
    }
#endif

    /**
     @overload
     This function accepts an ASCII string literal as its argument.
     @since LibreOffice 4.1
    */

    templatetypename T >
    typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type reverseCompareTo( T& literal ) const
    {
        assert(
            libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
        return rtl_ustr_asciil_reverseCompare_WithLength(
            pData->buffer, pData->length,
            libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
            libreoffice_internal::ConstCharArrayDetector<T>::length);
    }

    /**
      Perform a comparison of two strings.

      The result is true if and only if second string
      represents the same sequence of characters as the first string.
      This function can't be used for language specific comparison.

      @param    str         the object to be compared.
      @return   true if the strings are equal;
                false, otherwise.
    */

    bool equals( const OUString & str ) const
    {
        if ( pData->length != str.pData->length )
            return false;
        if ( pData == str.pData )
            return true;
        return rtl_ustr_reverseCompare_WithLength( pData->buffer, pData->length,
                                                   str.pData->buffer, str.pData->length ) == 0;
    }

    /**
      Perform an ASCII lowercase comparison of two strings.

      The result is true if and only if second string
      represents the same sequence of characters as the first string,
      ignoring the case.
      Character values between 65 and 90 (ASCII A-Z) are interpreted as
      values between 97 and 122 (ASCII a-z).
      This function can't be used for language specific comparison.

      @param    str         the object to be compared.
      @return   true if the strings are equal;
                false, otherwise.
    */

#if defined LIBO_INTERNAL_ONLY
    bool equalsIgnoreAsciiCase(std::u16string_view sv) const {
        if ( sal_uInt32(pData->length) != sv.size() )
            return false;
        if ( pData->buffer == sv.data() )
            return true;
        return
            rtl_ustr_compareIgnoreAsciiCase_WithLength(
                pData->buffer, pData->length, sv.data(), sv.size())
            == 0;
    }
#else
    bool equalsIgnoreAsciiCase( const OUString & str ) const
    {
        if ( pData->length != str.pData->length )
            return false;
        if ( pData == str.pData )
            return true;
        return rtl_ustr_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
                                                           str.pData->buffer, str.pData->length ) == 0;
    }
#endif

    /**
      Perform an ASCII lowercase comparison of two strings.

      Compare the two strings with uppercase ASCII
      character values between 65 and 90 (ASCII A-Z) interpreted as
      values between 97 and 122 (ASCII a-z).
      This function can't be used for language specific comparison.

      @param    str         the object to be compared.
      @return   0 - if both strings are equal
                < 0 - if this string is less than the string argument
                > 0 - if this string is greater than the string argument

      @since LibreOffice 4.0
    */

#if defined LIBO_INTERNAL_ONLY
    sal_Int32 compareToIgnoreAsciiCase(std::u16string_view sv) const {
        return rtl_ustr_compareIgnoreAsciiCase_WithLength(
            pData->buffer, pData->length, sv.data(), sv.size());
    }
#else
    sal_Int32 compareToIgnoreAsciiCase( const OUString & str ) const
    {
        return rtl_ustr_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
                                                           str.pData->buffer, str.pData->length );
    }
#endif

    /**
     @overload
     This function accepts an ASCII string literal as its argument.
     @since LibreOffice 3.6
    */

    templatetypename T >
    typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type equalsIgnoreAsciiCase( T& literal ) const
    {
        assert(
            libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
        return
            (pData->length
             == libreoffice_internal::ConstCharArrayDetector<T>::length)
            && (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength(
                    pData->buffer, pData->length,
                    libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
                        literal))
                == 0);
    }

   /**
      Match against a substring appearing in this string.

      The result is true if and only if the second string appears as a substring
      of this string, at the given position.
      This function can't be used for language specific comparison.

      @param    str         the object (substring) to be compared.
      @param    fromIndex   the index to start the comparison from.
                            The index must be greater than or equal to 0
                            and less or equal as the string length.
      @return   true if str match with the characters in the string
                at the given position;
                false, otherwise.
    */

#if defined LIBO_INTERNAL_ONLY
    bool match(std::u16string_view sv, sal_Int32 fromIndex = 0) const {
        assert(fromIndex >= 0);
        return
            rtl_ustr_shortenedCompare_WithLength(
                pData->buffer + fromIndex, pData->length - fromIndex, sv.data(), sv.size(),
                sv.size())
            == 0;
    }
#else
    bool match( const OUString & str, sal_Int32 fromIndex = 0 ) const
    {
        assert(fromIndex >= 0);
        return rtl_ustr_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
                                                     str.pData->buffer, str.pData->length, str.pData->length ) == 0;
    }
#endif

    /**
     @overload
     This function accepts an ASCII string literal as its argument.
     @since LibreOffice 3.6
    */

    templatetypename T >
    typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type match( T& literal, sal_Int32 fromIndex = 0 ) const
    {
        assert(
            libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
        assert(fromIndex >= 0);
        return
            rtl_ustr_ascii_shortenedCompare_WithLength(
                pData->buffer+fromIndex, pData->length-fromIndex,
                libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
                    literal),
                libreoffice_internal::ConstCharArrayDetector<T>::length)
            == 0;
    }

    /**
      Match against a substring appearing in this string, ignoring the case of
      ASCII letters.

      The result is true if and only if the second string appears as a substring
      of this string, at the given position.
      Character values between 65 and 90 (ASCII A-Z) are interpreted as
      values between 97 and 122 (ASCII a-z).
      This function can't be used for language specific comparison.

      @param    str         the object (substring) to be compared.
      @param    fromIndex   the index to start the comparison from.
                            The index must be greater than or equal to 0
                            and less than or equal to the string length.
      @return   true if str match with the characters in the string
                at the given position;
                false, otherwise.
    */

#if defined LIBO_INTERNAL_ONLY
    bool matchIgnoreAsciiCase(std::u16string_view sv, sal_Int32 fromIndex = 0) const {
        assert(fromIndex >= 0);
        return
            rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength(
                pData->buffer + fromIndex, pData->length - fromIndex, sv.data(), sv.size(),
                sv.size())
            == 0;
    }
#else
    bool matchIgnoreAsciiCase( const OUString & str, sal_Int32 fromIndex = 0 ) const
    {
        assert(fromIndex >= 0);
        return rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
                                                                    str.pData->buffer, str.pData->length,
                                                                    str.pData->length ) == 0;
    }
#endif

    /**
     @overload
     This function accepts an ASCII string literal as its argument.
     @since LibreOffice 3.6
    */

    templatetypename T >
    typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type matchIgnoreAsciiCase( T& literal, sal_Int32 fromIndex = 0 ) const
    {
        assert(
            libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
        return matchIgnoreAsciiCaseAsciiL(
            libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
            libreoffice_internal::ConstCharArrayDetector<T>::length, fromIndex);
    }

    /**
      Compares two strings.

      The comparison is based on the numeric value of each character in
      the strings and return a value indicating their relationship.
      Since this method is optimized for performance, the ASCII character
      values are not converted in any way. The caller has to make sure that
      all ASCII characters are in the allowed range between 0 and 127.
      The ASCII string must be NULL-terminated.
      This function can't be used for language specific sorting.

      @param  asciiStr      the 8-Bit ASCII character string to be compared.
      @return   0 - if both strings are equal
                < 0 - if this string is less than the string argument
                > 0 - if this string is greater than the string argument
    */

    sal_Int32 compareToAscii( const char* asciiStr ) const
    {
        return rtl_ustr_ascii_compare_WithLength( pData->buffer, pData->length, asciiStr );
    }

    /**
      Compares two strings with a maximum count of characters.

      The comparison is based on the numeric value of each character in
      the strings and return a value indicating their relationship.
      Since this method is optimized for performance, the ASCII character
      values are not converted in any way. The caller has to make sure that
      all ASCII characters are in the allowed range between 0 and 127.
      The ASCII string must be NULL-terminated.
      This function can't be used for language specific sorting.

      @deprecated  This is a confusing overload with unexpectedly different
      semantics from the one-parameter form, so it is marked as deprecated.
      Practically all uses compare the return value against zero and can thus
      be replaced with uses of startsWith.

      @param  asciiStr          the 8-Bit ASCII character string to be compared.
      @param  maxLength         the maximum count of characters to be compared.
      @return   0 - if both strings are equal
                < 0 - if this string is less than the string argument
                > 0 - if this string is greater than the string argument
    */

    SAL_DEPRECATED(
        "replace s1.compareToAscii(s2, strlen(s2)) == 0 with s1.startsWith(s2)")
    sal_Int32 compareToAscii( const char * asciiStr, sal_Int32 maxLength ) const
    {
        return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer, pData->length,
                                                           asciiStr, maxLength );
    }

    /**
      Compares two strings in reverse order.

      This could be useful, if normally both strings start with the same
      content. The comparison is based on the numeric value of each character
      in the strings and return a value indicating their relationship.
      Since this method is optimized for performance, the ASCII character
      values are not converted in any way. The caller has to make sure that
      all ASCII characters are in the allowed range between 0 and 127.
      The ASCII string must be greater than or equal to asciiStrLength.
      This function can't be used for language specific sorting.

      @param    asciiStr        the 8-Bit ASCII character string to be compared.
      @param    asciiStrLength  the length of the ascii string
      @return   0 - if both strings are equal
                < 0 - if this string is less than the string argument
                > 0 - if this string is greater than the string argument
    */

    sal_Int32 reverseCompareToAsciiL( const char * asciiStr, sal_Int32 asciiStrLength ) const
    {
        return rtl_ustr_asciil_reverseCompare_WithLength( pData->buffer, pData->length,
                                                          asciiStr, asciiStrLength );
    }

    /**
      Perform a comparison of two strings.

      The result is true if and only if second string
      represents the same sequence of characters as the first string.
      Since this method is optimized for performance, the ASCII character
      values are not converted in any way. The caller has to make sure that
      all ASCII characters are in the allowed range between 0 and 127.
      The ASCII string must be NULL-terminated.
      This function can't be used for language specific comparison.

      @param    asciiStr        the 8-Bit ASCII character string to be compared.
      @return   true if the strings are equal;
                false, otherwise.
    */

    bool equalsAscii( const char* asciiStr ) const
    {
        return rtl_ustr_ascii_compare_WithLength( pData->buffer, pData->length,
                                                  asciiStr ) == 0;
    }

    /**
      Perform a comparison of two strings.

      The result is true if and only if second string
      represents the same sequence of characters as the first string.
      Since this method is optimized for performance, the ASCII character
      values are not converted in any way. The caller has to make sure that
      all ASCII characters are in the allowed range between 0 and 127.
      The ASCII string must be greater than or equal to asciiStrLength.
      This function can't be used for language specific comparison.

      @param    asciiStr         the 8-Bit ASCII character string to be compared.
      @param    asciiStrLength   the length of the ascii string
      @return   true if the strings are equal;
                false, otherwise.
    */

    bool equalsAsciiL( const char* asciiStr, sal_Int32 asciiStrLength ) const
    {
        if ( pData->length != asciiStrLength )
            return false;

        return rtl_ustr_asciil_reverseEquals_WithLength(
                    pData->buffer, asciiStr, asciiStrLength );
    }

    /**
      Perform an ASCII lowercase comparison of two strings.

      The result is true if and only if second string
      represents the same sequence of characters as the first string,
      ignoring the case.
      Character values between 65 and 90 (ASCII A-Z) are interpreted as
      values between 97 and 122 (ASCII a-z).
      Since this method is optimized for performance, the ASCII character
      values are not converted in any way. The caller has to make sure that
      all ASCII characters are in the allowed range between 0 and 127.
      The ASCII string must be NULL-terminated.
      This function can't be used for language specific comparison.

      @param    asciiStr        the 8-Bit ASCII character string to be compared.
      @return   true if the strings are equal;
                false, otherwise.
    */

    bool equalsIgnoreAsciiCaseAscii( const char * asciiStr ) const
    {
        return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr ) == 0;
    }

#if defined LIBO_INTERNAL_ONLY
    bool equalsIgnoreAsciiCaseAscii( std::string_view asciiStr ) const
    {
        return o3tl::make_unsigned(pData->length) == asciiStr.length()
               && rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
                      pData->buffer, pData->length, asciiStr.data(), asciiStr.length()) == 0;
    }
#endif

    /**
      Compares two ASCII strings ignoring case

      The comparison is based on the numeric value of each character in
      the strings and return a value indicating their relationship.
      Since this method is optimized for performance, the ASCII character
      values are not converted in any way. The caller has to make sure that
      all ASCII characters are in the allowed range between 0 and 127.
      The ASCII string must be NULL-terminated.
      This function can't be used for language specific sorting.

      @param  asciiStr      the 8-Bit ASCII character string to be compared.
      @return   0 - if both strings are equal
                < 0 - if this string is less than the string argument
                > 0 - if this string is greater than the string argument

      @since LibreOffice 3.5
    */

    sal_Int32 compareToIgnoreAsciiCaseAscii( const char * asciiStr ) const
    {
        return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr );
    }

#if defined LIBO_INTERNAL_ONLY
    sal_Int32 compareToIgnoreAsciiCaseAscii( std::string_view asciiStr ) const
    {
        sal_Int32 nMax = std::min<size_t>(asciiStr.length(), std::numeric_limits<sal_Int32>::max());
        sal_Int32 result = rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
            pData->buffer, pData->length, asciiStr.data(), nMax);
        if (result == 0 && o3tl::make_unsigned(pData->length) < asciiStr.length())
            result = -1;
        return result;
    }
#endif

    /**
      Perform an ASCII lowercase comparison of two strings.

      The result is true if and only if second string
      represents the same sequence of characters as the first string,
      ignoring the case.
      Character values between 65 and 90 (ASCII A-Z) are interpreted as
      values between 97 and 122 (ASCII a-z).
      Since this method is optimized for performance, the ASCII character
      values are not converted in any way. The caller has to make sure that
      all ASCII characters are in the allowed range between 0 and 127.
      The ASCII string must be greater than or equal to asciiStrLength.
      This function can't be used for language specific comparison.

      @param    asciiStr        the 8-Bit ASCII character string to be compared.
      @param    asciiStrLength  the length of the ascii string
      @return   true if the strings are equal;
                false, otherwise.
    */

    bool equalsIgnoreAsciiCaseAsciiL( const char * asciiStr, sal_Int32 asciiStrLength ) const
    {
        if ( pData->length != asciiStrLength )
            return false;

        return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr ) == 0;
    }

    /**
      Match against a substring appearing in this string.

      The result is true if and only if the second string appears as a substring
      of this string, at the given position.
      Since this method is optimized for performance, the ASCII character
      values are not converted in any way. The caller has to make sure that
      all ASCII characters are in the allowed range between 0 and 127.
      The ASCII string must be greater than or equal to asciiStrLength.
      This function can't be used for language specific comparison.

      @param    asciiStr    the object (substring) to be compared.
      @param    asciiStrLength the length of asciiStr.
      @param    fromIndex   the index to start the comparison from.
                            The index must be greater than or equal to 0
                            and less than or equal to the string length.
      @return   true if str match with the characters in the string
                at the given position;
                false, otherwise.
    */

    bool matchAsciiL( const char* asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex = 0 ) const
    {
        assert(fromIndex >= 0);
        return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
                                                           asciiStr, asciiStrLength ) == 0;
    }

    // This overload is left undefined, to detect calls of matchAsciiL that
    // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
    // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
    // platforms):
#if SAL_TYPES_SIZEOFLONG == 8
    void matchAsciiL(char const *, sal_Int32, rtl_TextEncoding) const;
#endif

    /**
      Match against a substring appearing in this string, ignoring the case of
      ASCII letters.

      The result is true if and only if the second string appears as a substring
      of this string, at the given position.
      Character values between 65 and 90 (ASCII A-Z) are interpreted as
      values between 97 and 122 (ASCII a-z).
      Since this method is optimized for performance, the ASCII character
      values are not converted in any way. The caller has to make sure that
      all ASCII characters are in the allowed range between 0 and 127.
      The ASCII string must be greater than or equal to asciiStrLength.
      This function can't be used for language specific comparison.

      @param    asciiStr        the 8-Bit ASCII character string to be compared.
      @param    asciiStrLength  the length of the ascii string
      @param    fromIndex       the index to start the comparison from.
                                The index must be greater than or equal to 0
                                and less than or equal to the string length.
      @return   true if str match with the characters in the string
                at the given position;
                false, otherwise.
    */

    bool matchIgnoreAsciiCaseAsciiL( const char* asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex = 0 ) const
    {
        assert(fromIndex >= 0);
        return rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
                                                                          asciiStr, asciiStrLength ) == 0;
    }

    // This overload is left undefined, to detect calls of
    // matchIgnoreAsciiCaseAsciiL that erroneously use
    // RTL_CONSTASCII_USTRINGPARAM instead of RTL_CONSTASCII_STRINGPARAM (but
    // would lead to ambiguities on 32 bit platforms):
#if SAL_TYPES_SIZEOFLONG == 8
    void matchIgnoreAsciiCaseAsciiL(char const *, sal_Int32, rtl_TextEncoding)
        const;
#endif

#if defined LIBO_INTERNAL_ONLY
    /**
      Check whether this string starts with a given substring.

      @param str the substring to be compared

      @return true if and only if the given str appears as a substring at the
      start of this string

      @since LibreOffice 4.0
    */

    bool startsWith(std::u16string_view sv) const {
        return match(sv);
    }
    /**
      Check whether this string starts with a given substring.

      @param str the substring to be compared

      @param rest if this function returns true, then assign a
      copy of the remainder of this string to *rest. Available since
      LibreOffice 4.2

      @return true if and only if the given str appears as a substring at the
      start of this string

      @since LibreOffice 4.0
    */

    bool startsWith(std::u16string_view sv, OUString * rest) const {
        assert(rest);
        auto const b = startsWith(sv);
        if (b) {
            *rest = copy(sv.size());
        }
        return b;
    }
    /**
      Check whether this string starts with a given substring.

      @param str the substring to be compared

      @param rest if this function returns true, then assign a
      copy of the remainder of this string to *rest.

      @return true if and only if the given str appears as a substring at the
      start of this string

      @since LibreOffice 25.2
    */

    bool startsWith(std::u16string_view sv, std::u16string_view * rest) const {
        assert(rest);
        auto const b = startsWith(sv);
        if (b) {
            *rest = subView(sv.size());
        }
        return b;
    }
#else
    /**
      Check whether this string starts with a given substring.

      @param str the substring to be compared

      @param rest if non-null, and this function returns true, then assign a
      copy of the remainder of this string to *rest. Available since
      LibreOffice 4.2

      @return true if and only if the given str appears as a substring at the
      start of this string

      @since LibreOffice 4.0
    */

    bool startsWith(OUString const & str, OUString * rest = NULL) const {
        bool b = match(str);
        if (b && rest != NULL) {
            *rest = copy(str.getLength());
        }
        return b;
    }
#endif

#if defined LIBO_INTERNAL_ONLY
    /**
     This function accepts an ASCII string literal as its argument.
     @since LibreOffice 25.2
    */

    templatetypename T >
    typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWith(
        T & literal) const
    {
        assert(
            libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
        bool b
            = (libreoffice_internal::ConstCharArrayDetector<T>::length
               <= sal_uInt32(pData->length))
            && rtl_ustr_asciil_reverseEquals_WithLength(
                pData->buffer,
                libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
                    literal),
                libreoffice_internal::ConstCharArrayDetector<T>::length);
        return b;
    }
    /**
     @overload
     This function accepts an ASCII string literal as its argument.
     @since LibreOffice 4.0
    */

    templatetypename T >
    typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWith(
        T & literal, OUString * rest) const
    {
        assert(rest);
        bool b = startsWith(literal);
        if (b) {
            *rest = copy(
                libreoffice_internal::ConstCharArrayDetector<T>::length);
        }
        return b;
    }
    /**
     This function accepts an ASCII string literal as its argument.
     @since LibreOffice 25.2
    */

    templatetypename T >
    typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWith(
        T & literal, std::u16string_view * rest) const
    {
        assert(rest);
        bool b = startsWith(literal);
        if (b) {
            *rest = subView(
                libreoffice_internal::ConstCharArrayDetector<T>::length);
        }
        return b;
    }
#else
    /**
     @overload
     This function accepts an ASCII string literal as its argument.
     @since LibreOffice 4.0
    */

    templatetypename T >
    typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWith(
        T & literal, OUString * rest = NULL) const
    {
        assert(
            libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
        bool b
            = (libreoffice_internal::ConstCharArrayDetector<T>::length
               <= sal_uInt32(pData->length))
            && rtl_ustr_asciil_reverseEquals_WithLength(
                pData->buffer,
                libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
                    literal),
                libreoffice_internal::ConstCharArrayDetector<T>::length);
        if (b && rest != NULL) {
            *rest = copy(
                libreoffice_internal::ConstCharArrayDetector<T>::length);
        }
        return b;
    }
#endif

    /**
      Check whether this string starts with a given string, ignoring the case of
      ASCII letters.

      Character values between 65 and 90 (ASCII A-Z) are interpreted as
      values between 97 and 122 (ASCII a-z).
      This function can't be used for language specific comparison.

      @param str the substring to be compared

      @param rest if non-null, and this function returns true, then assign a
      copy of the remainder of this string to *rest. Available since
      LibreOffice 4.2

      @return true if and only if the given str appears as a substring at the
      start of this string, ignoring the case of ASCII letters ("A"--"Z" and
      "a"--"z")

      @since LibreOffice 4.0
    */

#if defined LIBO_INTERNAL_ONLY
    bool startsWithIgnoreAsciiCase(std::u16string_view sv) const {
        return matchIgnoreAsciiCase(sv);
    }
    bool startsWithIgnoreAsciiCase(std::u16string_view sv, OUString * rest) const {
        assert(rest);
        auto const b = startsWithIgnoreAsciiCase(sv);
        if (b) {
            *rest = copy(sv.size());
        }
        return b;
    }
    bool startsWithIgnoreAsciiCase(std::u16string_view sv, std::u16string_view * rest) const {
        assert(rest);
        auto const b = startsWithIgnoreAsciiCase(sv);
        if (b) {
            *rest = subView(sv.size());
        }
        return b;
    }
#else
    bool startsWithIgnoreAsciiCase(OUString const & str, OUString * rest = NULL)
        const
    {
        bool b = matchIgnoreAsciiCase(str);
        if (b && rest != NULL) {
            *rest = copy(str.getLength());
        }
        return b;
    }
#endif

#if defined LIBO_INTERNAL_ONLY
    /**
     @overload
     This function accepts an ASCII string literal as its argument.
     @since LibreOffice 4.0
    */

    templatetypename T >
    typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
    startsWithIgnoreAsciiCase(T & literal) const
    {
        assert(
            libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
        bool b
            = (libreoffice_internal::ConstCharArrayDetector<T>::length
               <= sal_uInt32(pData->length))
            && (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
                   pData->buffer,
                   libreoffice_internal::ConstCharArrayDetector<T>::length,
                   libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
                       literal),
                   libreoffice_internal::ConstCharArrayDetector<T>::length)
               == 0);
        return b;
    }
    /**
     @overload
     This function accepts an ASCII string literal as its argument.
     @since LibreOffice 4.0
    */

    templatetypename T >
    typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
    startsWithIgnoreAsciiCase(T & literal, OUString * rest) const
    {
        assert(rest);
        bool b = startsWithIgnoreAsciiCase(literal);
        if (b) {
            *rest = copy(
                libreoffice_internal::ConstCharArrayDetector<T>::length);
        }
        return b;
    }
    /**
     This function accepts an ASCII string literal as its argument.
     @since LibreOffice 25.2
    */

    templatetypename T >
    typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
    startsWithIgnoreAsciiCase(T & literal, std::u16string_view * rest) const
    {
        assert(rest);
        bool b = startsWithIgnoreAsciiCase(literal);
        if (b) {
            *rest = subView(
                libreoffice_internal::ConstCharArrayDetector<T>::length);
        }
        return b;
    }
#else
    /**
     @overload
     This function accepts an ASCII string literal as its argument.
     @since LibreOffice 4.0
    */

    templatetypename T >
    typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
    startsWithIgnoreAsciiCase(T & literal, OUString * rest = NULL) const
    {
        assert(
            libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
        bool b
            = (libreoffice_internal::ConstCharArrayDetector<T>::length
               <= sal_uInt32(pData->length))
            && (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
                   pData->buffer,
                   libreoffice_internal::ConstCharArrayDetector<T>::length,
                   libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
                       literal),
                   libreoffice_internal::ConstCharArrayDetector<T>::length)
               == 0);
        if (b && rest != NULL) {
            *rest = copy(
                libreoffice_internal::ConstCharArrayDetector<T>::length);
        }
        return b;
    }
#endif

#if defined LIBO_INTERNAL_ONLY
    /**
      Check whether this string ends with a given substring.

      @param str the substring to be compared

      @return true if and only if the given str appears as a substring at the
      end of this string

      @since LibreOffice 3.6
    */

    bool endsWith(std::u16string_view sv) const {
        return sv.size() <= sal_uInt32(pData->length)
            && match(sv, pData->length - sv.size());
    }
    bool endsWith(std::u16string_view sv, OUString * rest) const {
        auto const b = endsWith(sv);
        if (b && rest != nullptr) {
            *rest = copy(0, (pData->length - sv.size()));
        }
        return b;
    }
    /**
      Check whether this string ends with a given substring.

      @param str the substring to be compared

      @param rest if this function returns true, then assign a
      copy of the remainder of this string to *rest.

      @return true if and only if the given str appears as a substring at the
      end of this string

      @since LibreOffice 25.2
    */

    bool endsWith(std::u16string_view sv, std::u16string_view * rest) const {
        assert(rest);
        auto const b = endsWith(sv);
        if (b) {
            *rest = subView(0, (pData->length - sv.size()));
        }
        return b;
    }
#else
    /**
      Check whether this string ends with a given substring.

      @param str the substring to be compared

      @param rest if non-null, and this function returns true, then assign a
      copy of the remainder of this string to *rest. Available since
      LibreOffice 4.2

      @return true if and only if the given str appears as a substring at the
      end of this string

      @since LibreOffice 3.6
    */

    bool endsWith(OUString const & str, OUString * rest = NULL) const {
        bool b = str.getLength() <= getLength()
            && match(str, getLength() - str.getLength());
        if (b && rest != NULL) {
            *rest = copy(0, getLength() - str.getLength());
        }
        return b;
    }
#endif

#if defined LIBO_INTERNAL_ONLY
    /**
     @overload
     This function accepts an ASCII string literal as its argument.
     @since LibreOffice 25.2
    */

    templatetypename T >
--> --------------------

--> maximum size reached

--> --------------------

Messung V0.5
C=92 H=93 G=92

¤ Dauer der Verarbeitung: 0.24 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.