2014-05-05 17:30:46 +00: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 11:12:37 +00: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/. */
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2016-12-02 18:35:35 +00:00
|
|
|
#include "mozilla/CheckedInt.h"
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
/**
|
|
|
|
* computes the aggregate string length
|
|
|
|
*/
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2017-08-14 21:22:50 +00:00
|
|
|
template <typename T>
|
|
|
|
typename nsTSubstringTuple<T>::size_type
|
|
|
|
nsTSubstringTuple<T>::Length() const
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2016-12-02 18:35:35 +00:00
|
|
|
mozilla::CheckedInt<size_type> len;
|
2014-05-27 07:15:35 +00:00
|
|
|
if (mHead) {
|
2014-05-05 17:30:46 +00:00
|
|
|
len = mHead->Length();
|
2014-05-27 07:15:35 +00:00
|
|
|
} else {
|
2017-03-13 21:02:55 +00:00
|
|
|
len = mFragA->Length();
|
2014-05-27 07:15:35 +00:00
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2017-03-13 21:02:55 +00:00
|
|
|
len += mFragB->Length();
|
2016-12-02 18:35:35 +00:00
|
|
|
MOZ_RELEASE_ASSERT(len.isValid(), "Substring tuple length is invalid");
|
|
|
|
return len.value();
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
/**
|
2014-05-27 07:15:35 +00:00
|
|
|
* writes the aggregate string to the given buffer. aBufLen is assumed
|
2014-05-05 17:30:46 +00:00
|
|
|
* to be equal to or greater than the value returned by the Length()
|
2014-05-27 07:15:35 +00:00
|
|
|
* method. the string written to |aBuf| is not null-terminated.
|
2014-05-05 17:30:46 +00:00
|
|
|
*/
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2017-08-14 21:22:50 +00:00
|
|
|
template <typename T>
|
2004-02-19 02:44:03 +00:00
|
|
|
void
|
2017-08-14 21:22:50 +00:00
|
|
|
nsTSubstringTuple<T>::WriteTo(char_type* aBuf, uint32_t aBufLen) const
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2017-03-13 21:02:55 +00:00
|
|
|
MOZ_RELEASE_ASSERT(aBufLen >= mFragB->Length(), "buffer too small");
|
|
|
|
uint32_t headLen = aBufLen - mFragB->Length();
|
2014-05-27 07:15:35 +00:00
|
|
|
if (mHead) {
|
|
|
|
mHead->WriteTo(aBuf, headLen);
|
|
|
|
} else {
|
2017-03-13 21:02:55 +00:00
|
|
|
MOZ_RELEASE_ASSERT(mFragA->Length() == headLen, "buffer incorrectly sized");
|
|
|
|
char_traits::copy(aBuf, mFragA->Data(), mFragA->Length());
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2017-03-13 21:02:55 +00:00
|
|
|
char_traits::copy(aBuf + headLen, mFragB->Data(), mFragB->Length());
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
/**
|
|
|
|
* returns true if this tuple is dependent on (i.e., overlapping with)
|
|
|
|
* the given char sequence.
|
|
|
|
*/
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2017-08-14 21:22:50 +00:00
|
|
|
template <typename T>
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2017-08-14 21:22:50 +00:00
|
|
|
nsTSubstringTuple<T>::IsDependentOn(const char_type* aStart,
|
|
|
|
const char_type* aEnd) const
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-08-25 19:17:15 +00:00
|
|
|
// we aStart with the right-most fragment since it is faster to check.
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2017-03-13 21:02:55 +00:00
|
|
|
if (mFragB->IsDependentOn(aStart, aEnd)) {
|
2014-05-05 17:30:46 +00:00
|
|
|
return true;
|
2014-05-27 07:15:35 +00:00
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
if (mHead) {
|
2014-08-25 19:17:15 +00:00
|
|
|
return mHead->IsDependentOn(aStart, aEnd);
|
2014-05-27 07:15:35 +00:00
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2017-03-13 21:02:55 +00:00
|
|
|
return mFragA->IsDependentOn(aStart, aEnd);
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|