Bug 70083: add nsASingleFragmentString to hierarchy. r=dbaron, sr=scc

This commit is contained in:
jaggernaut%netscape.com 2001-10-28 08:24:55 +00:00
parent 6e63ecf1db
commit 8f8d8dc7e1
8 changed files with 44 additions and 330 deletions

Binary file not shown.

View File

@ -26,60 +26,24 @@
#ifndef nsAFlatString_h___
#define nsAFlatString_h___
#ifndef nsAString_h___
#include "nsAString.h"
#ifndef nsASingleFragmenttring_h___
#include "nsASingleFragmentString.h"
#endif
class NS_COM nsAFlatString
: public nsAString
: public nsASingleFragmentString
{
public:
// don't really want this to be virtual, and won't after |obsolete_nsString| is really dead
virtual const char_type* get() const;
char_type operator[]( PRUint32 i ) const { return get()[ i ]; }
char_type CharAt( PRUint32 ) const;
virtual PRUint32 Length() const;
// protected: // can't hide these (yet), since I call them from forwarding routines in |nsPromiseFlatString|
public:
virtual const char_type* GetReadableFragment( const_fragment_type&, nsFragmentRequest, PRUint32 ) const;
virtual char_type* GetWritableFragment( fragment_type&, nsFragmentRequest, PRUint32 );
virtual const char_type* get() const { const char_type* temp; return BeginReading(temp); }
};
class NS_COM nsAFlatCString
: public nsACString
: public nsASingleFragmentCString
{
public:
// don't really want this to be virtual, and won't after |obsolete_nsCString| is really dead
virtual const char_type* get() const;
char_type operator[]( PRUint32 i ) const { return get()[ i ]; }
char_type CharAt( PRUint32 ) const;
virtual PRUint32 Length() const;
// protected: // can't hide these (yet), since I call them from forwarding routines in |nsPromiseFlatCString|
public:
virtual const char_type* GetReadableFragment( const_fragment_type&, nsFragmentRequest, PRUint32 ) const;
virtual char_type* GetWritableFragment( fragment_type&, nsFragmentRequest, PRUint32 );
virtual const char_type* get() const { const char_type* temp; return BeginReading(temp); }
};
inline
nsAFlatString::char_type
nsAFlatString::CharAt( PRUint32 i ) const
{
NS_ASSERTION(i<Length(), "|CharAt| out-of-range");
return operator[](i);
}
inline
nsAFlatCString::char_type
nsAFlatCString::CharAt( PRUint32 i ) const
{
NS_ASSERTION(i<Length(), "|CharAt| out-of-range");
return operator[](i);
}
#endif /* !defined(nsAFlatString_h___) */

View File

@ -112,6 +112,14 @@ class NS_COM nsXPIDLString
void Adopt( char_type* aNewValue ) { *PrepareForUseAsOutParam() = aNewValue; }
// overridden to make getter_Copies mechanism work
const char_type* get() const
{
const buffer_handle_type* handle = GetBufferHandle();
// NS_ASSERTION(handle, "handle is null!");
return handle ? handle->DataStart() : 0;
}
// deprecated, to be eliminated
operator const char_type*() const { return get(); }
char_type operator[]( int i ) const { return get()[ i ]; }
@ -209,6 +217,14 @@ class NS_COM nsXPIDLCString
void Adopt( char_type* aNewValue ) { *PrepareForUseAsOutParam() = aNewValue; }
// overridden to make getter_Copies mechanism work
const char_type* get() const
{
const buffer_handle_type* handle = GetBufferHandle();
// NS_ASSERTION(handle, "handle is null!");
return handle ? handle->DataStart() : 0;
}
// deprecated, to be eliminated
operator const char_type*() const { return get(); }
char_type operator[]( int i ) const { return get()[ i ]; }

View File

