This commit is contained in:
scc%netscape.com 2000-04-27 20:01:28 +00:00
Родитель fc84b78a4e
Коммит 0ef80f2c28
6 изменённых файлов: 318 добавлений и 30 удалений

Просмотреть файл

@ -336,6 +336,14 @@ class basic_nsAReadableString
// protected:
virtual const void* Implementation() const;
virtual const CharT* GetReadableFragment( nsReadableFragment<CharT>&, nsFragmentRequest, PRUint32 = 0 ) const = 0;
virtual PRBool Promises( const basic_nsAReadableString<CharT>& aString ) const { return &aString == this; }
private:
// NOT TO BE IMPLEMENTED
typedef typename nsCharTraits<CharT>::incompatible_char_type incompatible_char_type;
PRUint32 CountChar( incompatible_char_type ) const;
// in Compare( incompatible_char_type ) const;
// PRBool Equals( incompatible_char_type ) const;
};
template <class CharT>
@ -513,7 +521,7 @@ basic_nsAReadableString<CharT>::CountChar( CharT c ) const
nsReadingIterator<CharT> iter( BeginReading() );
for (;;)
{
PRUint32 lengthToExamineInThisFragment = iter.size_forward();
PRInt32 lengthToExamineInThisFragment = iter.size_forward();
result += PRUint32(count(iter.operator->(), iter.operator->()+lengthToExamineInThisFragment, c));
if ( !(lengthToExamine -= lengthToExamineInThisFragment) )
return result;
@ -750,9 +758,11 @@ basic_nsLiteralChar<CharT>::GetReadableFragment( nsReadableFragment<CharT>& aFra
// nsPromiseConcatenation
//
template <class CharT> class nsPromiseReadable : public basic_nsAReadableString<CharT> { };
template <class CharT>
class nsPromiseConcatenation
: public basic_nsAReadableString<CharT>
: public nsPromiseReadable<CharT>
/*
NOT FOR USE BY HUMANS
@ -807,6 +817,7 @@ class nsPromiseConcatenation
}
virtual PRUint32 Length() const;
virtual PRBool Promises( const basic_nsAReadableString<CharT>& ) const;
nsPromiseConcatenation<CharT> operator+( const basic_nsAReadableString<CharT>& rhs ) const;
@ -829,6 +840,13 @@ nsPromiseConcatenation<CharT>::Length() const
return mStrings[kLeftString]->Length() + mStrings[kRightString]->Length();
}
template <class CharT>
PRBool
nsPromiseConcatenation<CharT>::Promises( const basic_nsAReadableString<CharT>& aString ) const
{
return mStrings[0]->Promises(aString) || mStrings[1]->Promises(aString);
}
template <class CharT>
const CharT*
nsPromiseConcatenation<CharT>::GetReadableFragment( nsReadableFragment<CharT>& aFragment, nsFragmentRequest aRequest, PRUint32 aPosition ) const
@ -866,15 +884,15 @@ nsPromiseConcatenation<CharT>::GetReadableFragment( nsReadableFragment<CharT>& a
}
const CharT* result;
bool done;
PRBool done;
do
{
done = true;
done = PR_TRUE;
result = mStrings[whichString]->GetReadableFragment(aFragment, aRequest, aPosition);
if ( !result )
{
done = false;
done = PR_FALSE;
if ( aRequest == kNextFragment && whichString == kLeftString )
{
aRequest = kFirstFragment;
@ -886,7 +904,7 @@ nsPromiseConcatenation<CharT>::GetReadableFragment( nsReadableFragment<CharT>& a
whichString = SetLeftStringInFragment(aFragment);
}
else
done = true;
done = PR_TRUE;
}
}
while ( !done );
@ -912,7 +930,7 @@ nsPromiseConcatenation<CharT>::operator+( const basic_nsAReadableString<CharT>&
template <class CharT>
class nsPromiseSubstring
: public basic_nsAReadableString<CharT>
: public nsPromiseReadable<CharT>
/*
NOT FOR USE BY HUMANS (mostly)
@ -935,6 +953,7 @@ class nsPromiseSubstring
}
virtual PRUint32 Length() const;
virtual PRBool Promises( const basic_nsAReadableString<CharT>& aString ) const { return mString.Promises(aString); }
private:
const basic_nsAReadableString<CharT>& mString;
@ -1037,6 +1056,11 @@ template <class CharT>
nsPromiseSubstring<CharT>
Substring( const basic_nsAReadableString<CharT>& aString, PRUint32 aStartPos, PRUint32 aSubstringLength )
{
#if 0
// signatures don't work, but consider this twist to help in assignments
if ( aSubstringLength == aString.Length() && aStartPos == 0 )
return aString;
#endif
return nsPromiseSubstring<CharT>(aString, aStartPos, aSubstringLength);
}

Просмотреть файл

@ -274,10 +274,12 @@ class basic_nsAWritableString
//
basic_nsAWritableString<CharT>& operator=( const basic_nsAReadableString<CharT>& aReadable ) { do_AssignFromReadable(aReadable); return *this; }
basic_nsAWritableString<CharT>& operator=( const nsPromiseReadable<CharT>& aReadable ) { Assign(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 nsPromiseReadable<CharT>& aReadable ) { aReadable.Promises(*this) ? AssignFromPromise(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); }
@ -290,10 +292,12 @@ class basic_nsAWritableString
//
basic_nsAWritableString<CharT>& operator+=( const basic_nsAReadableString<CharT>& aReadable ) { do_AppendFromReadable(aReadable); return *this; }
basic_nsAWritableString<CharT>& operator+=( const nsPromiseReadable<CharT>& aReadable ) { Append(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 nsPromiseReadable<CharT>& aReadable ) { aReadable.Promises(*this) ? AppendFromPromise(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); }
@ -307,6 +311,7 @@ class basic_nsAWritableString
//
void Insert( const basic_nsAReadableString<CharT>& aReadable, PRUint32 atPosition ) { do_InsertFromReadable(aReadable, atPosition); }
void Insert( const nsPromiseReadable<CharT>& aReadable, PRUint32 atPosition ) { aReadable.Promises(*this) ? InsertFromPromise(aReadable, 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); }
@ -318,8 +323,12 @@ class basic_nsAWritableString
void Replace( PRUint32 cutStart, PRUint32 cutLength, const basic_nsAReadableString<CharT>& );
void Replace( PRUint32 cutStart, PRUint32 cutLength, const basic_nsAReadableString<CharT>& aReadable ) { do_ReplaceFromReadable(cutStart, cutLength, aReadable); }
void Replace( PRUint32 cutStart, PRUint32 cutLength, const nsPromiseReadable<CharT>& aReadable ) { aReadable.Promises(*this) ? ReplaceFromPromise(cutStart, cutLength, aReadable) : do_ReplaceFromReadable(cutStart, cutLength, aReadable); }
// void Replace( PRUint32, PRUint32, const nsReadingIterator<CharT>&, const nsReadingIterator<CharT>& );
// void Replace( PRUint32, PRUint32, const CharT* );
// void Replace( PRUint32, PRUint32, const CharT*, PRUint32 );
// void Replace( PRUint32, PRUint32, CharT );
private:
typedef typename nsCharTraits<CharT>::incompatible_char_type incompatible_char_type;
@ -330,26 +339,37 @@ class basic_nsAWritableString
void operator+= ( incompatible_char_type );
void Append ( incompatible_char_type );
void Insert ( incompatible_char_type, PRUint32 );
// void Replace ( PRUint32, PRUint32, incompatible_char_type );
protected:
virtual void do_AssignFromReadable( const basic_nsAReadableString<CharT>& );
void AssignFromPromise( const nsPromiseReadable<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 );
virtual void do_AppendFromReadable( const basic_nsAReadableString<CharT>& );
void AppendFromPromise( const nsPromiseReadable<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 );
void InsertFromPromise( const nsPromiseReadable<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 );
virtual void do_ReplaceFromReadable( PRUint32, PRUint32, const basic_nsAReadableString<CharT>& );
void ReplaceFromPromise( PRUint32 cutStart, PRUint32 cutLength, const nsPromiseReadable<CharT>& );
// virtual void do_ReplaceFromIterators( ... );
// virtual void do_ReplaceFromElementPtr( ... );
// virtual void do_ReplaceFromElementPtrLength( ... );
// virtual void do_ReplaceFromElement( ... );
};
@ -410,6 +430,19 @@ basic_nsAWritableString<CharT>::do_AssignFromReadable( const basic_nsAReadableSt
copy_string(rhs.BeginReading(), rhs.EndReading(), BeginWriting());
}
template <class CharT>
void
basic_nsAWritableString<CharT>::AssignFromPromise( const nsPromiseReadable<CharT>& aReadable )
{
PRUint32 length = aReadable.Length();
if ( CharT* buffer = new CharT[length] )
{
copy_string(aReadable.BeginReading(), aReadable.EndReading(), buffer);
do_AssignFromElementPtrLength(buffer, length);
delete buffer;
}
}
#if 0
template <class CharT>
void
@ -456,6 +489,19 @@ basic_nsAWritableString<CharT>::do_AppendFromReadable( const basic_nsAReadableSt
copy_string(rhs.BeginReading(), rhs.EndReading(), BeginWriting(oldLength));
}
template <class CharT>
void
basic_nsAWritableString<CharT>::AppendFromPromise( const nsPromiseReadable<CharT>& aReadable )
{
PRUint32 length = aReadable.Length();
if ( CharT* buffer = new CharT[length] )
{
copy_string(aReadable.BeginReading(), aReadable.EndReading(), buffer);
do_AppendFromElementPtrLength(buffer, length);
delete buffer;
}
}
#if 0
template <class CharT>
void
@ -511,6 +557,19 @@ basic_nsAWritableString<CharT>::do_InsertFromReadable( const basic_nsAReadableSt
copy_string(aReadable.BeginReading(), aReadable.EndReading(), BeginWriting(atPosition));
}
template <class CharT>
void
basic_nsAWritableString<CharT>::InsertFromPromise( const nsPromiseReadable<CharT>& aReadable, PRUint32 atPosition )
{
PRUint32 length = aReadable.Length();
if ( CharT* buffer = new CharT[length] )
{
copy_string(aReadable.BeginReading(), aReadable.EndReading(), buffer);
do_InsertFromElementPtrLength(buffer, atPosition, length);
delete buffer;
}
}
template <class CharT>
void
basic_nsAWritableString<CharT>::do_InsertFromElementPtr( const CharT* aPtr, PRUint32 atPosition )
@ -554,7 +613,7 @@ basic_nsAWritableString<CharT>::Cut( PRUint32 cutStart, PRUint32 cutLength )
template <class CharT>
void
basic_nsAWritableString<CharT>::Replace( PRUint32 cutStart, PRUint32 cutLength, const basic_nsAReadableString<CharT>& aReplacement )
basic_nsAWritableString<CharT>::do_ReplaceFromReadable( PRUint32 cutStart, PRUint32 cutLength, const basic_nsAReadableString<CharT>& aReplacement )
{
PRUint32 oldLength = Length();
@ -576,6 +635,19 @@ basic_nsAWritableString<CharT>::Replace( PRUint32 cutStart, PRUint32 cutLength,
copy_string(aReplacement.BeginReading(), aReplacement.EndReading(), BeginWriting(cutStart));
}
template <class CharT>
void
basic_nsAWritableString<CharT>::ReplaceFromPromise( PRUint32 cutStart, PRUint32 cutLength, const nsPromiseReadable<CharT>& aReadable )
{
PRUint32 length = aReadable.Length();
if ( CharT* buffer = new CharT[length] )
{
copy_string(aReadable.BeginReading(), aReadable.EndReading(), buffer);
do_ReplaceFromReadable(cutStart, cutLength, basic_nsLiteralString<CharT>(buffer, length));
delete buffer;
}
}
//

Просмотреть файл

@ -336,6 +336,14 @@ class basic_nsAReadableString
// protected:
virtual const void* Implementation() const;
virtual const CharT* GetReadableFragment( nsReadableFragment<CharT>&, nsFragmentRequest, PRUint32 = 0 ) const = 0;
virtual PRBool Promises( const basic_nsAReadableString<CharT>& aString ) const { return &aString == this; }
private:
// NOT TO BE IMPLEMENTED
typedef typename nsCharTraits<CharT>::incompatible_char_type incompatible_char_type;
PRUint32 CountChar( incompatible_char_type ) const;
// in Compare( incompatible_char_type ) const;
// PRBool Equals( incompatible_char_type ) const;
};
template <class CharT>
@ -513,7 +521,7 @@ basic_nsAReadableString<CharT>::CountChar( CharT c ) const
nsReadingIterator<CharT> iter( BeginReading() );
for (;;)
{
PRUint32 lengthToExamineInThisFragment = iter.size_forward();
PRInt32 lengthToExamineInThisFragment = iter.size_forward();
result += PRUint32(count(iter.operator->(), iter.operator->()+lengthToExamineInThisFragment, c));
if ( !(lengthToExamine -= lengthToExamineInThisFragment) )
return result;
@ -750,9 +758,11 @@ basic_nsLiteralChar<CharT>::GetReadableFragment( nsReadableFragment<CharT>& aFra
// nsPromiseConcatenation
//
template <class CharT> class nsPromiseReadable : public basic_nsAReadableString<CharT> { };
template <class CharT>
class nsPromiseConcatenation
: public basic_nsAReadableString<CharT>
: public nsPromiseReadable<CharT>
/*
NOT FOR USE BY HUMANS
@ -807,6 +817,7 @@ class nsPromiseConcatenation
}
virtual PRUint32 Length() const;
virtual PRBool Promises( const basic_nsAReadableString<CharT>& ) const;
nsPromiseConcatenation<CharT> operator+( const basic_nsAReadableString<CharT>& rhs ) const;
@ -829,6 +840,13 @@ nsPromiseConcatenation<CharT>::Length() const
return mStrings[kLeftString]->Length() + mStrings[kRightString]->Length();
}
template <class CharT>
PRBool
nsPromiseConcatenation<CharT>::Promises( const basic_nsAReadableString<CharT>& aString ) const
{
return mStrings[0]->Promises(aString) || mStrings[1]->Promises(aString);
}
template <class CharT>
const CharT*
nsPromiseConcatenation<CharT>::GetReadableFragment( nsReadableFragment<CharT>& aFragment, nsFragmentRequest aRequest, PRUint32 aPosition ) const
@ -866,15 +884,15 @@ nsPromiseConcatenation<CharT>::GetReadableFragment( nsReadableFragment<CharT>& a
}
const CharT* result;
bool done;
PRBool done;
do
{
done = true;
done = PR_TRUE;
result = mStrings[whichString]->GetReadableFragment(aFragment, aRequest, aPosition);
if ( !result )
{
done = false;
done = PR_FALSE;
if ( aRequest == kNextFragment && whichString == kLeftString )
{
aRequest = kFirstFragment;
@ -886,7 +904,7 @@ nsPromiseConcatenation<CharT>::GetReadableFragment( nsReadableFragment<CharT>& a
whichString = SetLeftStringInFragment(aFragment);
}
else
done = true;
done = PR_TRUE;
}
}
while ( !done );
@ -912,7 +930,7 @@ nsPromiseConcatenation<CharT>::operator+( const basic_nsAReadableString<CharT>&
template <class CharT>
class nsPromiseSubstring
: public basic_nsAReadableString<CharT>
: public nsPromiseReadable<CharT>
/*
NOT FOR USE BY HUMANS (mostly)
@ -935,6 +953,7 @@ class nsPromiseSubstring
}
virtual PRUint32 Length() const;
virtual PRBool Promises( const basic_nsAReadableString<CharT>& aString ) const { return mString.Promises(aString); }
private:
const basic_nsAReadableString<CharT>& mString;
@ -1037,6 +1056,11 @@ template <class CharT>
nsPromiseSubstring<CharT>
Substring( const basic_nsAReadableString<CharT>& aString, PRUint32 aStartPos, PRUint32 aSubstringLength )
{
#if 0
// signatures don't work, but consider this twist to help in assignments
if ( aSubstringLength == aString.Length() && aStartPos == 0 )
return aString;
#endif
return nsPromiseSubstring<CharT>(aString, aStartPos, aSubstringLength);
}

Просмотреть файл

@ -274,10 +274,12 @@ class basic_nsAWritableString
//
basic_nsAWritableString<CharT>& operator=( const basic_nsAReadableString<CharT>& aReadable ) { do_AssignFromReadable(aReadable); return *this; }
basic_nsAWritableString<CharT>& operator=( const nsPromiseReadable<CharT>& aReadable ) { Assign(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 nsPromiseReadable<CharT>& aReadable ) { aReadable.Promises(*this) ? AssignFromPromise(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); }
@ -290,10 +292,12 @@ class basic_nsAWritableString
//
basic_nsAWritableString<CharT>& operator+=( const basic_nsAReadableString<CharT>& aReadable ) { do_AppendFromReadable(aReadable); return *this; }
basic_nsAWritableString<CharT>& operator+=( const nsPromiseReadable<CharT>& aReadable ) { Append(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 nsPromiseReadable<CharT>& aReadable ) { aReadable.Promises(*this) ? AppendFromPromise(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); }
@ -307,6 +311,7 @@ class basic_nsAWritableString
//
void Insert( const basic_nsAReadableString<CharT>& aReadable, PRUint32 atPosition ) { do_InsertFromReadable(aReadable, atPosition); }
void Insert( const nsPromiseReadable<CharT>& aReadable, PRUint32 atPosition ) { aReadable.Promises(*this) ? InsertFromPromise(aReadable, 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); }
@ -318,8 +323,12 @@ class basic_nsAWritableString
void Replace( PRUint32 cutStart, PRUint32 cutLength, const basic_nsAReadableString<CharT>& );
void Replace( PRUint32 cutStart, PRUint32 cutLength, const basic_nsAReadableString<CharT>& aReadable ) { do_ReplaceFromReadable(cutStart, cutLength, aReadable); }
void Replace( PRUint32 cutStart, PRUint32 cutLength, const nsPromiseReadable<CharT>& aReadable ) { aReadable.Promises(*this) ? ReplaceFromPromise(cutStart, cutLength, aReadable) : do_ReplaceFromReadable(cutStart, cutLength, aReadable); }
// void Replace( PRUint32, PRUint32, const nsReadingIterator<CharT>&, const nsReadingIterator<CharT>& );
// void Replace( PRUint32, PRUint32, const CharT* );
// void Replace( PRUint32, PRUint32, const CharT*, PRUint32 );
// void Replace( PRUint32, PRUint32, CharT );
private:
typedef typename nsCharTraits<CharT>::incompatible_char_type incompatible_char_type;
@ -330,26 +339,37 @@ class basic_nsAWritableString
void operator+= ( incompatible_char_type );
void Append ( incompatible_char_type );
void Insert ( incompatible_char_type, PRUint32 );
// void Replace ( PRUint32, PRUint32, incompatible_char_type );
protected:
virtual void do_AssignFromReadable( const basic_nsAReadableString<CharT>& );
void AssignFromPromise( const nsPromiseReadable<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 );
virtual void do_AppendFromReadable( const basic_nsAReadableString<CharT>& );
void AppendFromPromise( const nsPromiseReadable<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 );
void InsertFromPromise( const nsPromiseReadable<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 );
virtual void do_ReplaceFromReadable( PRUint32, PRUint32, const basic_nsAReadableString<CharT>& );
void ReplaceFromPromise( PRUint32 cutStart, PRUint32 cutLength, const nsPromiseReadable<CharT>& );
// virtual void do_ReplaceFromIterators( ... );
// virtual void do_ReplaceFromElementPtr( ... );
// virtual void do_ReplaceFromElementPtrLength( ... );
// virtual void do_ReplaceFromElement( ... );
};
@ -410,6 +430,19 @@ basic_nsAWritableString<CharT>::do_AssignFromReadable( const basic_nsAReadableSt
copy_string(rhs.BeginReading(), rhs.EndReading(), BeginWriting());
}
template <class CharT>
void
basic_nsAWritableString<CharT>::AssignFromPromise( const nsPromiseReadable<CharT>& aReadable )
{
PRUint32 length = aReadable.Length();
if ( CharT* buffer = new CharT[length] )
{
copy_string(aReadable.BeginReading(), aReadable.EndReading(), buffer);
do_AssignFromElementPtrLength(buffer, length);
delete buffer;
}
}
#if 0
template <class CharT>
void
@ -456,6 +489,19 @@ basic_nsAWritableString<CharT>::do_AppendFromReadable( const basic_nsAReadableSt
copy_string(rhs.BeginReading(), rhs.EndReading(), BeginWriting(oldLength));
}
template <class CharT>
void
basic_nsAWritableString<CharT>::AppendFromPromise( const nsPromiseReadable<CharT>& aReadable )
{
PRUint32 length = aReadable.Length();
if ( CharT* buffer = new CharT[length] )
{
copy_string(aReadable.BeginReading(), aReadable.EndReading(), buffer);
do_AppendFromElementPtrLength(buffer, length);
delete buffer;
}
}
#if 0
template <class CharT>
void
@ -511,6 +557,19 @@ basic_nsAWritableString<CharT>::do_InsertFromReadable( const basic_nsAReadableSt
copy_string(aReadable.BeginReading(), aReadable.EndReading(), BeginWriting(atPosition));
}
template <class CharT>
void
basic_nsAWritableString<CharT>::InsertFromPromise( const nsPromiseReadable<CharT>& aReadable, PRUint32 atPosition )
{
PRUint32 length = aReadable.Length();
if ( CharT* buffer = new CharT[length] )
{
copy_string(aReadable.BeginReading(), aReadable.EndReading(), buffer);
do_InsertFromElementPtrLength(buffer, atPosition, length);
delete buffer;
}
}
template <class CharT>
void
basic_nsAWritableString<CharT>::do_InsertFromElementPtr( const CharT* aPtr, PRUint32 atPosition )
@ -554,7 +613,7 @@ basic_nsAWritableString<CharT>::Cut( PRUint32 cutStart, PRUint32 cutLength )
template <class CharT>
void
basic_nsAWritableString<CharT>::Replace( PRUint32 cutStart, PRUint32 cutLength, const basic_nsAReadableString<CharT>& aReplacement )
basic_nsAWritableString<CharT>::do_ReplaceFromReadable( PRUint32 cutStart, PRUint32 cutLength, const basic_nsAReadableString<CharT>& aReplacement )
{
PRUint32 oldLength = Length();
@ -576,6 +635,19 @@ basic_nsAWritableString<CharT>::Replace( PRUint32 cutStart, PRUint32 cutLength,
copy_string(aReplacement.BeginReading(), aReplacement.EndReading(), BeginWriting(cutStart));
}
template <class CharT>
void
basic_nsAWritableString<CharT>::ReplaceFromPromise( PRUint32 cutStart, PRUint32 cutLength, const nsPromiseReadable<CharT>& aReadable )
{
PRUint32 length = aReadable.Length();
if ( CharT* buffer = new CharT[length] )
{
copy_string(aReadable.BeginReading(), aReadable.EndReading(), buffer);
do_ReplaceFromReadable(cutStart, cutLength, basic_nsLiteralString<CharT>(buffer, length));
delete buffer;
}
}
//

Просмотреть файл

@ -336,6 +336,14 @@ class basic_nsAReadableString
// protected:
virtual const void* Implementation() const;
virtual const CharT* GetReadableFragment( nsReadableFragment<CharT>&, nsFragmentRequest, PRUint32 = 0 ) const = 0;
virtual PRBool Promises( const basic_nsAReadableString<CharT>& aString ) const { return &aString == this; }
private:
// NOT TO BE IMPLEMENTED
typedef typename nsCharTraits<CharT>::incompatible_char_type incompatible_char_type;
PRUint32 CountChar( incompatible_char_type ) const;
// in Compare( incompatible_char_type ) const;
// PRBool Equals( incompatible_char_type ) const;
};
template <class CharT>
@ -513,7 +521,7 @@ basic_nsAReadableString<CharT>::CountChar( CharT c ) const
nsReadingIterator<CharT> iter( BeginReading() );
for (;;)
{
PRUint32 lengthToExamineInThisFragment = iter.size_forward();
PRInt32 lengthToExamineInThisFragment = iter.size_forward();
result += PRUint32(count(iter.operator->(), iter.operator->()+lengthToExamineInThisFragment, c));
if ( !(lengthToExamine -= lengthToExamineInThisFragment) )
return result;
@ -750,9 +758,11 @@ basic_nsLiteralChar<CharT>::GetReadableFragment( nsReadableFragment<CharT>& aFra
// nsPromiseConcatenation
//
template <class CharT> class nsPromiseReadable : public basic_nsAReadableString<CharT> { };
template <class CharT>
class nsPromiseConcatenation
: public basic_nsAReadableString<CharT>
: public nsPromiseReadable<CharT>
/*
NOT FOR USE BY HUMANS
@ -807,6 +817,7 @@ class nsPromiseConcatenation
}
virtual PRUint32 Length() const;
virtual PRBool Promises( const basic_nsAReadableString<CharT>& ) const;
nsPromiseConcatenation<CharT> operator+( const basic_nsAReadableString<CharT>& rhs ) const;
@ -829,6 +840,13 @@ nsPromiseConcatenation<CharT>::Length() const
return mStrings[kLeftString]->Length() + mStrings[kRightString]->Length();
}
template <class CharT>
PRBool
nsPromiseConcatenation<CharT>::Promises( const basic_nsAReadableString<CharT>& aString ) const
{
return mStrings[0]->Promises(aString) || mStrings[1]->Promises(aString);
}
template <class CharT>
const CharT*
nsPromiseConcatenation<CharT>::GetReadableFragment( nsReadableFragment<CharT>& aFragment, nsFragmentRequest aRequest, PRUint32 aPosition ) const
@ -866,15 +884,15 @@ nsPromiseConcatenation<CharT>::GetReadableFragment( nsReadableFragment<CharT>& a
}
const CharT* result;
bool done;
PRBool done;
do
{
done = true;
done = PR_TRUE;
result = mStrings[whichString]->GetReadableFragment(aFragment, aRequest, aPosition);
if ( !result )
{
done = false;
done = PR_FALSE;
if ( aRequest == kNextFragment && whichString == kLeftString )
{
aRequest = kFirstFragment;
@ -886,7 +904,7 @@ nsPromiseConcatenation<CharT>::GetReadableFragment( nsReadableFragment<CharT>& a
whichString = SetLeftStringInFragment(aFragment);
}
else
done = true;
done = PR_TRUE;
}
}
while ( !done );
@ -912,7 +930,7 @@ nsPromiseConcatenation<CharT>::operator+( const basic_nsAReadableString<CharT>&
template <class CharT>
class nsPromiseSubstring
: public basic_nsAReadableString<CharT>
: public nsPromiseReadable<CharT>
/*
NOT FOR USE BY HUMANS (mostly)
@ -935,6 +953,7 @@ class nsPromiseSubstring
}
virtual PRUint32 Length() const;
virtual PRBool Promises( const basic_nsAReadableString<CharT>& aString ) const { return mString.Promises(aString); }
private:
const basic_nsAReadableString<CharT>& mString;
@ -1037,6 +1056,11 @@ template <class CharT>
nsPromiseSubstring<CharT>
Substring( const basic_nsAReadableString<CharT>& aString, PRUint32 aStartPos, PRUint32 aSubstringLength )
{
#if 0
// signatures don't work, but consider this twist to help in assignments
if ( aSubstringLength == aString.Length() && aStartPos == 0 )
return aString;
#endif
return nsPromiseSubstring<CharT>(aString, aStartPos, aSubstringLength);
}

Просмотреть файл

@ -274,10 +274,12 @@ class basic_nsAWritableString
//
basic_nsAWritableString<CharT>& operator=( const basic_nsAReadableString<CharT>& aReadable ) { do_AssignFromReadable(aReadable); return *this; }
basic_nsAWritableString<CharT>& operator=( const nsPromiseReadable<CharT>& aReadable ) { Assign(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 nsPromiseReadable<CharT>& aReadable ) { aReadable.Promises(*this) ? AssignFromPromise(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); }
@ -290,10 +292,12 @@ class basic_nsAWritableString
//
basic_nsAWritableString<CharT>& operator+=( const basic_nsAReadableString<CharT>& aReadable ) { do_AppendFromReadable(aReadable); return *this; }
basic_nsAWritableString<CharT>& operator+=( const nsPromiseReadable<CharT>& aReadable ) { Append(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 nsPromiseReadable<CharT>& aReadable ) { aReadable.Promises(*this) ? AppendFromPromise(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); }
@ -307,6 +311,7 @@ class basic_nsAWritableString
//
void Insert( const basic_nsAReadableString<CharT>& aReadable, PRUint32 atPosition ) { do_InsertFromReadable(aReadable, atPosition); }
void Insert( const nsPromiseReadable<CharT>& aReadable, PRUint32 atPosition ) { aReadable.Promises(*this) ? InsertFromPromise(aReadable, 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); }
@ -318,8 +323,12 @@ class basic_nsAWritableString
void Replace( PRUint32 cutStart, PRUint32 cutLength, const basic_nsAReadableString<CharT>& );
void Replace( PRUint32 cutStart, PRUint32 cutLength, const basic_nsAReadableString<CharT>& aReadable ) { do_ReplaceFromReadable(cutStart, cutLength, aReadable); }
void Replace( PRUint32 cutStart, PRUint32 cutLength, const nsPromiseReadable<CharT>& aReadable ) { aReadable.Promises(*this) ? ReplaceFromPromise(cutStart, cutLength, aReadable) : do_ReplaceFromReadable(cutStart, cutLength, aReadable); }
// void Replace( PRUint32, PRUint32, const nsReadingIterator<CharT>&, const nsReadingIterator<CharT>& );
// void Replace( PRUint32, PRUint32, const CharT* );
// void Replace( PRUint32, PRUint32, const CharT*, PRUint32 );
// void Replace( PRUint32, PRUint32, CharT );
private:
typedef typename nsCharTraits<CharT>::incompatible_char_type incompatible_char_type;
@ -330,26 +339,37 @@ class basic_nsAWritableString
void operator+= ( incompatible_char_type );
void Append ( incompatible_char_type );
void Insert ( incompatible_char_type, PRUint32 );
// void Replace ( PRUint32, PRUint32, incompatible_char_type );
protected:
virtual void do_AssignFromReadable( const basic_nsAReadableString<CharT>& );
void AssignFromPromise( const nsPromiseReadable<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 );
virtual void do_AppendFromReadable( const basic_nsAReadableString<CharT>& );
void AppendFromPromise( const nsPromiseReadable<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 );
void InsertFromPromise( const nsPromiseReadable<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 );
virtual void do_ReplaceFromReadable( PRUint32, PRUint32, const basic_nsAReadableString<CharT>& );
void ReplaceFromPromise( PRUint32 cutStart, PRUint32 cutLength, const nsPromiseReadable<CharT>& );
// virtual void do_ReplaceFromIterators( ... );
// virtual void do_ReplaceFromElementPtr( ... );
// virtual void do_ReplaceFromElementPtrLength( ... );
// virtual void do_ReplaceFromElement( ... );
};
@ -410,6 +430,19 @@ basic_nsAWritableString<CharT>::do_AssignFromReadable( const basic_nsAReadableSt
copy_string(rhs.BeginReading(), rhs.EndReading(), BeginWriting());
}
template <class CharT>
void
basic_nsAWritableString<CharT>::AssignFromPromise( const nsPromiseReadable<CharT>& aReadable )
{
PRUint32 length = aReadable.Length();
if ( CharT* buffer = new CharT[length] )
{
copy_string(aReadable.BeginReading(), aReadable.EndReading(), buffer);
do_AssignFromElementPtrLength(buffer, length);
delete buffer;
}
}
#if 0
template <class CharT>
void
@ -456,6 +489,19 @@ basic_nsAWritableString<CharT>::do_AppendFromReadable( const basic_nsAReadableSt
copy_string(rhs.BeginReading(), rhs.EndReading(), BeginWriting(oldLength));
}
template <class CharT>
void
basic_nsAWritableString<CharT>::AppendFromPromise( const nsPromiseReadable<CharT>& aReadable )
{
PRUint32 length = aReadable.Length();
if ( CharT* buffer = new CharT[length] )
{
copy_string(aReadable.BeginReading(), aReadable.EndReading(), buffer);
do_AppendFromElementPtrLength(buffer, length);
delete buffer;
}
}
#if 0
template <class CharT>
void
@ -511,6 +557,19 @@ basic_nsAWritableString<CharT>::do_InsertFromReadable( const basic_nsAReadableSt
copy_string(aReadable.BeginReading(), aReadable.EndReading(), BeginWriting(atPosition));
}
template <class CharT>
void
basic_nsAWritableString<CharT>::InsertFromPromise( const nsPromiseReadable<CharT>& aReadable, PRUint32 atPosition )
{
PRUint32 length = aReadable.Length();
if ( CharT* buffer = new CharT[length] )
{
copy_string(aReadable.BeginReading(), aReadable.EndReading(), buffer);
do_InsertFromElementPtrLength(buffer, atPosition, length);
delete buffer;
}
}
template <class CharT>
void
basic_nsAWritableString<CharT>::do_InsertFromElementPtr( const CharT* aPtr, PRUint32 atPosition )
@ -554,7 +613,7 @@ basic_nsAWritableString<CharT>::Cut( PRUint32 cutStart, PRUint32 cutLength )
template <class CharT>
void
basic_nsAWritableString<CharT>::Replace( PRUint32 cutStart, PRUint32 cutLength, const basic_nsAReadableString<CharT>& aReplacement )
basic_nsAWritableString<CharT>::do_ReplaceFromReadable( PRUint32 cutStart, PRUint32 cutLength, const basic_nsAReadableString<CharT>& aReplacement )
{
PRUint32 oldLength = Length();
@ -576,6 +635,19 @@ basic_nsAWritableString<CharT>::Replace( PRUint32 cutStart, PRUint32 cutLength,
copy_string(aReplacement.BeginReading(), aReplacement.EndReading(), BeginWriting(cutStart));
}
template <class CharT>
void
basic_nsAWritableString<CharT>::ReplaceFromPromise( PRUint32 cutStart, PRUint32 cutLength, const nsPromiseReadable<CharT>& aReadable )
{
PRUint32 length = aReadable.Length();
if ( CharT* buffer = new CharT[length] )
{
copy_string(aReadable.BeginReading(), aReadable.EndReading(), buffer);
do_ReplaceFromReadable(cutStart, cutLength, basic_nsLiteralString<CharT>(buffer, length));
delete buffer;
}
}
//