Bug 910795 part 1. Add a way to Rebind() an nsString to be a dependent string. r=bsmedberg

This commit is contained in:
Boris Zbarsky 2013-09-04 16:43:12 -04:00
parent d47399769e
commit 85316040d3
4 changed files with 29 additions and 29 deletions

View File

@ -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<char_type*>(start), uint32_t(end - start), F_TERMINATED)
{
AssertValid();
AssertValidDepedentString();
}
nsTDependentString_CharT( const char_type* data, uint32_t length )
: string_type(const_cast<char_type*>(data), length, F_TERMINATED)
{
AssertValid();
AssertValidDepedentString();
}
explicit
nsTDependentString_CharT( const char_type* data )
: string_type(const_cast<char_type*>(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));

View File

@ -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

View File

@ -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<char_type*>(data);
mLength = length;
SetDataFlags(F_TERMINATED);
AssertValid();
}
void
nsTDependentString_CharT::Rebind( const string_type& str, uint32_t startPos )
{

View File

@ -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<char_type*>(data);
mLength = length;
SetDataFlags(F_TERMINATED);
AssertValidDepedentString();
}