@ -23,126 +23,3 @@
#include "nsAFlatString.h"
const nsAFlatString::char_type*
nsAFlatString::GetReadableFragment( const_fragment_type& aFragment, nsFragmentRequest aRequest, PRUint32 aOffset ) const
{
switch ( aRequest )
{
case kFirstFragment:
case kLastFragment:
case kFragmentAt:
{
const buffer_handle_type* buffer = GetBufferHandle();
if ( !buffer )
return 0;
aFragment.mEnd = buffer->DataEnd();
return (aFragment.mStart = buffer->DataStart()) + aOffset;
}
case kPrevFragment:
case kNextFragment:
default:
return 0;
}
}
nsAFlatString::char_type*
nsAFlatString::GetWritableFragment( fragment_type& aFragment, nsFragmentRequest aRequest, PRUint32 aOffset )
{
switch ( aRequest )
{
case kFirstFragment:
case kLastFragment:
case kFragmentAt:
{
buffer_handle_type* buffer = NS_CONST_CAST(buffer_handle_type*, GetBufferHandle());
NS_ASSERTION(buffer, "trouble: no buffer!");
aFragment.mEnd = buffer->DataEnd();
return (aFragment.mStart = buffer->DataStart()) + aOffset;
}
case kPrevFragment:
case kNextFragment:
default:
return 0;
}
}
const nsAFlatCString::char_type*
nsAFlatCString::GetReadableFragment( const_fragment_type& aFragment, nsFragmentRequest aRequest, PRUint32 aOffset ) const
{
switch ( aRequest )
{
case kFirstFragment:
case kLastFragment:
case kFragmentAt:
{
const buffer_handle_type* buffer = GetBufferHandle();
NS_ASSERTION(buffer, "trouble: no buffer!");
aFragment.mEnd = buffer->DataEnd();
return (aFragment.mStart = buffer->DataStart()) + aOffset;
}
case kPrevFragment:
case kNextFragment:
default:
return 0;
}
}
nsAFlatCString::char_type*
nsAFlatCString::GetWritableFragment( fragment_type& aFragment, nsFragmentRequest aRequest, PRUint32 aOffset )
{
switch ( aRequest )
{
case kFirstFragment:
case kLastFragment:
case kFragmentAt:
{
buffer_handle_type* buffer = NS_CONST_CAST(buffer_handle_type*, GetBufferHandle());
NS_ASSERTION(buffer, "trouble: no buffer!");
aFragment.mEnd = buffer->DataEnd();
return (aFragment.mStart = buffer->DataStart()) + aOffset;
}
case kPrevFragment:
case kNextFragment:
default:
return 0;
}
}
PRUint32
nsAFlatString::Length() const
{
const buffer_handle_type* handle = GetBufferHandle();
return PRUint32(handle ? handle->DataLength() : 0);
}
PRUint32
nsAFlatCString::Length() const
{
const buffer_handle_type* handle = GetBufferHandle();
return PRUint32(handle ? handle->DataLength() : 0);
}
const nsAFlatString::char_type*
nsAFlatString::get() const
{
const buffer_handle_type* handle = GetBufferHandle();
// NS_ASSERTION(handle, "handle is null!");
return handle ? handle->DataStart() : 0;
}
const nsAFlatCString::char_type*
nsAFlatCString::get() const
{
const buffer_handle_type* handle = GetBufferHandle();
// NS_ASSERTION(handle, "handle is null!");
return handle ? handle->DataStart() : 0;
}

Binary file not shown.

View File

@ -26,60 +26,24 @@
#ifndef nsAFlatString_h___
#define nsAFlatString_h___
#ifndef nsAString_h___
#include "nsAString.h"
#ifndef nsASingleFragmenttring_h___
#include "nsASingleFragmentString.h"
#endif
class NS_COM nsAFlatString
: public nsAString
: public nsASingleFragmentString
{
public:
// don't really want this to be virtual, and won't after |obsolete_nsString| is really dead
virtual const char_type* get() const;
char_type operator[]( PRUint32 i ) const { return get()[ i ]; }
char_type CharAt( PRUint32 ) const;
virtual PRUint32 Length() const;
// protected: // can't hide these (yet), since I call them from forwarding routines in |nsPromiseFlatString|
public:
virtual const char_type* GetReadableFragment( const_fragment_type&, nsFragmentRequest, PRUint32 ) const;
virtual char_type* GetWritableFragment( fragment_type&, nsFragmentRequest, PRUint32 );
virtual const char_type* get() const { const char_type* temp; return BeginReading(temp); }
};
class NS_COM nsAFlatCString
: public nsACString
: public nsASingleFragmentCString
{
public:
// don't really want this to be virtual, and won't after |obsolete_nsCString| is really dead
virtual const char_type* get() const;
char_type operator[]( PRUint32 i ) const { return get()[ i ]; }
char_type CharAt( PRUint32 ) const;
virtual PRUint32 Length() const;
// protected: // can't hide these (yet), since I call them from forwarding routines in |nsPromiseFlatCString|
public:
virtual const char_type* GetReadableFragment( const_fragment_type&, nsFragmentRequest, PRUint32 ) const;
virtual char_type* GetWritableFragment( fragment_type&, nsFragmentRequest, PRUint32 );
virtual const char_type* get() const { const char_type* temp; return BeginReading(temp); }
};
inline
nsAFlatString::char_type
nsAFlatString::CharAt( PRUint32 i ) const
{
NS_ASSERTION(i<Length(), "|CharAt| out-of-range");
return operator[](i);
}
inline
nsAFlatCString::char_type
nsAFlatCString::CharAt( PRUint32 i ) const
{
NS_ASSERTION(i<Length(), "|CharAt| out-of-range");
return operator[](i);
}
#endif /* !defined(nsAFlatString_h___) */

