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/. */
9 * computes the aggregate string length
12 nsTSubstringTuple_CharT::size_type
13 nsTSubstringTuple_CharT::Length() const
17 len
= mHead
->Length();
19 len
= TO_SUBSTRING(mFragA
).Length();
22 return len
+ TO_SUBSTRING(mFragB
).Length();
27 * writes the aggregate string to the given buffer. aBufLen is assumed
28 * to be equal to or greater than the value returned by the Length()
29 * method. the string written to |aBuf| is not null-terminated.
33 nsTSubstringTuple_CharT::WriteTo(char_type
* aBuf
, uint32_t aBufLen
) const
35 const substring_type
& b
= TO_SUBSTRING(mFragB
);
37 NS_ASSERTION(aBufLen
>= b
.Length(), "buffer too small");
38 uint32_t headLen
= aBufLen
- b
.Length();
40 mHead
->WriteTo(aBuf
, headLen
);
42 const substring_type
& a
= TO_SUBSTRING(mFragA
);
44 NS_ASSERTION(a
.Length() == headLen
, "buffer incorrectly sized");
45 char_traits::copy(aBuf
, a
.Data(), a
.Length());
48 char_traits::copy(aBuf
+ headLen
, b
.Data(), b
.Length());
51 // we need to write out data into |aBuf|, ending at |aBuf + aBufLen|. So our
52 // data needs to precede |aBuf + aBufLen| exactly. We trust that the buffer
53 // was properly sized!
55 const substring_type
& b
= TO_SUBSTRING(mFragB
);
57 NS_ASSERTION(aBufLen
>= b
.Length(), "buffer is too small");
58 char_traits::copy(aBuf
+ aBufLen
- b
.Length(), b
.Data(), b
.Length());
60 aBufLen
-= b
.Length();
63 mHead
->WriteTo(aBuf
, aBufLen
);
65 const substring_type
& a
= TO_SUBSTRING(mFragA
);
66 NS_ASSERTION(aBufLen
== a
.Length(), "buffer is too small");
67 char_traits::copy(aBuf
, a
.Data(), a
.Length());
74 * returns true if this tuple is dependent on (i.e., overlapping with)
75 * the given char sequence.
79 nsTSubstringTuple_CharT::IsDependentOn(const char_type
* aStart
,
80 const char_type
* aEnd
) const
82 // we aStart with the right-most fragment since it is faster to check.
84 if (TO_SUBSTRING(mFragB
).IsDependentOn(aStart
, aEnd
)) {
89 return mHead
->IsDependentOn(aStart
, aEnd
);
92 return TO_SUBSTRING(mFragA
).IsDependentOn(aStart
, aEnd
);