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: nsTAdoptingString_CharT& michael@0: nsTAdoptingString_CharT::operator=( const self_type& str ) michael@0: { michael@0: // This'll violate the constness of this argument, that's just michael@0: // the nature of this class... michael@0: self_type* mutable_str = const_cast(&str); michael@0: michael@0: if (str.mFlags & F_OWNED) michael@0: { michael@0: // We want to do what Adopt() does, but without actually incrementing michael@0: // the Adopt count. Note that we can be a little more straightforward michael@0: // about this than Adopt() is, because we know that str.mData is michael@0: // non-null. Should we be able to assert that str is not void here? michael@0: NS_ASSERTION(str.mData, "String with null mData?"); michael@0: Finalize(); michael@0: mData = str.mData; michael@0: mLength = str.mLength; michael@0: SetDataFlags(F_TERMINATED | F_OWNED); michael@0: michael@0: // Make str forget the buffer we just took ownership of. michael@0: new (mutable_str) self_type(); michael@0: } michael@0: else michael@0: { michael@0: Assign(str); michael@0: michael@0: mutable_str->Truncate(); michael@0: } michael@0: michael@0: return *this; michael@0: } michael@0: michael@0: void michael@0: nsTString_CharT::Rebind( const char_type* data, size_type length ) michael@0: { michael@0: // If we currently own a buffer, release it. michael@0: Finalize(); michael@0: michael@0: mData = const_cast(data); michael@0: mLength = length; michael@0: SetDataFlags(F_TERMINATED); michael@0: AssertValidDepedentString(); michael@0: } michael@0: