1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/string/src/nsTSubstringTuple.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,95 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim:set ts=2 sw=2 sts=2 et cindent: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 + 1.11 + /** 1.12 + * computes the aggregate string length 1.13 + */ 1.14 + 1.15 +nsTSubstringTuple_CharT::size_type 1.16 +nsTSubstringTuple_CharT::Length() const 1.17 + { 1.18 + uint32_t len; 1.19 + if (mHead) 1.20 + len = mHead->Length(); 1.21 + else 1.22 + len = TO_SUBSTRING(mFragA).Length(); 1.23 + 1.24 + return len + TO_SUBSTRING(mFragB).Length(); 1.25 + } 1.26 + 1.27 + 1.28 + /** 1.29 + * writes the aggregate string to the given buffer. bufLen is assumed 1.30 + * to be equal to or greater than the value returned by the Length() 1.31 + * method. the string written to |buf| is not null-terminated. 1.32 + */ 1.33 + 1.34 +void 1.35 +nsTSubstringTuple_CharT::WriteTo( char_type *buf, uint32_t bufLen ) const 1.36 + { 1.37 + const substring_type& b = TO_SUBSTRING(mFragB); 1.38 + 1.39 + NS_ASSERTION(bufLen >= b.Length(), "buffer too small"); 1.40 + uint32_t headLen = bufLen - b.Length(); 1.41 + if (mHead) 1.42 + { 1.43 + mHead->WriteTo(buf, headLen); 1.44 + } 1.45 + else 1.46 + { 1.47 + const substring_type& a = TO_SUBSTRING(mFragA); 1.48 + 1.49 + NS_ASSERTION(a.Length() == headLen, "buffer incorrectly sized"); 1.50 + char_traits::copy(buf, a.Data(), a.Length()); 1.51 + } 1.52 + 1.53 + char_traits::copy(buf + headLen, b.Data(), b.Length()); 1.54 + 1.55 +#if 0 1.56 + // we need to write out data into |buf|, ending at |buf+bufLen|. so our 1.57 + // data needs to precede |buf+bufLen| exactly. we trust that the buffer 1.58 + // was properly sized! 1.59 + 1.60 + const substring_type& b = TO_SUBSTRING(mFragB); 1.61 + 1.62 + NS_ASSERTION(bufLen >= b.Length(), "buffer is too small"); 1.63 + char_traits::copy(buf + bufLen - b.Length(), b.Data(), b.Length()); 1.64 + 1.65 + bufLen -= b.Length(); 1.66 + 1.67 + if (mHead) 1.68 + { 1.69 + mHead->WriteTo(buf, bufLen); 1.70 + } 1.71 + else 1.72 + { 1.73 + const substring_type& a = TO_SUBSTRING(mFragA); 1.74 + NS_ASSERTION(bufLen == a.Length(), "buffer is too small"); 1.75 + char_traits::copy(buf, a.Data(), a.Length()); 1.76 + } 1.77 +#endif 1.78 + } 1.79 + 1.80 + 1.81 + /** 1.82 + * returns true if this tuple is dependent on (i.e., overlapping with) 1.83 + * the given char sequence. 1.84 + */ 1.85 + 1.86 +bool 1.87 +nsTSubstringTuple_CharT::IsDependentOn( const char_type *start, const char_type *end ) const 1.88 + { 1.89 + // we start with the right-most fragment since it is faster to check. 1.90 + 1.91 + if (TO_SUBSTRING(mFragB).IsDependentOn(start, end)) 1.92 + return true; 1.93 + 1.94 + if (mHead) 1.95 + return mHead->IsDependentOn(start, end); 1.96 + 1.97 + return TO_SUBSTRING(mFragA).IsDependentOn(start, end); 1.98 + }