no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / xpcom / string / nsTSubstringTuple.h
blobdff8dedca91308e265a35cc30a9384fc89480291
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"
14 /**
15 * nsTSubstringTuple
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.
23 template <typename T>
24 class MOZ_TEMPORARY_CLASS nsTSubstringTuple {
25 public:
26 typedef T char_type;
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;
33 public:
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)
39 : mHead(&aHead),
40 mFragA(nullptr), // this fragment is ignored when aHead != nullptr
41 mFragB(aStrB) {}
43 /**
44 * computes the aggregate string length
46 size_type Length() const;
48 /**
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;
55 /**
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;
61 /**
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
64 * tree only once.
66 std::pair<bool, size_type> IsDependentOnWithLength(
67 const char_type* aStart, const char_type* aEnd) const;
69 private:
70 const self_type* const mHead;
71 const base_string_type* const mFragA;
72 const base_string_type* const mFragB;
75 template <typename T>
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);
82 template <typename T>
83 inline const nsTSubstringTuple<T> operator+(
84 const nsTSubstringTuple<T>& aHead,
85 const mozilla::detail::nsTStringRepr<T>& aStrB) {
86 return nsTSubstringTuple<T>(aHead, &aStrB);
89 #endif