xpcom/string/src/nsTSubstringTuple.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial