зеркало из https://github.com/mozilla/gecko-dev.git
incremental changes. We're getting closer. These files are not yet part of the build.
This commit is contained in:
Родитель
e6ae3320f8
Коммит
85ed3b0e46
|
@ -232,7 +232,11 @@ class basic_nsAReadableString
|
|||
*/
|
||||
{
|
||||
public:
|
||||
typedef nsReadingIterator<CharT> ConstIterator;
|
||||
typedef PRUint32 size_type;
|
||||
typedef PRUint32 index_type;
|
||||
|
||||
typedef nsReadingIterator<CharT> const_iterator;
|
||||
|
||||
|
||||
|
||||
virtual ~basic_nsAReadableString() { }
|
||||
|
@ -615,7 +619,10 @@ class basic_nsLiteralString
|
|||
: mStart(aLiteral),
|
||||
mEnd(mStart + aLength)
|
||||
{
|
||||
// nothing else to do here
|
||||
// This is an annoying hack. Callers should be fixed to use the other
|
||||
// constructor if they don't really know the length.
|
||||
if ( aLength == PRUint32(-1) )
|
||||
mEnd = mStart + nsCharTraits<CharT>::length(mStart);
|
||||
}
|
||||
|
||||
virtual PRUint32 Length() const;
|
||||
|
@ -658,6 +665,59 @@ basic_nsLiteralString<CharT>::Length() const
|
|||
|
||||
|
||||
|
||||
//
|
||||
// nsLiteralChar, nsLiteralPRUnichar
|
||||
//
|
||||
|
||||
template <class CharT>
|
||||
class basic_nsLiteralChar
|
||||
: public basic_nsAReadableString<CharT>
|
||||
{
|
||||
protected:
|
||||
virtual const CharT* GetReadableFragment( nsReadableFragment<CharT>&, nsFragmentRequest, PRUint32 ) const;
|
||||
|
||||
public:
|
||||
|
||||
basic_nsLiteralChar( CharT aChar )
|
||||
: mChar(aChar)
|
||||
{
|
||||
// nothing else to do here
|
||||
}
|
||||
|
||||
virtual
|
||||
PRUint32
|
||||
Length() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
private:
|
||||
CharT mChar;
|
||||
};
|
||||
|
||||
template <class CharT>
|
||||
const CharT*
|
||||
basic_nsLiteralChar<CharT>::GetReadableFragment( nsReadableFragment<CharT>& aFragment, nsFragmentRequest aRequest, PRUint32 aOffset ) const
|
||||
{
|
||||
switch ( aRequest )
|
||||
{
|
||||
case kFirstFragment:
|
||||
case kLastFragment:
|
||||
case kFragmentAt:
|
||||
aFragment.mEnd = (aFragment.mStart = &mChar) + 1;
|
||||
return aFragment.mStart + aOffset;
|
||||
|
||||
case kPrevFragment:
|
||||
case kNextFragment:
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
// nsPromiseConcatenation
|
||||
|
@ -1107,5 +1167,8 @@ typedef basic_nsLiteralString<char> nsLiteralCString;
|
|||
#define NS_LITERAL_STRING(s) nsLiteralString(s, sizeof(s)/sizeof(wchar_t))
|
||||
#define NS_LITERAL_CSTRING(s) nsLiteralCString(s, sizeof(s))
|
||||
|
||||
typedef basic_nsLiteralChar<char> nsLiteralChar;
|
||||
typedef basic_nsLiteralChar<PRUnichar> nsLiteralPRUnichar;
|
||||
|
||||
|
||||
#endif // !defined(_nsAReadableString_h__)
|
||||
|
|
|
@ -200,7 +200,10 @@ class basic_nsAWritableString
|
|||
// friend class nsWritingIterator<CharT>;
|
||||
|
||||
public:
|
||||
typedef nsWritingIterator<CharT> Iterator;
|
||||
typedef PRUint32 size_type;
|
||||
typedef PRUint32 index_type;
|
||||
|
||||
typedef nsWritingIterator<CharT> iterator;
|
||||
|
||||
virtual CharT* GetWritableFragment( nsWritableFragment<CharT>&, nsFragmentRequest, PRUint32 = 0 ) = 0;
|
||||
|
||||
|
@ -255,49 +258,84 @@ class basic_nsAWritableString
|
|||
|
||||
|
||||
|
||||
virtual void Assign( const basic_nsAReadableString<CharT>& rhs );
|
||||
// virtual void AssignChar( CharT ) = 0;
|
||||
//
|
||||
// |operator=()|, |Assign()|
|
||||
//
|
||||
|
||||
basic_nsAWritableString<CharT>& operator=( const basic_nsAReadableString<CharT>& aReadable ) { do_AssignFromReadable(aReadable); return *this; }
|
||||
basic_nsAWritableString<CharT>& operator=( const CharT* aPtr ) { do_AssignFromElementPtr(aPtr); return *this; }
|
||||
basic_nsAWritableString<CharT>& operator=( CharT aChar ) { do_AssignFromElement(aChar); return *this; }
|
||||
|
||||
void Assign( const basic_nsAReadableString<CharT>& aReadable ) { do_AssignFromReadable(aReadable); }
|
||||
// void Assign( const nsReadingIterator<CharT>& aStart, const nsReadingIterator<CharT>& aEnd ) { do_AssignFromIterators(aStart, aEnd); }
|
||||
void Assign( const CharT* aPtr ) { do_AssignFromElementPtr(aPtr); }
|
||||
void Assign( const CharT* aPtr, PRUint32 aLength ) { do_AssignFromElementPtrLength(aPtr, aLength); }
|
||||
void Assign( CharT aChar ) { do_AssignFromElement(aChar); }
|
||||
|
||||
|
||||
|
||||
//
|
||||
// |operator+=()|, |Append()|
|
||||
//
|
||||
|
||||
basic_nsAWritableString<CharT>& operator+=( const basic_nsAReadableString<CharT>& aReadable ) { do_AppendFromReadable(aReadable); return *this; }
|
||||
basic_nsAWritableString<CharT>& operator+=( const CharT* aPtr ) { do_AppendFromElementPtr(aPtr); return *this; }
|
||||
basic_nsAWritableString<CharT>& operator+=( CharT aChar ) { do_AppendFromElement(aChar); return *this; }
|
||||
|
||||
void Append( const basic_nsAReadableString<CharT>& aReadable ) { do_AppendFromReadable(aReadable); }
|
||||
// void Append( const nsReadingIterator<CharT>& aStart, const nsReadingIterator<CharT>& aEnd ) { do_AppendFromIterators(aStart, aEnd); }
|
||||
void Append( const CharT* aPtr ) { do_AppendFromElementPtr(aPtr); }
|
||||
void Append( const CharT* aPtr, PRUint32 aLength ) { do_AppendFromElementPtrLength(aPtr, aLength); }
|
||||
void Append( CharT aChar ) { do_AppendFromElement(aChar); }
|
||||
|
||||
|
||||
|
||||
//
|
||||
// |Insert()|
|
||||
// Note: I would really like to move the |atPosition| parameter to the front of the argument list
|
||||
//
|
||||
|
||||
void Insert( const basic_nsAReadableString<CharT>& aReadable, PRUint32 atPosition ) { do_InsertFromReadable(aReadable, atPosition); }
|
||||
// void Insert( const nsReadingIterator<CharT>& aStart, const nsReadingIterator<CharT>& aEnd, PRUint32 atPosition ) { do_InsertFromIterators(aStart, aEnd, atPosition); }
|
||||
void Insert( const CharT* aPtr, PRUint32 atPosition ) { do_InsertFromElementPtr(aPtr, atPosition); }
|
||||
void Insert( const CharT* aPtr, PRUint32 atPosition, PRUint32 aLength ) { do_InsertFromElementPtrLength(aPtr, atPosition, aLength); }
|
||||
void Insert( CharT aChar, PRUint32 atPosition ) { do_InsertFromElement(aChar, atPosition); }
|
||||
|
||||
virtual void Append( const basic_nsAReadableString<CharT>& );
|
||||
virtual void AppendChar( CharT );
|
||||
|
||||
virtual void Insert( const basic_nsAReadableString<CharT>&, PRUint32 atPosition );
|
||||
// virtual void InsertChar( CharT, PRUint32 atPosition ) = 0;
|
||||
|
||||
virtual void Cut( PRUint32 cutStart, PRUint32 cutLength );
|
||||
|
||||
virtual void Replace( PRUint32 cutStart, PRUint32 cutLength, const basic_nsAReadableString<CharT>& );
|
||||
|
||||
|
||||
basic_nsAWritableString<CharT>&
|
||||
operator+=( const basic_nsAReadableString<CharT>& rhs )
|
||||
{
|
||||
Append(rhs);
|
||||
return *this;
|
||||
}
|
||||
void Replace( PRUint32 cutStart, PRUint32 cutLength, const basic_nsAReadableString<CharT>& );
|
||||
|
||||
basic_nsAWritableString<CharT>&
|
||||
operator+=( const basic_nsLiteralString<CharT>& rhs )
|
||||
{
|
||||
Append(rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
basic_nsAWritableString<CharT>&
|
||||
operator=( const basic_nsAReadableString<CharT>& rhs )
|
||||
{
|
||||
Assign(rhs);
|
||||
return *this;
|
||||
}
|
||||
protected:
|
||||
virtual void do_AssignFromReadable( const basic_nsAReadableString<CharT>& );
|
||||
// virtual void do_AssignFromIterators( nsReadingIterator<CharT>, nsReadingIterator<CharT> );
|
||||
virtual void do_AssignFromElementPtr( const CharT* );
|
||||
virtual void do_AssignFromElementPtrLength( const CharT*, PRUint32 );
|
||||
virtual void do_AssignFromElement( CharT );
|
||||
|
||||
basic_nsAWritableString<CharT>&
|
||||
operator=( const basic_nsLiteralString<CharT>& rhs )
|
||||
{
|
||||
Assign(rhs);
|
||||
return *this;
|
||||
}
|
||||
virtual void do_AppendFromReadable( const basic_nsAReadableString<CharT>& );
|
||||
// virtual void do_AppendFromIterators( nsReadingIterator<CharT>, nsReadingIterator<CharT> );
|
||||
virtual void do_AppendFromElementPtr( const CharT* );
|
||||
virtual void do_AppendFromElementPtrLength( const CharT*, PRUint32 );
|
||||
virtual void do_AppendFromElement( CharT );
|
||||
|
||||
virtual void do_InsertFromReadable( const basic_nsAReadableString<CharT>&, PRUint32 );
|
||||
// virtual void do_InsertFromIterators( nsReadingIterator<CharT>, nsReadingIterator<CharT>, PRUint32 );
|
||||
virtual void do_InsertFromElementPtr( const CharT*, PRUint32 );
|
||||
virtual void do_InsertFromElementPtrLength( const CharT*, PRUint32, PRUint32 );
|
||||
virtual void do_InsertFromElement( CharT, PRUint32 );
|
||||
};
|
||||
|
||||
|
||||
|
||||
//
|
||||
// |nsWritingIterator|s
|
||||
//
|
||||
|
||||
template <class CharT>
|
||||
inline
|
||||
void
|
||||
|
@ -326,53 +364,144 @@ operator==( const nsWritingIterator<CharT>& lhs, const nsWritingIterator<CharT>&
|
|||
return lhs.operator->() == rhs.operator->();
|
||||
}
|
||||
|
||||
template <class CharT>
|
||||
inline
|
||||
PRBool
|
||||
operator!=( const nsWritingIterator<CharT>& lhs, const nsWritingIterator<CharT>& rhs )
|
||||
{
|
||||
return lhs.operator->() != rhs.operator->();
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// |Assign()|
|
||||
//
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::Assign( const basic_nsAReadableString<CharT>& rhs )
|
||||
basic_nsAWritableString<CharT>::do_AssignFromReadable( const basic_nsAReadableString<CharT>& rhs )
|
||||
{
|
||||
SetLength(rhs.Length());
|
||||
copy_string(rhs.BeginReading(), rhs.EndReading(), BeginWriting());
|
||||
}
|
||||
|
||||
#if 0
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::Append( const basic_nsAReadableString<CharT>& rhs )
|
||||
basic_nsAWritableString<CharT>::do_AssignFromIterators( const nsReadingIterator<CharT>& aStart, const nsReadingIterator<CharT>& aEnd )
|
||||
{
|
||||
SetLength(distance(aStart, aEnd));
|
||||
copy_string(aStart, aEnd, BeginWriting());
|
||||
}
|
||||
#endif
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::do_AssignFromElementPtr( const CharT* aPtr )
|
||||
{
|
||||
do_AssignFromReadable(basic_nsLiteralString<CharT>(aPtr));
|
||||
}
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::do_AssignFromElementPtrLength( const CharT* aPtr, PRUint32 aLength )
|
||||
{
|
||||
do_AssignFromReadable(basic_nsLiteralString<CharT>(aPtr, aLength));
|
||||
}
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::do_AssignFromElement( CharT aChar )
|
||||
{
|
||||
do_AssignFromReadable(basic_nsLiteralChar<CharT>(aChar));
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// |Append()|
|
||||
//
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::do_AppendFromReadable( const basic_nsAReadableString<CharT>& rhs )
|
||||
{
|
||||
PRUint32 oldLength = Length();
|
||||
SetLength(oldLength + rhs.Length());
|
||||
copy_string(rhs.BeginReading(), rhs.EndReading(), BeginWriting(oldLength));
|
||||
}
|
||||
|
||||
#if 0
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::AppendChar( CharT aChar )
|
||||
basic_nsAWritableString<CharT>::do_AppendFromIterators( const nsReadingIterator<CharT>& aStart, const nsReadingIterator<CharT>& aEnd )
|
||||
{
|
||||
SetLength(Length()+1);
|
||||
*EndWriting(1) = aChar;
|
||||
PRUint32 oldLength = Length();
|
||||
SetLength(oldLength + distance(aStart, aEnd));
|
||||
copy_string(aStart, aEnd, BeginWriting(oldLength));
|
||||
}
|
||||
#endif
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::do_AppendFromElementPtr( const CharT* aChar )
|
||||
{
|
||||
do_AppendFromReadable(basic_nsLiteralString<CharT>(aChar));
|
||||
}
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::Insert( const basic_nsAReadableString<CharT>& aReadable, PRUint32 aPosition )
|
||||
basic_nsAWritableString<CharT>::do_AppendFromElementPtrLength( const CharT* aChar, PRUint32 aLength )
|
||||
{
|
||||
do_AppendFromReadable(basic_nsLiteralString<CharT>(aChar, aLength));
|
||||
}
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::do_AppendFromElement( CharT aChar )
|
||||
{
|
||||
do_AppendFromReadable(basic_nsLiteralChar<CharT>(aChar));
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// |Insert()|
|
||||
//
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::do_InsertFromReadable( const basic_nsAReadableString<CharT>& aReadable, PRUint32 atPosition )
|
||||
{
|
||||
PRUint32 oldLength = Length();
|
||||
SetLength(oldLength + aReadable.Length());
|
||||
if ( aPosition < oldLength )
|
||||
copy_string_backward(BeginReading(aPosition), BeginReading(oldLength), EndWriting());
|
||||
if ( atPosition < oldLength )
|
||||
copy_string_backward(BeginReading(atPosition), BeginReading(oldLength), EndWriting());
|
||||
else
|
||||
aPosition = oldLength;
|
||||
copy_string(aReadable.BeginReading(), aReadable.EndReading(), BeginWriting(aPosition));
|
||||
atPosition = oldLength;
|
||||
copy_string(aReadable.BeginReading(), aReadable.EndReading(), BeginWriting(atPosition));
|
||||
}
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::do_InsertFromElementPtr( const CharT* aPtr, PRUint32 atPosition )
|
||||
{
|
||||
do_InsertFromReadable(basic_nsLiteralString<CharT>(aPtr), atPosition);
|
||||
}
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::do_InsertFromElementPtrLength( const CharT* aPtr, PRUint32 atPosition, PRUint32 aLength )
|
||||
{
|
||||
do_InsertFromReadable(basic_nsLiteralString<CharT>(aPtr, aLength), atPosition);
|
||||
}
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::do_InsertFromElement( CharT aChar, PRUint32 atPosition )
|
||||
{
|
||||
do_InsertFromReadable(basic_nsLiteralChar<CharT>(aChar), atPosition);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// |Cut()|
|
||||
//
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::Cut( PRUint32 cutStart, PRUint32 cutLength )
|
||||
|
@ -381,6 +510,12 @@ basic_nsAWritableString<CharT>::Cut( PRUint32 cutStart, PRUint32 cutLength )
|
|||
SetLength(Length()-cutLength);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// |Replace()|
|
||||
//
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::Replace( PRUint32 cutStart, PRUint32 cutLength, const basic_nsAReadableString<CharT>& aReplacement )
|
||||
|
@ -405,8 +540,11 @@ basic_nsAWritableString<CharT>::Replace( PRUint32 cutStart, PRUint32 cutLength,
|
|||
copy_string(aReplacement.BeginReading(), aReplacement.EndReading(), BeginWriting(cutStart));
|
||||
}
|
||||
|
||||
// operator>>
|
||||
// getline (maybe)
|
||||
|
||||
|
||||
//
|
||||
// Types
|
||||
//
|
||||
|
||||
typedef basic_nsAWritableString<PRUnichar> nsAWritableString;
|
||||
typedef basic_nsAWritableString<char> nsAWritableCString;
|
||||
|
|
|
@ -69,7 +69,10 @@ class basic_nsSharedString
|
|||
{
|
||||
nsrefcnt result = --mRefCount;
|
||||
if ( !mRefCount )
|
||||
delete this;
|
||||
{
|
||||
delete this;
|
||||
// BULLSHIT ALERT: need to make |delete| match |new|
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -109,7 +112,7 @@ class nsSharedStringPtr
|
|||
// ...
|
||||
|
||||
private:
|
||||
basic_nsSharedString<CharT>* mPtr;
|
||||
basic_nsSharedString<CharT>* mRawPtr;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -232,7 +232,11 @@ class basic_nsAReadableString
|
|||
*/
|
||||
{
|
||||
public:
|
||||
typedef nsReadingIterator<CharT> ConstIterator;
|
||||
typedef PRUint32 size_type;
|
||||
typedef PRUint32 index_type;
|
||||
|
||||
typedef nsReadingIterator<CharT> const_iterator;
|
||||
|
||||
|
||||
|
||||
virtual ~basic_nsAReadableString() { }
|
||||
|
@ -615,7 +619,10 @@ class basic_nsLiteralString
|
|||
: mStart(aLiteral),
|
||||
mEnd(mStart + aLength)
|
||||
{
|
||||
// nothing else to do here
|
||||
// This is an annoying hack. Callers should be fixed to use the other
|
||||
// constructor if they don't really know the length.
|
||||
if ( aLength == PRUint32(-1) )
|
||||
mEnd = mStart + nsCharTraits<CharT>::length(mStart);
|
||||
}
|
||||
|
||||
virtual PRUint32 Length() const;
|
||||
|
@ -658,6 +665,59 @@ basic_nsLiteralString<CharT>::Length() const
|
|||
|
||||
|
||||
|
||||
//
|
||||
// nsLiteralChar, nsLiteralPRUnichar
|
||||
//
|
||||
|
||||
template <class CharT>
|
||||
class basic_nsLiteralChar
|
||||
: public basic_nsAReadableString<CharT>
|
||||
{
|
||||
protected:
|
||||
virtual const CharT* GetReadableFragment( nsReadableFragment<CharT>&, nsFragmentRequest, PRUint32 ) const;
|
||||
|
||||
public:
|
||||
|
||||
basic_nsLiteralChar( CharT aChar )
|
||||
: mChar(aChar)
|
||||
{
|
||||
// nothing else to do here
|
||||
}
|
||||
|
||||
virtual
|
||||
PRUint32
|
||||
Length() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
private:
|
||||
CharT mChar;
|
||||
};
|
||||
|
||||
template <class CharT>
|
||||
const CharT*
|
||||
basic_nsLiteralChar<CharT>::GetReadableFragment( nsReadableFragment<CharT>& aFragment, nsFragmentRequest aRequest, PRUint32 aOffset ) const
|
||||
{
|
||||
switch ( aRequest )
|
||||
{
|
||||
case kFirstFragment:
|
||||
case kLastFragment:
|
||||
case kFragmentAt:
|
||||
aFragment.mEnd = (aFragment.mStart = &mChar) + 1;
|
||||
return aFragment.mStart + aOffset;
|
||||
|
||||
case kPrevFragment:
|
||||
case kNextFragment:
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
// nsPromiseConcatenation
|
||||
|
@ -1107,5 +1167,8 @@ typedef basic_nsLiteralString<char> nsLiteralCString;
|
|||
#define NS_LITERAL_STRING(s) nsLiteralString(s, sizeof(s)/sizeof(wchar_t))
|
||||
#define NS_LITERAL_CSTRING(s) nsLiteralCString(s, sizeof(s))
|
||||
|
||||
typedef basic_nsLiteralChar<char> nsLiteralChar;
|
||||
typedef basic_nsLiteralChar<PRUnichar> nsLiteralPRUnichar;
|
||||
|
||||
|
||||
#endif // !defined(_nsAReadableString_h__)
|
||||
|
|
|
@ -200,7 +200,10 @@ class basic_nsAWritableString
|
|||
// friend class nsWritingIterator<CharT>;
|
||||
|
||||
public:
|
||||
typedef nsWritingIterator<CharT> Iterator;
|
||||
typedef PRUint32 size_type;
|
||||
typedef PRUint32 index_type;
|
||||
|
||||
typedef nsWritingIterator<CharT> iterator;
|
||||
|
||||
virtual CharT* GetWritableFragment( nsWritableFragment<CharT>&, nsFragmentRequest, PRUint32 = 0 ) = 0;
|
||||
|
||||
|
@ -255,49 +258,84 @@ class basic_nsAWritableString
|
|||
|
||||
|
||||
|
||||
virtual void Assign( const basic_nsAReadableString<CharT>& rhs );
|
||||
// virtual void AssignChar( CharT ) = 0;
|
||||
//
|
||||
// |operator=()|, |Assign()|
|
||||
//
|
||||
|
||||
basic_nsAWritableString<CharT>& operator=( const basic_nsAReadableString<CharT>& aReadable ) { do_AssignFromReadable(aReadable); return *this; }
|
||||
basic_nsAWritableString<CharT>& operator=( const CharT* aPtr ) { do_AssignFromElementPtr(aPtr); return *this; }
|
||||
basic_nsAWritableString<CharT>& operator=( CharT aChar ) { do_AssignFromElement(aChar); return *this; }
|
||||
|
||||
void Assign( const basic_nsAReadableString<CharT>& aReadable ) { do_AssignFromReadable(aReadable); }
|
||||
// void Assign( const nsReadingIterator<CharT>& aStart, const nsReadingIterator<CharT>& aEnd ) { do_AssignFromIterators(aStart, aEnd); }
|
||||
void Assign( const CharT* aPtr ) { do_AssignFromElementPtr(aPtr); }
|
||||
void Assign( const CharT* aPtr, PRUint32 aLength ) { do_AssignFromElementPtrLength(aPtr, aLength); }
|
||||
void Assign( CharT aChar ) { do_AssignFromElement(aChar); }
|
||||
|
||||
|
||||
|
||||
//
|
||||
// |operator+=()|, |Append()|
|
||||
//
|
||||
|
||||
basic_nsAWritableString<CharT>& operator+=( const basic_nsAReadableString<CharT>& aReadable ) { do_AppendFromReadable(aReadable); return *this; }
|
||||
basic_nsAWritableString<CharT>& operator+=( const CharT* aPtr ) { do_AppendFromElementPtr(aPtr); return *this; }
|
||||
basic_nsAWritableString<CharT>& operator+=( CharT aChar ) { do_AppendFromElement(aChar); return *this; }
|
||||
|
||||
void Append( const basic_nsAReadableString<CharT>& aReadable ) { do_AppendFromReadable(aReadable); }
|
||||
// void Append( const nsReadingIterator<CharT>& aStart, const nsReadingIterator<CharT>& aEnd ) { do_AppendFromIterators(aStart, aEnd); }
|
||||
void Append( const CharT* aPtr ) { do_AppendFromElementPtr(aPtr); }
|
||||
void Append( const CharT* aPtr, PRUint32 aLength ) { do_AppendFromElementPtrLength(aPtr, aLength); }
|
||||
void Append( CharT aChar ) { do_AppendFromElement(aChar); }
|
||||
|
||||
|
||||
|
||||
//
|
||||
// |Insert()|
|
||||
// Note: I would really like to move the |atPosition| parameter to the front of the argument list
|
||||
//
|
||||
|
||||
void Insert( const basic_nsAReadableString<CharT>& aReadable, PRUint32 atPosition ) { do_InsertFromReadable(aReadable, atPosition); }
|
||||
// void Insert( const nsReadingIterator<CharT>& aStart, const nsReadingIterator<CharT>& aEnd, PRUint32 atPosition ) { do_InsertFromIterators(aStart, aEnd, atPosition); }
|
||||
void Insert( const CharT* aPtr, PRUint32 atPosition ) { do_InsertFromElementPtr(aPtr, atPosition); }
|
||||
void Insert( const CharT* aPtr, PRUint32 atPosition, PRUint32 aLength ) { do_InsertFromElementPtrLength(aPtr, atPosition, aLength); }
|
||||
void Insert( CharT aChar, PRUint32 atPosition ) { do_InsertFromElement(aChar, atPosition); }
|
||||
|
||||
virtual void Append( const basic_nsAReadableString<CharT>& );
|
||||
virtual void AppendChar( CharT );
|
||||
|
||||
virtual void Insert( const basic_nsAReadableString<CharT>&, PRUint32 atPosition );
|
||||
// virtual void InsertChar( CharT, PRUint32 atPosition ) = 0;
|
||||
|
||||
virtual void Cut( PRUint32 cutStart, PRUint32 cutLength );
|
||||
|
||||
virtual void Replace( PRUint32 cutStart, PRUint32 cutLength, const basic_nsAReadableString<CharT>& );
|
||||
|
||||
|
||||
basic_nsAWritableString<CharT>&
|
||||
operator+=( const basic_nsAReadableString<CharT>& rhs )
|
||||
{
|
||||
Append(rhs);
|
||||
return *this;
|
||||
}
|
||||
void Replace( PRUint32 cutStart, PRUint32 cutLength, const basic_nsAReadableString<CharT>& );
|
||||
|
||||
basic_nsAWritableString<CharT>&
|
||||
operator+=( const basic_nsLiteralString<CharT>& rhs )
|
||||
{
|
||||
Append(rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
basic_nsAWritableString<CharT>&
|
||||
operator=( const basic_nsAReadableString<CharT>& rhs )
|
||||
{
|
||||
Assign(rhs);
|
||||
return *this;
|
||||
}
|
||||
protected:
|
||||
virtual void do_AssignFromReadable( const basic_nsAReadableString<CharT>& );
|
||||
// virtual void do_AssignFromIterators( nsReadingIterator<CharT>, nsReadingIterator<CharT> );
|
||||
virtual void do_AssignFromElementPtr( const CharT* );
|
||||
virtual void do_AssignFromElementPtrLength( const CharT*, PRUint32 );
|
||||
virtual void do_AssignFromElement( CharT );
|
||||
|
||||
basic_nsAWritableString<CharT>&
|
||||
operator=( const basic_nsLiteralString<CharT>& rhs )
|
||||
{
|
||||
Assign(rhs);
|
||||
return *this;
|
||||
}
|
||||
virtual void do_AppendFromReadable( const basic_nsAReadableString<CharT>& );
|
||||
// virtual void do_AppendFromIterators( nsReadingIterator<CharT>, nsReadingIterator<CharT> );
|
||||
virtual void do_AppendFromElementPtr( const CharT* );
|
||||
virtual void do_AppendFromElementPtrLength( const CharT*, PRUint32 );
|
||||
virtual void do_AppendFromElement( CharT );
|
||||
|
||||
virtual void do_InsertFromReadable( const basic_nsAReadableString<CharT>&, PRUint32 );
|
||||
// virtual void do_InsertFromIterators( nsReadingIterator<CharT>, nsReadingIterator<CharT>, PRUint32 );
|
||||
virtual void do_InsertFromElementPtr( const CharT*, PRUint32 );
|
||||
virtual void do_InsertFromElementPtrLength( const CharT*, PRUint32, PRUint32 );
|
||||
virtual void do_InsertFromElement( CharT, PRUint32 );
|
||||
};
|
||||
|
||||
|
||||
|
||||
//
|
||||
// |nsWritingIterator|s
|
||||
//
|
||||
|
||||
template <class CharT>
|
||||
inline
|
||||
void
|
||||
|
@ -326,53 +364,144 @@ operator==( const nsWritingIterator<CharT>& lhs, const nsWritingIterator<CharT>&
|
|||
return lhs.operator->() == rhs.operator->();
|
||||
}
|
||||
|
||||
template <class CharT>
|
||||
inline
|
||||
PRBool
|
||||
operator!=( const nsWritingIterator<CharT>& lhs, const nsWritingIterator<CharT>& rhs )
|
||||
{
|
||||
return lhs.operator->() != rhs.operator->();
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// |Assign()|
|
||||
//
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::Assign( const basic_nsAReadableString<CharT>& rhs )
|
||||
basic_nsAWritableString<CharT>::do_AssignFromReadable( const basic_nsAReadableString<CharT>& rhs )
|
||||
{
|
||||
SetLength(rhs.Length());
|
||||
copy_string(rhs.BeginReading(), rhs.EndReading(), BeginWriting());
|
||||
}
|
||||
|
||||
#if 0
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::Append( const basic_nsAReadableString<CharT>& rhs )
|
||||
basic_nsAWritableString<CharT>::do_AssignFromIterators( const nsReadingIterator<CharT>& aStart, const nsReadingIterator<CharT>& aEnd )
|
||||
{
|
||||
SetLength(distance(aStart, aEnd));
|
||||
copy_string(aStart, aEnd, BeginWriting());
|
||||
}
|
||||
#endif
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::do_AssignFromElementPtr( const CharT* aPtr )
|
||||
{
|
||||
do_AssignFromReadable(basic_nsLiteralString<CharT>(aPtr));
|
||||
}
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::do_AssignFromElementPtrLength( const CharT* aPtr, PRUint32 aLength )
|
||||
{
|
||||
do_AssignFromReadable(basic_nsLiteralString<CharT>(aPtr, aLength));
|
||||
}
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::do_AssignFromElement( CharT aChar )
|
||||
{
|
||||
do_AssignFromReadable(basic_nsLiteralChar<CharT>(aChar));
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// |Append()|
|
||||
//
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::do_AppendFromReadable( const basic_nsAReadableString<CharT>& rhs )
|
||||
{
|
||||
PRUint32 oldLength = Length();
|
||||
SetLength(oldLength + rhs.Length());
|
||||
copy_string(rhs.BeginReading(), rhs.EndReading(), BeginWriting(oldLength));
|
||||
}
|
||||
|
||||
#if 0
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::AppendChar( CharT aChar )
|
||||
basic_nsAWritableString<CharT>::do_AppendFromIterators( const nsReadingIterator<CharT>& aStart, const nsReadingIterator<CharT>& aEnd )
|
||||
{
|
||||
SetLength(Length()+1);
|
||||
*EndWriting(1) = aChar;
|
||||
PRUint32 oldLength = Length();
|
||||
SetLength(oldLength + distance(aStart, aEnd));
|
||||
copy_string(aStart, aEnd, BeginWriting(oldLength));
|
||||
}
|
||||
#endif
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::do_AppendFromElementPtr( const CharT* aChar )
|
||||
{
|
||||
do_AppendFromReadable(basic_nsLiteralString<CharT>(aChar));
|
||||
}
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::Insert( const basic_nsAReadableString<CharT>& aReadable, PRUint32 aPosition )
|
||||
basic_nsAWritableString<CharT>::do_AppendFromElementPtrLength( const CharT* aChar, PRUint32 aLength )
|
||||
{
|
||||
do_AppendFromReadable(basic_nsLiteralString<CharT>(aChar, aLength));
|
||||
}
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::do_AppendFromElement( CharT aChar )
|
||||
{
|
||||
do_AppendFromReadable(basic_nsLiteralChar<CharT>(aChar));
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// |Insert()|
|
||||
//
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::do_InsertFromReadable( const basic_nsAReadableString<CharT>& aReadable, PRUint32 atPosition )
|
||||
{
|
||||
PRUint32 oldLength = Length();
|
||||
SetLength(oldLength + aReadable.Length());
|
||||
if ( aPosition < oldLength )
|
||||
copy_string_backward(BeginReading(aPosition), BeginReading(oldLength), EndWriting());
|
||||
if ( atPosition < oldLength )
|
||||
copy_string_backward(BeginReading(atPosition), BeginReading(oldLength), EndWriting());
|
||||
else
|
||||
aPosition = oldLength;
|
||||
copy_string(aReadable.BeginReading(), aReadable.EndReading(), BeginWriting(aPosition));
|
||||
atPosition = oldLength;
|
||||
copy_string(aReadable.BeginReading(), aReadable.EndReading(), BeginWriting(atPosition));
|
||||
}
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::do_InsertFromElementPtr( const CharT* aPtr, PRUint32 atPosition )
|
||||
{
|
||||
do_InsertFromReadable(basic_nsLiteralString<CharT>(aPtr), atPosition);
|
||||
}
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::do_InsertFromElementPtrLength( const CharT* aPtr, PRUint32 atPosition, PRUint32 aLength )
|
||||
{
|
||||
do_InsertFromReadable(basic_nsLiteralString<CharT>(aPtr, aLength), atPosition);
|
||||
}
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::do_InsertFromElement( CharT aChar, PRUint32 atPosition )
|
||||
{
|
||||
do_InsertFromReadable(basic_nsLiteralChar<CharT>(aChar), atPosition);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// |Cut()|
|
||||
//
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::Cut( PRUint32 cutStart, PRUint32 cutLength )
|
||||
|
@ -381,6 +510,12 @@ basic_nsAWritableString<CharT>::Cut( PRUint32 cutStart, PRUint32 cutLength )
|
|||
SetLength(Length()-cutLength);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// |Replace()|
|
||||
//
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::Replace( PRUint32 cutStart, PRUint32 cutLength, const basic_nsAReadableString<CharT>& aReplacement )
|
||||
|
@ -405,8 +540,11 @@ basic_nsAWritableString<CharT>::Replace( PRUint32 cutStart, PRUint32 cutLength,
|
|||
copy_string(aReplacement.BeginReading(), aReplacement.EndReading(), BeginWriting(cutStart));
|
||||
}
|
||||
|
||||
// operator>>
|
||||
// getline (maybe)
|
||||
|
||||
|
||||
//
|
||||
// Types
|
||||
//
|
||||
|
||||
typedef basic_nsAWritableString<PRUnichar> nsAWritableString;
|
||||
typedef basic_nsAWritableString<char> nsAWritableCString;
|
||||
|
|
|
@ -69,7 +69,10 @@ class basic_nsSharedString
|
|||
{
|
||||
nsrefcnt result = --mRefCount;
|
||||
if ( !mRefCount )
|
||||
delete this;
|
||||
{
|
||||
delete this;
|
||||
// BULLSHIT ALERT: need to make |delete| match |new|
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -109,7 +112,7 @@ class nsSharedStringPtr
|
|||
// ...
|
||||
|
||||
private:
|
||||
basic_nsSharedString<CharT>* mPtr;
|
||||
basic_nsSharedString<CharT>* mRawPtr;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -232,7 +232,11 @@ class basic_nsAReadableString
|
|||
*/
|
||||
{
|
||||
public:
|
||||
typedef nsReadingIterator<CharT> ConstIterator;
|
||||
typedef PRUint32 size_type;
|
||||
typedef PRUint32 index_type;
|
||||
|
||||
typedef nsReadingIterator<CharT> const_iterator;
|
||||
|
||||
|
||||
|
||||
virtual ~basic_nsAReadableString() { }
|
||||
|
@ -615,7 +619,10 @@ class basic_nsLiteralString
|
|||
: mStart(aLiteral),
|
||||
mEnd(mStart + aLength)
|
||||
{
|
||||
// nothing else to do here
|
||||
// This is an annoying hack. Callers should be fixed to use the other
|
||||
// constructor if they don't really know the length.
|
||||
if ( aLength == PRUint32(-1) )
|
||||
mEnd = mStart + nsCharTraits<CharT>::length(mStart);
|
||||
}
|
||||
|
||||
virtual PRUint32 Length() const;
|
||||
|
@ -658,6 +665,59 @@ basic_nsLiteralString<CharT>::Length() const
|
|||
|
||||
|
||||
|
||||
//
|
||||
// nsLiteralChar, nsLiteralPRUnichar
|
||||
//
|
||||
|
||||
template <class CharT>
|
||||
class basic_nsLiteralChar
|
||||
: public basic_nsAReadableString<CharT>
|
||||
{
|
||||
protected:
|
||||
virtual const CharT* GetReadableFragment( nsReadableFragment<CharT>&, nsFragmentRequest, PRUint32 ) const;
|
||||
|
||||
public:
|
||||
|
||||
basic_nsLiteralChar( CharT aChar )
|
||||
: mChar(aChar)
|
||||
{
|
||||
// nothing else to do here
|
||||
}
|
||||
|
||||
virtual
|
||||
PRUint32
|
||||
Length() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
private:
|
||||
CharT mChar;
|
||||
};
|
||||
|
||||
template <class CharT>
|
||||
const CharT*
|
||||
basic_nsLiteralChar<CharT>::GetReadableFragment( nsReadableFragment<CharT>& aFragment, nsFragmentRequest aRequest, PRUint32 aOffset ) const
|
||||
{
|
||||
switch ( aRequest )
|
||||
{
|
||||
case kFirstFragment:
|
||||
case kLastFragment:
|
||||
case kFragmentAt:
|
||||
aFragment.mEnd = (aFragment.mStart = &mChar) + 1;
|
||||
return aFragment.mStart + aOffset;
|
||||
|
||||
case kPrevFragment:
|
||||
case kNextFragment:
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
// nsPromiseConcatenation
|
||||
|
@ -1107,5 +1167,8 @@ typedef basic_nsLiteralString<char> nsLiteralCString;
|
|||
#define NS_LITERAL_STRING(s) nsLiteralString(s, sizeof(s)/sizeof(wchar_t))
|
||||
#define NS_LITERAL_CSTRING(s) nsLiteralCString(s, sizeof(s))
|
||||
|
||||
typedef basic_nsLiteralChar<char> nsLiteralChar;
|
||||
typedef basic_nsLiteralChar<PRUnichar> nsLiteralPRUnichar;
|
||||
|
||||
|
||||
#endif // !defined(_nsAReadableString_h__)
|
||||
|
|
|
@ -200,7 +200,10 @@ class basic_nsAWritableString
|
|||
// friend class nsWritingIterator<CharT>;
|
||||
|
||||
public:
|
||||
typedef nsWritingIterator<CharT> Iterator;
|
||||
typedef PRUint32 size_type;
|
||||
typedef PRUint32 index_type;
|
||||
|
||||
typedef nsWritingIterator<CharT> iterator;
|
||||
|
||||
virtual CharT* GetWritableFragment( nsWritableFragment<CharT>&, nsFragmentRequest, PRUint32 = 0 ) = 0;
|
||||
|
||||
|
@ -255,49 +258,84 @@ class basic_nsAWritableString
|
|||
|
||||
|
||||
|
||||
virtual void Assign( const basic_nsAReadableString<CharT>& rhs );
|
||||
// virtual void AssignChar( CharT ) = 0;
|
||||
//
|
||||
// |operator=()|, |Assign()|
|
||||
//
|
||||
|
||||
basic_nsAWritableString<CharT>& operator=( const basic_nsAReadableString<CharT>& aReadable ) { do_AssignFromReadable(aReadable); return *this; }
|
||||
basic_nsAWritableString<CharT>& operator=( const CharT* aPtr ) { do_AssignFromElementPtr(aPtr); return *this; }
|
||||
basic_nsAWritableString<CharT>& operator=( CharT aChar ) { do_AssignFromElement(aChar); return *this; }
|
||||
|
||||
void Assign( const basic_nsAReadableString<CharT>& aReadable ) { do_AssignFromReadable(aReadable); }
|
||||
// void Assign( const nsReadingIterator<CharT>& aStart, const nsReadingIterator<CharT>& aEnd ) { do_AssignFromIterators(aStart, aEnd); }
|
||||
void Assign( const CharT* aPtr ) { do_AssignFromElementPtr(aPtr); }
|
||||
void Assign( const CharT* aPtr, PRUint32 aLength ) { do_AssignFromElementPtrLength(aPtr, aLength); }
|
||||
void Assign( CharT aChar ) { do_AssignFromElement(aChar); }
|
||||
|
||||
|
||||
|
||||
//
|
||||
// |operator+=()|, |Append()|
|
||||
//
|
||||
|
||||
basic_nsAWritableString<CharT>& operator+=( const basic_nsAReadableString<CharT>& aReadable ) { do_AppendFromReadable(aReadable); return *this; }
|
||||
basic_nsAWritableString<CharT>& operator+=( const CharT* aPtr ) { do_AppendFromElementPtr(aPtr); return *this; }
|
||||
basic_nsAWritableString<CharT>& operator+=( CharT aChar ) { do_AppendFromElement(aChar); return *this; }
|
||||
|
||||
void Append( const basic_nsAReadableString<CharT>& aReadable ) { do_AppendFromReadable(aReadable); }
|
||||
// void Append( const nsReadingIterator<CharT>& aStart, const nsReadingIterator<CharT>& aEnd ) { do_AppendFromIterators(aStart, aEnd); }
|
||||
void Append( const CharT* aPtr ) { do_AppendFromElementPtr(aPtr); }
|
||||
void Append( const CharT* aPtr, PRUint32 aLength ) { do_AppendFromElementPtrLength(aPtr, aLength); }
|
||||
void Append( CharT aChar ) { do_AppendFromElement(aChar); }
|
||||
|
||||
|
||||
|
||||
//
|
||||
// |Insert()|
|
||||
// Note: I would really like to move the |atPosition| parameter to the front of the argument list
|
||||
//
|
||||
|
||||
void Insert( const basic_nsAReadableString<CharT>& aReadable, PRUint32 atPosition ) { do_InsertFromReadable(aReadable, atPosition); }
|
||||
// void Insert( const nsReadingIterator<CharT>& aStart, const nsReadingIterator<CharT>& aEnd, PRUint32 atPosition ) { do_InsertFromIterators(aStart, aEnd, atPosition); }
|
||||
void Insert( const CharT* aPtr, PRUint32 atPosition ) { do_InsertFromElementPtr(aPtr, atPosition); }
|
||||
void Insert( const CharT* aPtr, PRUint32 atPosition, PRUint32 aLength ) { do_InsertFromElementPtrLength(aPtr, atPosition, aLength); }
|
||||
void Insert( CharT aChar, PRUint32 atPosition ) { do_InsertFromElement(aChar, atPosition); }
|
||||
|
||||
virtual void Append( const basic_nsAReadableString<CharT>& );
|
||||
virtual void AppendChar( CharT );
|
||||
|
||||
virtual void Insert( const basic_nsAReadableString<CharT>&, PRUint32 atPosition );
|
||||
// virtual void InsertChar( CharT, PRUint32 atPosition ) = 0;
|
||||
|
||||
virtual void Cut( PRUint32 cutStart, PRUint32 cutLength );
|
||||
|
||||
virtual void Replace( PRUint32 cutStart, PRUint32 cutLength, const basic_nsAReadableString<CharT>& );
|
||||
|
||||
|
||||
basic_nsAWritableString<CharT>&
|
||||
operator+=( const basic_nsAReadableString<CharT>& rhs )
|
||||
{
|
||||
Append(rhs);
|
||||
return *this;
|
||||
}
|
||||
void Replace( PRUint32 cutStart, PRUint32 cutLength, const basic_nsAReadableString<CharT>& );
|
||||
|
||||
basic_nsAWritableString<CharT>&
|
||||
operator+=( const basic_nsLiteralString<CharT>& rhs )
|
||||
{
|
||||
Append(rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
basic_nsAWritableString<CharT>&
|
||||
operator=( const basic_nsAReadableString<CharT>& rhs )
|
||||
{
|
||||
Assign(rhs);
|
||||
return *this;
|
||||
}
|
||||
protected:
|
||||
virtual void do_AssignFromReadable( const basic_nsAReadableString<CharT>& );
|
||||
// virtual void do_AssignFromIterators( nsReadingIterator<CharT>, nsReadingIterator<CharT> );
|
||||
virtual void do_AssignFromElementPtr( const CharT* );
|
||||
virtual void do_AssignFromElementPtrLength( const CharT*, PRUint32 );
|
||||
virtual void do_AssignFromElement( CharT );
|
||||
|
||||
basic_nsAWritableString<CharT>&
|
||||
operator=( const basic_nsLiteralString<CharT>& rhs )
|
||||
{
|
||||
Assign(rhs);
|
||||
return *this;
|
||||
}
|
||||
virtual void do_AppendFromReadable( const basic_nsAReadableString<CharT>& );
|
||||
// virtual void do_AppendFromIterators( nsReadingIterator<CharT>, nsReadingIterator<CharT> );
|
||||
virtual void do_AppendFromElementPtr( const CharT* );
|
||||
virtual void do_AppendFromElementPtrLength( const CharT*, PRUint32 );
|
||||
virtual void do_AppendFromElement( CharT );
|
||||
|
||||
virtual void do_InsertFromReadable( const basic_nsAReadableString<CharT>&, PRUint32 );
|
||||
// virtual void do_InsertFromIterators( nsReadingIterator<CharT>, nsReadingIterator<CharT>, PRUint32 );
|
||||
virtual void do_InsertFromElementPtr( const CharT*, PRUint32 );
|
||||
virtual void do_InsertFromElementPtrLength( const CharT*, PRUint32, PRUint32 );
|
||||
virtual void do_InsertFromElement( CharT, PRUint32 );
|
||||
};
|
||||
|
||||
|
||||
|
||||
//
|
||||
// |nsWritingIterator|s
|
||||
//
|
||||
|
||||
template <class CharT>
|
||||
inline
|
||||
void
|
||||
|
@ -326,53 +364,144 @@ operator==( const nsWritingIterator<CharT>& lhs, const nsWritingIterator<CharT>&
|
|||
return lhs.operator->() == rhs.operator->();
|
||||
}
|
||||
|
||||
template <class CharT>
|
||||
inline
|
||||
PRBool
|
||||
operator!=( const nsWritingIterator<CharT>& lhs, const nsWritingIterator<CharT>& rhs )
|
||||
{
|
||||
return lhs.operator->() != rhs.operator->();
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// |Assign()|
|
||||
//
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::Assign( const basic_nsAReadableString<CharT>& rhs )
|
||||
basic_nsAWritableString<CharT>::do_AssignFromReadable( const basic_nsAReadableString<CharT>& rhs )
|
||||
{
|
||||
SetLength(rhs.Length());
|
||||
copy_string(rhs.BeginReading(), rhs.EndReading(), BeginWriting());
|
||||
}
|
||||
|
||||
#if 0
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::Append( const basic_nsAReadableString<CharT>& rhs )
|
||||
basic_nsAWritableString<CharT>::do_AssignFromIterators( const nsReadingIterator<CharT>& aStart, const nsReadingIterator<CharT>& aEnd )
|
||||
{
|
||||
SetLength(distance(aStart, aEnd));
|
||||
copy_string(aStart, aEnd, BeginWriting());
|
||||
}
|
||||
#endif
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::do_AssignFromElementPtr( const CharT* aPtr )
|
||||
{
|
||||
do_AssignFromReadable(basic_nsLiteralString<CharT>(aPtr));
|
||||
}
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::do_AssignFromElementPtrLength( const CharT* aPtr, PRUint32 aLength )
|
||||
{
|
||||
do_AssignFromReadable(basic_nsLiteralString<CharT>(aPtr, aLength));
|
||||
}
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::do_AssignFromElement( CharT aChar )
|
||||
{
|
||||
do_AssignFromReadable(basic_nsLiteralChar<CharT>(aChar));
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// |Append()|
|
||||
//
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::do_AppendFromReadable( const basic_nsAReadableString<CharT>& rhs )
|
||||
{
|
||||
PRUint32 oldLength = Length();
|
||||
SetLength(oldLength + rhs.Length());
|
||||
copy_string(rhs.BeginReading(), rhs.EndReading(), BeginWriting(oldLength));
|
||||
}
|
||||
|
||||
#if 0
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::AppendChar( CharT aChar )
|
||||
basic_nsAWritableString<CharT>::do_AppendFromIterators( const nsReadingIterator<CharT>& aStart, const nsReadingIterator<CharT>& aEnd )
|
||||
{
|
||||
SetLength(Length()+1);
|
||||
*EndWriting(1) = aChar;
|
||||
PRUint32 oldLength = Length();
|
||||
SetLength(oldLength + distance(aStart, aEnd));
|
||||
copy_string(aStart, aEnd, BeginWriting(oldLength));
|
||||
}
|
||||
#endif
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::do_AppendFromElementPtr( const CharT* aChar )
|
||||
{
|
||||
do_AppendFromReadable(basic_nsLiteralString<CharT>(aChar));
|
||||
}
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::Insert( const basic_nsAReadableString<CharT>& aReadable, PRUint32 aPosition )
|
||||
basic_nsAWritableString<CharT>::do_AppendFromElementPtrLength( const CharT* aChar, PRUint32 aLength )
|
||||
{
|
||||
do_AppendFromReadable(basic_nsLiteralString<CharT>(aChar, aLength));
|
||||
}
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::do_AppendFromElement( CharT aChar )
|
||||
{
|
||||
do_AppendFromReadable(basic_nsLiteralChar<CharT>(aChar));
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// |Insert()|
|
||||
//
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::do_InsertFromReadable( const basic_nsAReadableString<CharT>& aReadable, PRUint32 atPosition )
|
||||
{
|
||||
PRUint32 oldLength = Length();
|
||||
SetLength(oldLength + aReadable.Length());
|
||||
if ( aPosition < oldLength )
|
||||
copy_string_backward(BeginReading(aPosition), BeginReading(oldLength), EndWriting());
|
||||
if ( atPosition < oldLength )
|
||||
copy_string_backward(BeginReading(atPosition), BeginReading(oldLength), EndWriting());
|
||||
else
|
||||
aPosition = oldLength;
|
||||
copy_string(aReadable.BeginReading(), aReadable.EndReading(), BeginWriting(aPosition));
|
||||
atPosition = oldLength;
|
||||
copy_string(aReadable.BeginReading(), aReadable.EndReading(), BeginWriting(atPosition));
|
||||
}
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::do_InsertFromElementPtr( const CharT* aPtr, PRUint32 atPosition )
|
||||
{
|
||||
do_InsertFromReadable(basic_nsLiteralString<CharT>(aPtr), atPosition);
|
||||
}
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::do_InsertFromElementPtrLength( const CharT* aPtr, PRUint32 atPosition, PRUint32 aLength )
|
||||
{
|
||||
do_InsertFromReadable(basic_nsLiteralString<CharT>(aPtr, aLength), atPosition);
|
||||
}
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::do_InsertFromElement( CharT aChar, PRUint32 atPosition )
|
||||
{
|
||||
do_InsertFromReadable(basic_nsLiteralChar<CharT>(aChar), atPosition);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// |Cut()|
|
||||
//
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::Cut( PRUint32 cutStart, PRUint32 cutLength )
|
||||
|
@ -381,6 +510,12 @@ basic_nsAWritableString<CharT>::Cut( PRUint32 cutStart, PRUint32 cutLength )
|
|||
SetLength(Length()-cutLength);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// |Replace()|
|
||||
//
|
||||
|
||||
template <class CharT>
|
||||
void
|
||||
basic_nsAWritableString<CharT>::Replace( PRUint32 cutStart, PRUint32 cutLength, const basic_nsAReadableString<CharT>& aReplacement )
|
||||
|
@ -405,8 +540,11 @@ basic_nsAWritableString<CharT>::Replace( PRUint32 cutStart, PRUint32 cutLength,
|
|||
copy_string(aReplacement.BeginReading(), aReplacement.EndReading(), BeginWriting(cutStart));
|
||||
}
|
||||
|
||||
// operator>>
|
||||
// getline (maybe)
|
||||
|
||||
|
||||
//
|
||||
// Types
|
||||
//
|
||||
|
||||
typedef basic_nsAWritableString<PRUnichar> nsAWritableString;
|
||||
typedef basic_nsAWritableString<char> nsAWritableCString;
|
||||
|
|
|
@ -69,7 +69,10 @@ class basic_nsSharedString
|
|||
{
|
||||
nsrefcnt result = --mRefCount;
|
||||
if ( !mRefCount )
|
||||
delete this;
|
||||
{
|
||||
delete this;
|
||||
// BULLSHIT ALERT: need to make |delete| match |new|
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -109,7 +112,7 @@ class nsSharedStringPtr
|
|||
// ...
|
||||
|
||||
private:
|
||||
basic_nsSharedString<CharT>* mPtr;
|
||||
basic_nsSharedString<CharT>* mRawPtr;
|
||||
};
|
||||
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче