Bumping manifests a=b2g-bump
[gecko.git] / xpcom / string / nsTSubstringTuple.cpp
blob75c3c9728c9cf9c0d69d76c19ad203d7cd0433c3
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/. */
8 /**
9 * computes the aggregate string length
12 nsTSubstringTuple_CharT::size_type
13 nsTSubstringTuple_CharT::Length() const
15 uint32_t len;
16 if (mHead) {
17 len = mHead->Length();
18 } else {
19 len = TO_SUBSTRING(mFragA).Length();
22 return len + TO_SUBSTRING(mFragB).Length();
26 /**
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.
32 void
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();
39 if (mHead) {
40 mHead->WriteTo(aBuf, headLen);
41 } else {
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());
50 #if 0
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();
62 if (mHead) {
63 mHead->WriteTo(aBuf, aBufLen);
64 } else {
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());
69 #endif
73 /**
74 * returns true if this tuple is dependent on (i.e., overlapping with)
75 * the given char sequence.
78 bool
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)) {
85 return true;
88 if (mHead) {
89 return mHead->IsDependentOn(aStart, aEnd);
92 return TO_SUBSTRING(mFragA).IsDependentOn(aStart, aEnd);