1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 // IWYU pragma: private, include "nsString.h"
8 #ifndef nsTSubstringTuple_h
9 #define nsTSubstringTuple_h
11 #include "mozilla/Attributes.h"
12 #include "nsTStringRepr.h"
17 * Represents a tuple of string fragments. Built as a recursive binary tree.
18 * It is used to implement the concatenation of two or more string objects.
20 * NOTE: This class is a private implementation detail and should never be
21 * referenced outside the string code.
24 class MOZ_TEMPORARY_CLASS nsTSubstringTuple
{
27 typedef nsCharTraits
<char_type
> char_traits
;
29 typedef nsTSubstringTuple
<T
> self_type
;
30 typedef mozilla::detail::nsTStringRepr
<char_type
> base_string_type
;
31 typedef size_t size_type
;
34 nsTSubstringTuple(const base_string_type
* aStrA
,
35 const base_string_type
* aStrB
)
36 : mHead(nullptr), mFragA(aStrA
), mFragB(aStrB
) {}
38 nsTSubstringTuple(const self_type
& aHead
, const base_string_type
* aStrB
)
40 mFragA(nullptr), // this fragment is ignored when aHead != nullptr
44 * computes the aggregate string length
46 size_type
Length() const;
49 * writes the aggregate string to the given buffer. bufLen is assumed
50 * to be equal to or greater than the value returned by the Length()
51 * method. the string written to |buf| is not null-terminated.
53 void WriteTo(char_type
* aBuf
, size_type aBufLen
) const;
56 * returns true if this tuple is dependent on (i.e., overlapping with)
57 * the given char sequence.
59 bool IsDependentOn(const char_type
* aStart
, const char_type
* aEnd
) const;
62 * returns a pair of the results of IsDependentOn() and Length(). This is more
63 * efficient than calling both functions subsequently, as this traverses the
66 std::pair
<bool, size_type
> IsDependentOnWithLength(
67 const char_type
* aStart
, const char_type
* aEnd
) const;
70 const self_type
* const mHead
;
71 const base_string_type
* const mFragA
;
72 const base_string_type
* const mFragB
;
76 inline const nsTSubstringTuple
<T
> operator+(
77 const mozilla::detail::nsTStringRepr
<T
>& aStrA
,
78 const mozilla::detail::nsTStringRepr
<T
>& aStrB
) {
79 return nsTSubstringTuple
<T
>(&aStrA
, &aStrB
);
83 inline const nsTSubstringTuple
<T
> operator+(
84 const nsTSubstringTuple
<T
>& aHead
,
85 const mozilla::detail::nsTStringRepr
<T
>& aStrB
) {
86 return nsTSubstringTuple
<T
>(aHead
, &aStrB
);