Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim:set ts=2 sw=2 sts=2 et cindent: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | |
michael@0 | 8 | /** |
michael@0 | 9 | * computes the aggregate string length |
michael@0 | 10 | */ |
michael@0 | 11 | |
michael@0 | 12 | nsTSubstringTuple_CharT::size_type |
michael@0 | 13 | nsTSubstringTuple_CharT::Length() const |
michael@0 | 14 | { |
michael@0 | 15 | uint32_t len; |
michael@0 | 16 | if (mHead) |
michael@0 | 17 | len = mHead->Length(); |
michael@0 | 18 | else |
michael@0 | 19 | len = TO_SUBSTRING(mFragA).Length(); |
michael@0 | 20 | |
michael@0 | 21 | return len + TO_SUBSTRING(mFragB).Length(); |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | |
michael@0 | 25 | /** |
michael@0 | 26 | * writes the aggregate string to the given buffer. bufLen is assumed |
michael@0 | 27 | * to be equal to or greater than the value returned by the Length() |
michael@0 | 28 | * method. the string written to |buf| is not null-terminated. |
michael@0 | 29 | */ |
michael@0 | 30 | |
michael@0 | 31 | void |
michael@0 | 32 | nsTSubstringTuple_CharT::WriteTo( char_type *buf, uint32_t bufLen ) const |
michael@0 | 33 | { |
michael@0 | 34 | const substring_type& b = TO_SUBSTRING(mFragB); |
michael@0 | 35 | |
michael@0 | 36 | NS_ASSERTION(bufLen >= b.Length(), "buffer too small"); |
michael@0 | 37 | uint32_t headLen = bufLen - b.Length(); |
michael@0 | 38 | if (mHead) |
michael@0 | 39 | { |
michael@0 | 40 | mHead->WriteTo(buf, headLen); |
michael@0 | 41 | } |
michael@0 | 42 | else |
michael@0 | 43 | { |
michael@0 | 44 | const substring_type& a = TO_SUBSTRING(mFragA); |
michael@0 | 45 | |
michael@0 | 46 | NS_ASSERTION(a.Length() == headLen, "buffer incorrectly sized"); |
michael@0 | 47 | char_traits::copy(buf, a.Data(), a.Length()); |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | char_traits::copy(buf + headLen, b.Data(), b.Length()); |
michael@0 | 51 | |
michael@0 | 52 | #if 0 |
michael@0 | 53 | // we need to write out data into |buf|, ending at |buf+bufLen|. so our |
michael@0 | 54 | // data needs to precede |buf+bufLen| exactly. we trust that the buffer |
michael@0 | 55 | // was properly sized! |
michael@0 | 56 | |
michael@0 | 57 | const substring_type& b = TO_SUBSTRING(mFragB); |
michael@0 | 58 | |
michael@0 | 59 | NS_ASSERTION(bufLen >= b.Length(), "buffer is too small"); |
michael@0 | 60 | char_traits::copy(buf + bufLen - b.Length(), b.Data(), b.Length()); |
michael@0 | 61 | |
michael@0 | 62 | bufLen -= b.Length(); |
michael@0 | 63 | |
michael@0 | 64 | if (mHead) |
michael@0 | 65 | { |
michael@0 | 66 | mHead->WriteTo(buf, bufLen); |
michael@0 | 67 | } |
michael@0 | 68 | else |
michael@0 | 69 | { |
michael@0 | 70 | const substring_type& a = TO_SUBSTRING(mFragA); |
michael@0 | 71 | NS_ASSERTION(bufLen == a.Length(), "buffer is too small"); |
michael@0 | 72 | char_traits::copy(buf, a.Data(), a.Length()); |
michael@0 | 73 | } |
michael@0 | 74 | #endif |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | |
michael@0 | 78 | /** |
michael@0 | 79 | * returns true if this tuple is dependent on (i.e., overlapping with) |
michael@0 | 80 | * the given char sequence. |
michael@0 | 81 | */ |
michael@0 | 82 | |
michael@0 | 83 | bool |
michael@0 | 84 | nsTSubstringTuple_CharT::IsDependentOn( const char_type *start, const char_type *end ) const |
michael@0 | 85 | { |
michael@0 | 86 | // we start with the right-most fragment since it is faster to check. |
michael@0 | 87 | |
michael@0 | 88 | if (TO_SUBSTRING(mFragB).IsDependentOn(start, end)) |
michael@0 | 89 | return true; |
michael@0 | 90 | |
michael@0 | 91 | if (mHead) |
michael@0 | 92 | return mHead->IsDependentOn(start, end); |
michael@0 | 93 | |
michael@0 | 94 | return TO_SUBSTRING(mFragA).IsDependentOn(start, end); |
michael@0 | 95 | } |