xpcom/string/src/nsTString.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/string/src/nsTString.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,50 @@
     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 +nsTAdoptingString_CharT&
    1.11 +nsTAdoptingString_CharT::operator=( const self_type& str )
    1.12 +  {
    1.13 +    // This'll violate the constness of this argument, that's just
    1.14 +    // the nature of this class...
    1.15 +    self_type* mutable_str = const_cast<self_type*>(&str);
    1.16 +
    1.17 +    if (str.mFlags & F_OWNED)
    1.18 +      {
    1.19 +        // We want to do what Adopt() does, but without actually incrementing
    1.20 +        // the Adopt count.  Note that we can be a little more straightforward
    1.21 +        // about this than Adopt() is, because we know that str.mData is
    1.22 +        // non-null.  Should we be able to assert that str is not void here?
    1.23 +        NS_ASSERTION(str.mData, "String with null mData?");
    1.24 +        Finalize();
    1.25 +        mData = str.mData;
    1.26 +        mLength = str.mLength;
    1.27 +        SetDataFlags(F_TERMINATED | F_OWNED);
    1.28 +
    1.29 +        // Make str forget the buffer we just took ownership of.
    1.30 +        new (mutable_str) self_type();
    1.31 +      }
    1.32 +    else
    1.33 +      {
    1.34 +        Assign(str);
    1.35 +
    1.36 +        mutable_str->Truncate();
    1.37 +      }
    1.38 +
    1.39 +    return *this;
    1.40 +  }
    1.41 +
    1.42 +void
    1.43 +nsTString_CharT::Rebind( const char_type* data, size_type length )
    1.44 +  {
    1.45 +    // If we currently own a buffer, release it.
    1.46 +    Finalize();
    1.47 +
    1.48 +    mData = const_cast<char_type*>(data);
    1.49 +    mLength = length;
    1.50 +    SetDataFlags(F_TERMINATED);
    1.51 +    AssertValidDepedentString();
    1.52 +  }
    1.53 +

mercurial