michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et cindent: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: /** michael@0: * computes the aggregate string length michael@0: */ michael@0: michael@0: nsTSubstringTuple_CharT::size_type michael@0: nsTSubstringTuple_CharT::Length() const michael@0: { michael@0: uint32_t len; michael@0: if (mHead) michael@0: len = mHead->Length(); michael@0: else michael@0: len = TO_SUBSTRING(mFragA).Length(); michael@0: michael@0: return len + TO_SUBSTRING(mFragB).Length(); michael@0: } michael@0: michael@0: michael@0: /** michael@0: * writes the aggregate string to the given buffer. bufLen is assumed michael@0: * to be equal to or greater than the value returned by the Length() michael@0: * method. the string written to |buf| is not null-terminated. michael@0: */ michael@0: michael@0: void michael@0: nsTSubstringTuple_CharT::WriteTo( char_type *buf, uint32_t bufLen ) const michael@0: { michael@0: const substring_type& b = TO_SUBSTRING(mFragB); michael@0: michael@0: NS_ASSERTION(bufLen >= b.Length(), "buffer too small"); michael@0: uint32_t headLen = bufLen - b.Length(); michael@0: if (mHead) michael@0: { michael@0: mHead->WriteTo(buf, headLen); michael@0: } michael@0: else michael@0: { michael@0: const substring_type& a = TO_SUBSTRING(mFragA); michael@0: michael@0: NS_ASSERTION(a.Length() == headLen, "buffer incorrectly sized"); michael@0: char_traits::copy(buf, a.Data(), a.Length()); michael@0: } michael@0: michael@0: char_traits::copy(buf + headLen, b.Data(), b.Length()); michael@0: michael@0: #if 0 michael@0: // we need to write out data into |buf|, ending at |buf+bufLen|. so our michael@0: // data needs to precede |buf+bufLen| exactly. we trust that the buffer michael@0: // was properly sized! michael@0: michael@0: const substring_type& b = TO_SUBSTRING(mFragB); michael@0: michael@0: NS_ASSERTION(bufLen >= b.Length(), "buffer is too small"); michael@0: char_traits::copy(buf + bufLen - b.Length(), b.Data(), b.Length()); michael@0: michael@0: bufLen -= b.Length(); michael@0: michael@0: if (mHead) michael@0: { michael@0: mHead->WriteTo(buf, bufLen); michael@0: } michael@0: else michael@0: { michael@0: const substring_type& a = TO_SUBSTRING(mFragA); michael@0: NS_ASSERTION(bufLen == a.Length(), "buffer is too small"); michael@0: char_traits::copy(buf, a.Data(), a.Length()); michael@0: } michael@0: #endif michael@0: } michael@0: michael@0: michael@0: /** michael@0: * returns true if this tuple is dependent on (i.e., overlapping with) michael@0: * the given char sequence. michael@0: */ michael@0: michael@0: bool michael@0: nsTSubstringTuple_CharT::IsDependentOn( const char_type *start, const char_type *end ) const michael@0: { michael@0: // we start with the right-most fragment since it is faster to check. michael@0: michael@0: if (TO_SUBSTRING(mFragB).IsDependentOn(start, end)) michael@0: return true; michael@0: michael@0: if (mHead) michael@0: return mHead->IsDependentOn(start, end); michael@0: michael@0: return TO_SUBSTRING(mFragA).IsDependentOn(start, end); michael@0: }