2014-05-05 10:30:46 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
2014-05-05 10:30:46 -07:00
|
|
|
/**
|
|
|
|
* computes the aggregate string length
|
|
|
|
*/
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsTSubstringTuple_CharT::size_type
|
|
|
|
nsTSubstringTuple_CharT::Length() const
|
2014-05-05 10:30:46 -07:00
|
|
|
{
|
|
|
|
uint32_t len;
|
2014-05-27 00:15:35 -07:00
|
|
|
if (mHead) {
|
2014-05-05 10:30:46 -07:00
|
|
|
len = mHead->Length();
|
2014-05-27 00:15:35 -07:00
|
|
|
} else {
|
2014-05-05 10:30:46 -07:00
|
|
|
len = TO_SUBSTRING(mFragA).Length();
|
2014-05-27 00:15:35 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-05-05 10:30:46 -07:00
|
|
|
return len + TO_SUBSTRING(mFragB).Length();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
2014-05-05 10:30:46 -07:00
|
|
|
/**
|
2014-05-27 00:15:35 -07:00
|
|
|
* writes the aggregate string to the given buffer. aBufLen is assumed
|
2014-05-05 10:30:46 -07:00
|
|
|
* to be equal to or greater than the value returned by the Length()
|
2014-05-27 00:15:35 -07:00
|
|
|
* method. the string written to |aBuf| is not null-terminated.
|
2014-05-05 10:30:46 -07:00
|
|
|
*/
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
void
|
2014-05-27 00:15:35 -07:00
|
|
|
nsTSubstringTuple_CharT::WriteTo(char_type* aBuf, uint32_t aBufLen) const
|
2014-05-05 10:30:46 -07:00
|
|
|
{
|
|
|
|
const substring_type& b = TO_SUBSTRING(mFragB);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-05-27 00:15:35 -07:00
|
|
|
NS_ASSERTION(aBufLen >= b.Length(), "buffer too small");
|
|
|
|
uint32_t headLen = aBufLen - b.Length();
|
|
|
|
if (mHead) {
|
|
|
|
mHead->WriteTo(aBuf, headLen);
|
|
|
|
} else {
|
2014-05-05 10:30:46 -07:00
|
|
|
const substring_type& a = TO_SUBSTRING(mFragA);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-05-05 10:30:46 -07:00
|
|
|
NS_ASSERTION(a.Length() == headLen, "buffer incorrectly sized");
|
2014-05-27 00:15:35 -07:00
|
|
|
char_traits::copy(aBuf, a.Data(), a.Length());
|
2014-05-05 10:30:46 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-05-27 00:15:35 -07:00
|
|
|
char_traits::copy(aBuf + headLen, b.Data(), b.Length());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#if 0
|
2014-05-27 00:15:35 -07:00
|
|
|
// we need to write out data into |aBuf|, ending at |aBuf + aBufLen|. So our
|
|
|
|
// data needs to precede |aBuf + aBufLen| exactly. We trust that the buffer
|
2014-05-05 10:30:46 -07:00
|
|
|
// was properly sized!
|
|
|
|
|
|
|
|
const substring_type& b = TO_SUBSTRING(mFragB);
|
|
|
|
|
2014-05-27 00:15:35 -07:00
|
|
|
NS_ASSERTION(aBufLen >= b.Length(), "buffer is too small");
|
|
|
|
char_traits::copy(aBuf + aBufLen - b.Length(), b.Data(), b.Length());
|
2014-05-05 10:30:46 -07:00
|
|
|
|
2014-05-27 00:15:35 -07:00
|
|
|
aBufLen -= b.Length();
|
2014-05-05 10:30:46 -07:00
|
|
|
|
2014-05-27 00:15:35 -07:00
|
|
|
if (mHead) {
|
|
|
|
mHead->WriteTo(aBuf, aBufLen);
|
|
|
|
} else {
|
2014-05-05 10:30:46 -07:00
|
|
|
const substring_type& a = TO_SUBSTRING(mFragA);
|
2014-05-27 00:15:35 -07:00
|
|
|
NS_ASSERTION(aBufLen == a.Length(), "buffer is too small");
|
|
|
|
char_traits::copy(aBuf, a.Data(), a.Length());
|
2014-05-05 10:30:46 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
2014-05-05 10:30:46 -07:00
|
|
|
/**
|
|
|
|
* returns true if this tuple is dependent on (i.e., overlapping with)
|
|
|
|
* the given char sequence.
|
|
|
|
*/
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2014-08-25 12:17:15 -07:00
|
|
|
nsTSubstringTuple_CharT::IsDependentOn(const char_type* aStart,
|
|
|
|
const char_type* aEnd) const
|
2014-05-05 10:30:46 -07:00
|
|
|
{
|
2014-08-25 12:17:15 -07:00
|
|
|
// we aStart with the right-most fragment since it is faster to check.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-08-25 12:17:15 -07:00
|
|
|
if (TO_SUBSTRING(mFragB).IsDependentOn(aStart, aEnd)) {
|
2014-05-05 10:30:46 -07:00
|
|
|
return true;
|
2014-05-27 00:15:35 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-05-27 00:15:35 -07:00
|
|
|
if (mHead) {
|
2014-08-25 12:17:15 -07:00
|
|
|
return mHead->IsDependentOn(aStart, aEnd);
|
2014-05-27 00:15:35 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-08-25 12:17:15 -07:00
|
|
|
return TO_SUBSTRING(mFragA).IsDependentOn(aStart, aEnd);
|
2014-05-05 10:30:46 -07:00
|
|
|
}
|