Add assertions that users of nsDependentC?String meet the requirements of nsAFlatC?String. Add nsDependentSingleFragmentC?Substring for users that don't. Additional cleanup after bug 100214. b=104651 r=jag sr=scc
git-svn-id: svn://10.0.0.236/trunk@107556 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -30,6 +30,16 @@
|
||||
#include "nsASingleFragmentString.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* |nsAFlatC?String| is an abstract class. Strings implementing
|
||||
* |nsAFlatC?String| have a buffer that is stored as a single fragment
|
||||
* and is NULL-terminated. That buffer can be accessed for reading
|
||||
* using the |get| method.
|
||||
*
|
||||
* See also |nsASingleFragmentC?String| and |nsAC?String|, base
|
||||
* classes of |nsAFlatC?String|.
|
||||
*/
|
||||
|
||||
class NS_COM nsAFlatString
|
||||
: public nsASingleFragmentString
|
||||
{
|
||||
|
||||
@@ -30,6 +30,16 @@
|
||||
#include "nsAString.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* |nsASingleFragmentC?String| is an abstract class. Strings
|
||||
* implementing |nsASingleFragmentC?String| have a buffer that is
|
||||
* stored as a single fragment. However, they are not necessarily
|
||||
* NULL-terminated.
|
||||
*
|
||||
* See also |nsAFlatC?String|, the remaining more-specific abstract
|
||||
* class in the string hierarchy.
|
||||
*/
|
||||
|
||||
class NS_COM nsASingleFragmentString
|
||||
: public nsAString
|
||||
{
|
||||
|
||||
@@ -42,7 +42,14 @@
|
||||
|
||||
|
||||
/**
|
||||
* |nsAC?String| is the most abstract class in the string hierarchy.
|
||||
* Strings implementing |nsAC?String| may be stored in multiple
|
||||
* fragments. They need not be null-terminated and they may contain
|
||||
* embedded null characters. They may be dependent objects that
|
||||
* depend on other strings.
|
||||
*
|
||||
* See also |nsASingleFragmentC?String| and |nsAFlatC?String|, the
|
||||
* other main abstract classes in the string hierarchy.
|
||||
*/
|
||||
|
||||
class NS_COM nsAString
|
||||
|
||||
@@ -51,13 +51,19 @@ class NS_COM nsDependentString
|
||||
void
|
||||
Rebind( const char_type* aPtr )
|
||||
{
|
||||
NS_ASSERTION(aPtr, "nsDependentString must wrap a non-NULL buffer");
|
||||
mHandle.DataStart(aPtr);
|
||||
// XXX This should not be NULL-safe, but we should flip the switch
|
||||
// early in a milestone.
|
||||
//mHandle.DataEnd(aPtr+nsCharTraits<char_type>::length(aPtr));
|
||||
mHandle.DataEnd(aPtr ? (aPtr+nsCharTraits<char_type>::length(aPtr)) : 0);
|
||||
}
|
||||
|
||||
void
|
||||
Rebind( const char_type* aStartPtr, const char_type* aEndPtr )
|
||||
{
|
||||
NS_ASSERTION(aStartPtr && aEndPtr, "nsDependentString must wrap a non-NULL buffer");
|
||||
NS_ASSERTION(!*aEndPtr, "nsDependentString must wrap only null-terminated strings");
|
||||
mHandle.DataStart(aStartPtr);
|
||||
mHandle.DataEnd(aEndPtr);
|
||||
}
|
||||
@@ -65,13 +71,8 @@ class NS_COM nsDependentString
|
||||
void
|
||||
Rebind( const char_type* aPtr, PRUint32 aLength )
|
||||
{
|
||||
if ( aLength == PRUint32(-1) )
|
||||
{
|
||||
// NS_WARNING("Tell scc: Caller binding a dependent string doesn't know the real length. Please pick the appropriate call.");
|
||||
Rebind(aPtr);
|
||||
}
|
||||
else
|
||||
Rebind(aPtr, aPtr+aLength);
|
||||
NS_ASSERTION(aLength != PRUint32(-1), "caller passing bogus length");
|
||||
Rebind(aPtr, aPtr+aLength);
|
||||
}
|
||||
|
||||
nsDependentString( const char_type* aStartPtr, const char_type* aEndPtr ) { Rebind(aStartPtr, aEndPtr); }
|
||||
@@ -104,13 +105,19 @@ class NS_COM nsDependentCString
|
||||
void
|
||||
Rebind( const char_type* aPtr )
|
||||
{
|
||||
NS_ASSERTION(aPtr, "nsDependentCString must wrap a non-NULL buffer");
|
||||
mHandle.DataStart(aPtr);
|
||||
// XXX This should not be NULL-safe, but we should flip the switch
|
||||
// early in a milestone.
|
||||
//mHandle.DataEnd(aPtr+nsCharTraits<char_type>::length(aPtr));
|
||||
mHandle.DataEnd(aPtr ? (aPtr+nsCharTraits<char_type>::length(aPtr)) : 0);
|
||||
}
|
||||
|
||||
void
|
||||
Rebind( const char_type* aStartPtr, const char_type* aEndPtr )
|
||||
{
|
||||
NS_ASSERTION(aStartPtr && aEndPtr, "nsDependentCString must wrap a non-NULL buffer");
|
||||
NS_ASSERTION(!*aEndPtr, "nsDependentCString must wrap only null-terminated strings");
|
||||
mHandle.DataStart(aStartPtr);
|
||||
mHandle.DataEnd(aEndPtr);
|
||||
}
|
||||
@@ -118,13 +125,8 @@ class NS_COM nsDependentCString
|
||||
void
|
||||
Rebind( const char_type* aPtr, PRUint32 aLength )
|
||||
{
|
||||
if ( aLength == PRUint32(-1) )
|
||||
{
|
||||
// NS_WARNING("Tell scc: Caller binding a dependent string doesn't know the real length. Please pick the appropriate call.");
|
||||
Rebind(aPtr);
|
||||
}
|
||||
else
|
||||
Rebind(aPtr, aPtr+aLength);
|
||||
NS_ASSERTION(aLength != PRUint32(-1), "caller passing bogus length");
|
||||
Rebind(aPtr, aPtr+aLength);
|
||||
}
|
||||
|
||||
nsDependentCString( const char_type* aStartPtr, const char_type* aEndPtr ) { Rebind(aStartPtr, aEndPtr); }
|
||||
@@ -136,7 +138,7 @@ class NS_COM nsDependentCString
|
||||
|
||||
private:
|
||||
// NOT TO BE IMPLEMENTED
|
||||
void operator=( const self_type& ); // we're immutable, so no copy-assignment operator
|
||||
void operator=( const self_type& ); // we're immutable, so no copy-assignment operator
|
||||
|
||||
public:
|
||||
virtual const buffer_handle_type* GetFlatBufferHandle() const { return NS_REINTERPRET_CAST(const buffer_handle_type*, &mHandle); }
|
||||
|
||||
@@ -28,6 +28,10 @@
|
||||
#include "nsAString.h"
|
||||
#endif
|
||||
|
||||
#ifndef nsASingleFragmentString_h___
|
||||
#include "nsASingleFragmentString.h"
|
||||
#endif
|
||||
|
||||
#ifndef nsStringTraits_h___
|
||||
#include "nsStringTraits.h"
|
||||
#endif
|
||||
@@ -145,8 +149,88 @@ class NS_COM nsDependentCSubstring
|
||||
};
|
||||
|
||||
|
||||
class NS_COM nsDependentSingleFragmentSubstring
|
||||
: public nsASingleFragmentString
|
||||
{
|
||||
public:
|
||||
typedef nsDependentSingleFragmentSubstring self_type;
|
||||
typedef nsASingleFragmentString abstract_single_fragment_type;
|
||||
|
||||
void
|
||||
Rebind( const char_type* aStartPtr, const char_type* aEndPtr )
|
||||
{
|
||||
NS_ASSERTION(aStartPtr && aEndPtr, "nsDependentSingleFragmentString must wrap a non-NULL buffer");
|
||||
mHandle.DataStart(aStartPtr);
|
||||
mHandle.DataEnd(aEndPtr);
|
||||
}
|
||||
|
||||
void
|
||||
Rebind( const abstract_single_fragment_type& aString, const PRUint32 aStartPos, const PRUint32 aLength )
|
||||
{
|
||||
const_char_iterator iter;
|
||||
mHandle.DataStart(aString.BeginReading(iter) + NS_MIN(aStartPos, aString.Length()));
|
||||
mHandle.DataEnd( NS_MIN(mHandle.DataStart() + aLength, aString.EndReading(iter)) );
|
||||
}
|
||||
|
||||
nsDependentSingleFragmentSubstring( const char_type* aStartPtr, const char_type* aEndPtr ) { Rebind(aStartPtr, aEndPtr); }
|
||||
nsDependentSingleFragmentSubstring( const abstract_single_fragment_type& aString, const PRUint32 aStartPos, const PRUint32 aLength ) { Rebind(aString, aStartPos, aLength); }
|
||||
|
||||
// nsDependentSingleFragmentSubstring( const self_type& ); // auto-generated copy-constructor OK
|
||||
// ~nsDependentSingleFragmentSubstring(); // auto-generated destructor OK
|
||||
|
||||
private:
|
||||
// NOT TO BE IMPLEMENTED
|
||||
void operator=( const self_type& ); // we're immutable, so no copy-assignment operator
|
||||
|
||||
public:
|
||||
virtual const buffer_handle_type* GetFlatBufferHandle() const { return NS_REINTERPRET_CAST(const buffer_handle_type*, &mHandle); }
|
||||
virtual const buffer_handle_type* GetBufferHandle() const { return NS_REINTERPRET_CAST(const buffer_handle_type*, &mHandle); }
|
||||
|
||||
private:
|
||||
const_buffer_handle_type mHandle;
|
||||
};
|
||||
|
||||
|
||||
class NS_COM nsDependentSingleFragmentCSubstring
|
||||
: public nsASingleFragmentCString
|
||||
{
|
||||
public:
|
||||
typedef nsDependentSingleFragmentCSubstring self_type;
|
||||
typedef nsASingleFragmentCString abstract_single_fragment_type;
|
||||
|
||||
void
|
||||
Rebind( const char_type* aStartPtr, const char_type* aEndPtr )
|
||||
{
|
||||
NS_ASSERTION(aStartPtr && aEndPtr, "nsDependentSingleFragmentCString must wrap a non-NULL buffer");
|
||||
mHandle.DataStart(aStartPtr);
|
||||
mHandle.DataEnd(aEndPtr);
|
||||
}
|
||||
|
||||
void
|
||||
Rebind( const abstract_single_fragment_type& aString, const PRUint32 aStartPos, const PRUint32 aLength )
|
||||
{
|
||||
const_char_iterator iter;
|
||||
mHandle.DataStart(aString.BeginReading(iter) + NS_MIN(aStartPos, aString.Length()));
|
||||
mHandle.DataEnd( NS_MIN(mHandle.DataStart() + aLength, aString.EndReading(iter)) );
|
||||
}
|
||||
|
||||
nsDependentSingleFragmentCSubstring( const char_type* aStartPtr, const char_type* aEndPtr ) { Rebind(aStartPtr, aEndPtr); }
|
||||
nsDependentSingleFragmentCSubstring( const abstract_single_fragment_type& aString, const PRUint32 aStartPos, const PRUint32 aLength ) { Rebind(aString, aStartPos, aLength); }
|
||||
|
||||
// nsDependentSingleFragmentCSubstring( const self_type& ); // auto-generated copy-constructor OK
|
||||
// ~nsDependentSingleFragmentCSubstring(); // auto-generated destructor OK
|
||||
|
||||
private:
|
||||
// NOT TO BE IMPLEMENTED
|
||||
void operator=( const self_type& ); // we're immutable, so no copy-assignment operator
|
||||
|
||||
public:
|
||||
virtual const buffer_handle_type* GetFlatBufferHandle() const { return NS_REINTERPRET_CAST(const buffer_handle_type*, &mHandle); }
|
||||
virtual const buffer_handle_type* GetBufferHandle() const { return NS_REINTERPRET_CAST(const buffer_handle_type*, &mHandle); }
|
||||
|
||||
private:
|
||||
const_buffer_handle_type mHandle;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -179,4 +263,33 @@ Substring( const nsAString::const_iterator& aStart, const nsAString::const_itera
|
||||
}
|
||||
|
||||
|
||||
inline
|
||||
const nsDependentSingleFragmentCSubstring
|
||||
Substring( const nsASingleFragmentCString& aString, PRUint32 aStartPos, PRUint32 aSubstringLength )
|
||||
{
|
||||
return nsDependentSingleFragmentCSubstring(aString, aStartPos, aSubstringLength);
|
||||
}
|
||||
|
||||
inline
|
||||
const nsDependentSingleFragmentSubstring
|
||||
Substring( const nsASingleFragmentString& aString, PRUint32 aStartPos, PRUint32 aSubstringLength )
|
||||
{
|
||||
return nsDependentSingleFragmentSubstring(aString, aStartPos, aSubstringLength);
|
||||
}
|
||||
|
||||
inline
|
||||
const nsDependentSingleFragmentCSubstring
|
||||
Substring( const nsASingleFragmentCString::const_char_iterator& aStart, const nsASingleFragmentCString::const_char_iterator& aEnd )
|
||||
{
|
||||
return nsDependentSingleFragmentCSubstring(aStart, aEnd);
|
||||
}
|
||||
|
||||
inline
|
||||
const nsDependentSingleFragmentSubstring
|
||||
Substring( const nsASingleFragmentString::const_char_iterator& aStart, const nsASingleFragmentString::const_char_iterator& aEnd )
|
||||
{
|
||||
return nsDependentSingleFragmentSubstring(aStart, aEnd);
|
||||
}
|
||||
|
||||
|
||||
#endif /* !defined(nsDependentSubstring_h___) */
|
||||
|
||||
@@ -306,13 +306,13 @@ nsAString::do_AssignFromElementPtr( const char_type* aPtr )
|
||||
void
|
||||
nsAString::do_AssignFromElementPtrLength( const char_type* aPtr, size_type aLength )
|
||||
{
|
||||
do_AssignFromReadable(nsDependentString(aPtr, aLength));
|
||||
do_AssignFromReadable(Substring(aPtr, aPtr+aLength));
|
||||
}
|
||||
|
||||
void
|
||||
nsAString::do_AssignFromElement( char_type aChar )
|
||||
{
|
||||
do_AssignFromReadable(nsDependentString(&aChar, 1));
|
||||
do_AssignFromReadable(Substring(&aChar, &aChar+1));
|
||||
}
|
||||
|
||||
|
||||
@@ -371,13 +371,13 @@ nsAString::do_AppendFromElementPtr( const char_type* aPtr )
|
||||
void
|
||||
nsAString::do_AppendFromElementPtrLength( const char_type* aPtr, size_type aLength )
|
||||
{
|
||||
do_AppendFromReadable(nsDependentString(aPtr, aLength));
|
||||
do_AppendFromReadable(Substring(aPtr, aPtr+aLength));
|
||||
}
|
||||
|
||||
void
|
||||
nsAString::do_AppendFromElement( char_type aChar )
|
||||
{
|
||||
do_AppendFromReadable(nsDependentString(&aChar, 1));
|
||||
do_AppendFromReadable(Substring(&aChar, &aChar + 1));
|
||||
}
|
||||
|
||||
|
||||
@@ -440,13 +440,13 @@ nsAString::do_InsertFromElementPtr( const char_type* aPtr, index_type atPosition
|
||||
void
|
||||
nsAString::do_InsertFromElementPtrLength( const char_type* aPtr, index_type atPosition, size_type aLength )
|
||||
{
|
||||
do_InsertFromReadable(nsDependentString(aPtr, aLength), atPosition);
|
||||
do_InsertFromReadable(Substring(aPtr, aPtr+aLength), atPosition);
|
||||
}
|
||||
|
||||
void
|
||||
nsAString::do_InsertFromElement( char_type aChar, index_type atPosition )
|
||||
{
|
||||
do_InsertFromReadable(nsDependentString(&aChar, 1), atPosition);
|
||||
do_InsertFromReadable(Substring(&aChar, &aChar+1), atPosition);
|
||||
}
|
||||
|
||||
|
||||
@@ -825,13 +825,13 @@ nsACString::do_AssignFromElementPtr( const char_type* aPtr )
|
||||
void
|
||||
nsACString::do_AssignFromElementPtrLength( const char_type* aPtr, size_type aLength )
|
||||
{
|
||||
do_AssignFromReadable(nsDependentCString(aPtr, aLength));
|
||||
do_AssignFromReadable(Substring(aPtr, aPtr+aLength));
|
||||
}
|
||||
|
||||
void
|
||||
nsACString::do_AssignFromElement( char_type aChar )
|
||||
{
|
||||
do_AssignFromReadable(nsDependentCString(&aChar, 1));
|
||||
do_AssignFromReadable(Substring(&aChar, &aChar+1));
|
||||
}
|
||||
|
||||
|
||||
@@ -890,13 +890,13 @@ nsACString::do_AppendFromElementPtr( const char_type* aPtr )
|
||||
void
|
||||
nsACString::do_AppendFromElementPtrLength( const char_type* aPtr, size_type aLength )
|
||||
{
|
||||
do_AppendFromReadable(nsDependentCString(aPtr, aLength));
|
||||
do_AppendFromReadable(Substring(aPtr, aPtr+aLength));
|
||||
}
|
||||
|
||||
void
|
||||
nsACString::do_AppendFromElement( char_type aChar )
|
||||
{
|
||||
do_AppendFromReadable(nsDependentCString(&aChar, 1));
|
||||
do_AppendFromReadable(Substring(&aChar, &aChar + 1));
|
||||
}
|
||||
|
||||
|
||||
@@ -959,13 +959,13 @@ nsACString::do_InsertFromElementPtr( const char_type* aPtr, index_type atPositio
|
||||
void
|
||||
nsACString::do_InsertFromElementPtrLength( const char_type* aPtr, index_type atPosition, size_type aLength )
|
||||
{
|
||||
do_InsertFromReadable(nsDependentCString(aPtr, aLength), atPosition);
|
||||
do_InsertFromReadable(Substring(aPtr, aPtr+aLength), atPosition);
|
||||
}
|
||||
|
||||
void
|
||||
nsACString::do_InsertFromElement( char_type aChar, index_type atPosition )
|
||||
{
|
||||
do_InsertFromReadable(nsDependentCString(&aChar, 1), atPosition);
|
||||
do_InsertFromReadable(Substring(&aChar, &aChar+1), atPosition);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user