From 85316040d32d6f491e77bbf46c5c36e1efcf4458 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 4 Sep 2013 16:43:12 -0400 Subject: [PATCH] Bug 910795 part 1. Add a way to Rebind() an nsString to be a dependent string. r=bsmedberg --- xpcom/string/public/nsTDependentString.h | 20 ++++---------------- xpcom/string/public/nsTString.h | 14 +++++++++++++- xpcom/string/src/nsTDependentString.cpp | 12 ------------ xpcom/string/src/nsTString.cpp | 12 ++++++++++++ 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/xpcom/string/public/nsTDependentString.h b/xpcom/string/public/nsTDependentString.h index 530d9316e7cf..4ed17315ce73 100644 --- a/xpcom/string/public/nsTDependentString.h +++ b/xpcom/string/public/nsTDependentString.h @@ -24,17 +24,6 @@ class nsTDependentString_CharT : public nsTString_CharT public: - /** - * verify restrictions - */ - void AssertValid() - { - NS_ASSERTION(mData, "nsTDependentString must wrap a non-NULL buffer"); - NS_ASSERTION(mLength != size_type(-1), "nsTDependentString has bogus length"); - NS_ASSERTION(mData[mLength] == 0, "nsTDependentString must wrap only null-terminated strings"); - } - - /** * constructors */ @@ -42,20 +31,20 @@ class nsTDependentString_CharT : public nsTString_CharT nsTDependentString_CharT( const char_type* start, const char_type* end ) : string_type(const_cast(start), uint32_t(end - start), F_TERMINATED) { - AssertValid(); + AssertValidDepedentString(); } nsTDependentString_CharT( const char_type* data, uint32_t length ) : string_type(const_cast(data), length, F_TERMINATED) { - AssertValid(); + AssertValidDepedentString(); } explicit nsTDependentString_CharT( const char_type* data ) : string_type(const_cast(data), uint32_t(char_traits::length(data)), F_TERMINATED) { - AssertValid(); + AssertValidDepedentString(); } nsTDependentString_CharT( const string_type& str, uint32_t startPos ) @@ -78,13 +67,12 @@ class nsTDependentString_CharT : public nsTString_CharT * allow this class to be bound to a different string... */ + using nsTString_CharT::Rebind; void Rebind( const char_type* data ) { Rebind(data, uint32_t(char_traits::length(data))); } - void Rebind( const char_type* data, size_type length ); - void Rebind( const char_type* start, const char_type* end ) { Rebind(start, uint32_t(end - start)); diff --git a/xpcom/string/public/nsTString.h b/xpcom/string/public/nsTString.h index be633bd56e27..ca694736f26c 100644 --- a/xpcom/string/public/nsTString.h +++ b/xpcom/string/public/nsTString.h @@ -358,6 +358,18 @@ class nsTString_CharT : public nsTSubstring_CharT #endif // !MOZ_STRING_WITH_OBSOLETE_API + void Rebind( const char_type* data, size_type length ); + + /** + * verify restrictions for dependent strings + */ + void AssertValidDepedentString() + { + NS_ASSERTION(mData, "nsTDependentString must wrap a non-NULL buffer"); + NS_ASSERTION(mLength != size_type(-1), "nsTDependentString has bogus length"); + NS_ASSERTION(mData[mLength] == 0, "nsTDependentString must wrap only null-terminated strings"); + } + protected: @@ -368,7 +380,7 @@ class nsTString_CharT : public nsTSubstring_CharT // allow subclasses to initialize fields directly nsTString_CharT( char_type* data, size_type length, uint32_t flags ) : substring_type(data, length, flags) {} - }; +}; class nsTFixedString_CharT : public nsTString_CharT diff --git a/xpcom/string/src/nsTDependentString.cpp b/xpcom/string/src/nsTDependentString.cpp index f9c401f153c1..230df222036e 100644 --- a/xpcom/string/src/nsTDependentString.cpp +++ b/xpcom/string/src/nsTDependentString.cpp @@ -4,18 +4,6 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -void -nsTDependentString_CharT::Rebind( const char_type* data, size_type length ) - { - // If we currently own a buffer, release it. - Finalize(); - - mData = const_cast(data); - mLength = length; - SetDataFlags(F_TERMINATED); - AssertValid(); - } - void nsTDependentString_CharT::Rebind( const string_type& str, uint32_t startPos ) { diff --git a/xpcom/string/src/nsTString.cpp b/xpcom/string/src/nsTString.cpp index 4957e82edb8f..561e99eef71e 100644 --- a/xpcom/string/src/nsTString.cpp +++ b/xpcom/string/src/nsTString.cpp @@ -36,3 +36,15 @@ nsTAdoptingString_CharT::operator=( const self_type& str ) return *this; } +void +nsTString_CharT::Rebind( const char_type* data, size_type length ) + { + // If we currently own a buffer, release it. + Finalize(); + + mData = const_cast(data); + mLength = length; + SetDataFlags(F_TERMINATED); + AssertValidDepedentString(); + } +