View File

@ -112,6 +112,14 @@ class NS_COM nsXPIDLString
void Adopt( char_type* aNewValue ) { *PrepareForUseAsOutParam() = aNewValue; }
// overridden to make getter_Copies mechanism work
const char_type* get() const
{
const buffer_handle_type* handle = GetBufferHandle();
// NS_ASSERTION(handle, "handle is null!");
return handle ? handle->DataStart() : 0;
}
// deprecated, to be eliminated
operator const char_type*() const { return get(); }
char_type operator[]( int i ) const { return get()[ i ]; }
@ -209,6 +217,14 @@ class NS_COM nsXPIDLCString
void Adopt( char_type* aNewValue ) { *PrepareForUseAsOutParam() = aNewValue; }
// overridden to make getter_Copies mechanism work
const char_type* get() const
{
const buffer_handle_type* handle = GetBufferHandle();
// NS_ASSERTION(handle, "handle is null!");
return handle ? handle->DataStart() : 0;
}
// deprecated, to be eliminated
operator const char_type*() const { return get(); }
char_type operator[]( int i ) const { return get()[ i ]; }

View File

@ -23,126 +23,3 @@
#include "nsAFlatString.h"
const nsAFlatString::char_type*
nsAFlatString::GetReadableFragment( const_fragment_type& aFragment, nsFragmentRequest aRequest, PRUint32 aOffset ) const
{
switch ( aRequest )
{
case kFirstFragment:
case kLastFragment:
case kFragmentAt:
{
const buffer_handle_type* buffer = GetBufferHandle();
if ( !buffer )
return 0;
aFragment.mEnd = buffer->DataEnd();
return (aFragment.mStart = buffer->DataStart()) + aOffset;
}
case kPrevFragment:
case kNextFragment:
default:
return 0;
}
}
nsAFlatString::char_type*
nsAFlatString::GetWritableFragment( fragment_type& aFragment, nsFragmentRequest aRequest, PRUint32 aOffset )
{
switch ( aRequest )
{
case kFirstFragment:
case kLastFragment:
case kFragmentAt:
{
buffer_handle_type* buffer = NS_CONST_CAST(buffer_handle_type*, GetBufferHandle());
NS_ASSERTION(buffer, "trouble: no buffer!");
aFragment.mEnd = buffer->DataEnd();
return (aFragment.mStart = buffer->DataStart()) + aOffset;
}
case kPrevFragment:
case kNextFragment:
default:
return 0;
}
}
const nsAFlatCString::char_type*
nsAFlatCString::GetReadableFragment( const_fragment_type& aFragment, nsFragmentRequest aRequest, PRUint32 aOffset ) const
{
switch ( aRequest )
{
case kFirstFragment:
case kLastFragment:
case kFragmentAt:
{
const buffer_handle_type* buffer = GetBufferHandle();
NS_ASSERTION(buffer, "trouble: no buffer!");
aFragment.mEnd = buffer->DataEnd();
return (aFragment.mStart = buffer->DataStart()) + aOffset;
}
case kPrevFragment:
case kNextFragment:
default:
return 0;
}
}
nsAFlatCString::char_type*
nsAFlatCString::GetWritableFragment( fragment_type& aFragment, nsFragmentRequest aRequest, PRUint32 aOffset )
{
switch ( aRequest )
{
case kFirstFragment:
case kLastFragment:
case kFragmentAt:
{
buffer_handle_type* buffer = NS_CONST_CAST(buffer_handle_type*, GetBufferHandle());
NS_ASSERTION(buffer, "trouble: no buffer!");
aFragment.mEnd = buffer->DataEnd();
return (aFragment.mStart = buffer->DataStart()) + aOffset;
}
case kPrevFragment:
case kNextFragment:
default:
return 0;
}
}
PRUint32
nsAFlatString::Length() const
{
const buffer_handle_type* handle = GetBufferHandle();
return PRUint32(handle ? handle->DataLength() : 0);
}
PRUint32
nsAFlatCString::Length() const
{
const buffer_handle_type* handle = GetBufferHandle();
return PRUint32(handle ? handle->DataLength() : 0);
}
const nsAFlatString::char_type*
nsAFlatString::get() const
{
const buffer_handle_type* handle = GetBufferHandle();
// NS_ASSERTION(handle, "handle is null!");
return handle ? handle->DataStart() : 0;
}
const nsAFlatCString::char_type*
nsAFlatCString::get() const
{
const buffer_handle_type* handle = GetBufferHandle();
// NS_ASSERTION(handle, "handle is null!");
return handle ? handle->DataStart() : 0;
}