2000-03-07 04:02:10 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/*
|
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
2000-05-12 09:16:00 +04:00
|
|
|
* Original Author:
|
|
|
|
* Scott Collins <scc@mozilla.org>
|
|
|
|
*
|
2000-03-07 04:02:10 +03:00
|
|
|
* Contributor(s):
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _nsAReadableString_h__
|
|
|
|
#define _nsAReadableString_h__
|
|
|
|
|
2000-03-24 00:15:01 +03:00
|
|
|
#ifndef nscore_h___
|
2000-03-07 04:02:10 +03:00
|
|
|
#include "nscore.h"
|
2000-03-09 09:37:45 +03:00
|
|
|
// for |PRUnichar|
|
2000-03-24 00:15:01 +03:00
|
|
|
#endif
|
2000-03-09 09:37:45 +03:00
|
|
|
|
2000-03-24 00:15:01 +03:00
|
|
|
#ifndef _nsCharTraits_h__
|
|
|
|
#include "nsCharTraits.h"
|
|
|
|
#endif
|
2000-03-09 09:37:45 +03:00
|
|
|
|
2000-03-07 04:02:10 +03:00
|
|
|
/*
|
|
|
|
This file defines the abstract interfaces |nsAReadableString| and
|
|
|
|
|nsAReadableCString| (the 'A' is for 'abstract', as opposed to the 'I' in
|
|
|
|
[XP]COM interface names).
|
|
|
|
|
|
|
|
These types are intended to be as source compatible as possible with the original
|
|
|
|
definitions of |const nsString&| and |const nsCString&|, respectively. In otherwords,
|
|
|
|
these interfaces provide only non-mutating access to the underlying strings. We
|
|
|
|
split the these interfaces out from the mutating parts (see
|
|
|
|
"nsAWritableString.h") because tests showed that we could exploit specialized
|
|
|
|
implementations in some areas; we need an abstract interface to bring the whole
|
|
|
|
family of strings together.
|
|
|
|
|
|
|
|
|nsAReadableString| is a string of |PRUnichar|s. |nsAReadableCString| (note the
|
|
|
|
'C') is a string of |char|s.
|
|
|
|
*/
|
|
|
|
|
2000-03-25 01:06:57 +03:00
|
|
|
enum nsFragmentRequest { kPrevFragment, kFirstFragment, kLastFragment, kNextFragment, kFragmentAt };
|
2000-03-09 09:37:45 +03:00
|
|
|
|
2000-03-25 01:06:57 +03:00
|
|
|
template <class CharT>
|
|
|
|
struct nsReadableFragment
|
|
|
|
{
|
|
|
|
const CharT* mStart;
|
|
|
|
const CharT* mEnd;
|
|
|
|
PRUint32 mFragmentIdentifier;
|
2000-03-09 09:37:45 +03:00
|
|
|
|
2000-03-25 01:06:57 +03:00
|
|
|
nsReadableFragment()
|
|
|
|
: mStart(0), mEnd(0), mFragmentIdentifier(0)
|
|
|
|
{
|
|
|
|
// nothing else to do here
|
|
|
|
}
|
|
|
|
};
|
2000-03-07 04:02:10 +03:00
|
|
|
|
2000-03-27 13:06:37 +04:00
|
|
|
template <class CharT> class basic_nsAReadableString;
|
|
|
|
|
|
|
|
template <class CharT> class basic_nsAWritableString;
|
|
|
|
// ...because we sometimes use them as `out' params
|
|
|
|
|
2000-05-15 03:33:05 +04:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
// Under VC++, at the highest warning level, we are overwhelmed with warnings
|
|
|
|
// about a possible error when |operator->()| is used against something that
|
|
|
|
// doesn't have members, e.g., a |PRUnichar|. This is to be expected with
|
|
|
|
// templates, so we disable the warning.
|
|
|
|
#pragma warning( disable: 4284 )
|
|
|
|
#endif
|
2000-03-27 13:06:37 +04:00
|
|
|
|
2000-03-07 04:02:10 +03:00
|
|
|
template <class CharT>
|
2000-03-25 01:06:57 +03:00
|
|
|
class nsReadingIterator
|
2000-05-14 03:59:49 +04:00
|
|
|
// : public bidirectional_iterator_tag
|
2000-03-07 04:02:10 +03:00
|
|
|
{
|
2000-03-24 03:39:44 +03:00
|
|
|
public:
|
2000-03-25 01:06:57 +03:00
|
|
|
typedef ptrdiff_t difference_type;
|
|
|
|
typedef CharT value_type;
|
|
|
|
typedef const CharT* pointer;
|
|
|
|
typedef const CharT& reference;
|
2000-05-14 03:59:49 +04:00
|
|
|
// typedef bidirectional_iterator_tag iterator_category;
|
2000-03-07 04:02:10 +03:00
|
|
|
|
2000-03-25 01:06:57 +03:00
|
|
|
private:
|
|
|
|
friend class basic_nsAReadableString<CharT>;
|
2000-03-07 04:02:10 +03:00
|
|
|
|
2000-03-25 01:06:57 +03:00
|
|
|
nsReadableFragment<CharT> mFragment;
|
|
|
|
const CharT* mPosition;
|
|
|
|
const basic_nsAReadableString<CharT>* mOwningString;
|
2000-03-07 04:02:10 +03:00
|
|
|
|
2000-03-25 01:06:57 +03:00
|
|
|
inline void normalize_forward();
|
|
|
|
inline void normalize_backward();
|
|
|
|
|
|
|
|
nsReadingIterator( const nsReadableFragment<CharT>& aFragment,
|
|
|
|
const CharT* aStartingPosition,
|
|
|
|
const basic_nsAReadableString<CharT>& aOwningString )
|
|
|
|
: mFragment(aFragment),
|
|
|
|
mPosition(aStartingPosition),
|
|
|
|
mOwningString(&aOwningString)
|
|
|
|
{
|
|
|
|
// nothing else to do here
|
|
|
|
}
|
2000-03-22 11:19:48 +03:00
|
|
|
|
2000-03-07 04:02:10 +03:00
|
|
|
public:
|
2000-03-25 01:06:57 +03:00
|
|
|
// nsReadingIterator( const nsReadingIterator<CharT>& ); ...use default copy-constructor
|
|
|
|
// nsReadingIterator<CharT>& operator=( const nsReadingIterator<CharT>& ); ...use default copy-assignment operator
|
2000-03-22 11:19:48 +03:00
|
|
|
|
2000-03-25 01:06:57 +03:00
|
|
|
|
|
|
|
CharT
|
|
|
|
operator*() const
|
|
|
|
{
|
|
|
|
return *mPosition;
|
|
|
|
}
|
2000-03-09 09:37:45 +03:00
|
|
|
|
2000-03-25 01:06:57 +03:00
|
|
|
pointer
|
|
|
|
operator->() const
|
|
|
|
{
|
|
|
|
return mPosition;
|
|
|
|
}
|
2000-03-07 04:02:10 +03:00
|
|
|
|
2000-03-25 01:06:57 +03:00
|
|
|
nsReadingIterator<CharT>&
|
|
|
|
operator++()
|
2000-03-07 04:02:10 +03:00
|
|
|
{
|
2000-03-25 01:06:57 +03:00
|
|
|
++mPosition;
|
|
|
|
normalize_forward();
|
|
|
|
return *this;
|
|
|
|
}
|
2000-03-12 04:28:16 +03:00
|
|
|
|
2000-03-25 01:06:57 +03:00
|
|
|
nsReadingIterator<CharT>
|
|
|
|
operator++( int )
|
|
|
|
{
|
|
|
|
nsReadingIterator<CharT> result(*this);
|
|
|
|
++mPosition;
|
|
|
|
normalize_forward();
|
|
|
|
return result;
|
|
|
|
}
|
2000-03-07 04:02:10 +03:00
|
|
|
|
2000-03-25 01:06:57 +03:00
|
|
|
nsReadingIterator<CharT>&
|
|
|
|
operator--()
|
|
|
|
{
|
|
|
|
normalize_backward();
|
|
|
|
--mPosition;
|
|
|
|
return *this;
|
|
|
|
}
|
2000-03-07 23:56:07 +03:00
|
|
|
|
2000-03-25 01:06:57 +03:00
|
|
|
nsReadingIterator<CharT>
|
|
|
|
operator--( int )
|
|
|
|
{
|
|
|
|
nsReadingIterator<CharT> result(*this);
|
|
|
|
normalize_backward();
|
|
|
|
--mPosition;
|
|
|
|
return result;
|
|
|
|
}
|
2000-03-24 00:15:01 +03:00
|
|
|
|
2000-03-25 01:06:57 +03:00
|
|
|
const nsReadableFragment<CharT>&
|
|
|
|
fragment() const
|
|
|
|
{
|
|
|
|
return mFragment;
|
|
|
|
}
|
2000-03-07 23:56:07 +03:00
|
|
|
|
2000-03-25 01:06:57 +03:00
|
|
|
difference_type
|
|
|
|
size_forward() const
|
|
|
|
{
|
|
|
|
return mFragment.mEnd - mPosition;
|
|
|
|
}
|
2000-03-07 23:56:07 +03:00
|
|
|
|
2000-03-25 01:06:57 +03:00
|
|
|
difference_type
|
|
|
|
size_backward() const
|
|
|
|
{
|
|
|
|
return mPosition - mFragment.mStart;
|
|
|
|
}
|
2000-03-07 04:02:10 +03:00
|
|
|
|
2000-03-25 01:06:57 +03:00
|
|
|
nsReadingIterator<CharT>&
|
|
|
|
operator+=( difference_type n )
|
|
|
|
{
|
|
|
|
if ( n < 0 )
|
|
|
|
return operator-=(-n);
|
2000-03-07 04:02:10 +03:00
|
|
|
|
2000-03-25 01:06:57 +03:00
|
|
|
while ( n )
|
|
|
|
{
|
|
|
|
difference_type one_hop = NS_MIN(n, size_forward());
|
|
|
|
mPosition += one_hop;
|
|
|
|
normalize_forward();
|
|
|
|
n -= one_hop;
|
|
|
|
}
|
2000-03-07 23:56:07 +03:00
|
|
|
|
2000-03-25 01:06:57 +03:00
|
|
|
return *this;
|
|
|
|
}
|
2000-03-22 11:19:48 +03:00
|
|
|
|
2000-03-25 01:06:57 +03:00
|
|
|
nsReadingIterator<CharT>&
|
|
|
|
operator-=( difference_type n )
|
|
|
|
{
|
|
|
|
if ( n < 0 )
|
|
|
|
return operator+=(-n);
|
2000-03-07 23:56:07 +03:00
|
|
|
|
2000-03-25 01:06:57 +03:00
|
|
|
while ( n )
|
|
|
|
{
|
|
|
|
difference_type one_hop = NS_MIN(n, size_backward());
|
|
|
|
mPosition -= one_hop;
|
|
|
|
normalize_backward();
|
|
|
|
n -= one_hop;
|
|
|
|
}
|
2000-03-07 23:56:07 +03:00
|
|
|
|
2000-03-25 01:06:57 +03:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
};
|
2000-03-22 11:19:48 +03:00
|
|
|
|
2000-04-21 05:25:19 +04:00
|
|
|
template <class Iterator>
|
|
|
|
inline
|
|
|
|
PRBool
|
|
|
|
SameFragment( const Iterator& lhs, const Iterator& rhs )
|
|
|
|
{
|
|
|
|
return lhs.fragment().mStart == rhs.fragment().mStart;
|
|
|
|
}
|
|
|
|
|
2000-03-22 11:19:48 +03:00
|
|
|
|
2000-03-25 01:06:57 +03:00
|
|
|
//
|
|
|
|
// nsAReadable[C]String
|
|
|
|
//
|
2000-03-22 11:19:48 +03:00
|
|
|
|
2000-03-25 01:06:57 +03:00
|
|
|
template <class CharT>
|
|
|
|
class basic_nsAReadableString
|
|
|
|
/*
|
|
|
|
...
|
|
|
|
*/
|
|
|
|
{
|
2000-03-25 03:47:02 +03:00
|
|
|
public:
|
2000-03-31 02:53:41 +04:00
|
|
|
typedef PRUint32 size_type;
|
|
|
|
typedef PRUint32 index_type;
|
|
|
|
|
|
|
|
typedef nsReadingIterator<CharT> const_iterator;
|
|
|
|
|
2000-03-25 03:47:02 +03:00
|
|
|
|
2000-03-07 04:02:10 +03:00
|
|
|
|
2000-03-24 00:15:01 +03:00
|
|
|
virtual ~basic_nsAReadableString() { }
|
2000-03-12 04:28:16 +03:00
|
|
|
// ...yes, I expect to be sub-classed.
|
2000-03-07 04:02:10 +03:00
|
|
|
|
2000-03-25 10:55:07 +03:00
|
|
|
nsReadingIterator<CharT> BeginReading( PRUint32 aOffset = 0 ) const;
|
|
|
|
nsReadingIterator<CharT> EndReading( PRUint32 aOffset = 0 ) const;
|
2000-03-07 04:02:10 +03:00
|
|
|
|
2000-03-25 10:55:07 +03:00
|
|
|
virtual PRUint32 Length() const = 0;
|
|
|
|
PRBool IsEmpty() const;
|
2000-03-07 04:02:10 +03:00
|
|
|
|
2000-03-25 10:55:07 +03:00
|
|
|
CharT CharAt( PRUint32 ) const;
|
|
|
|
CharT operator[]( PRUint32 ) const;
|
|
|
|
CharT First() const;
|
|
|
|
CharT Last() const;
|
2000-03-07 04:02:10 +03:00
|
|
|
|
2000-03-25 10:55:07 +03:00
|
|
|
PRUint32 CountChar( CharT ) const;
|
2000-03-07 04:02:10 +03:00
|
|
|
|
2000-05-14 00:17:35 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
|Left|, |Mid|, and |Right| are annoying signatures that seem better almost
|
|
|
|
any _other_ way than they are now. Consider these alternatives
|
|
|
|
|
|
|
|
aWritable = aReadable.Left(17); // ...a member function that returns a |Substring|
|
|
|
|
aWritable = Left(aReadable, 17); // ...a global function that returns a |Substring|
|
|
|
|
Left(aReadable, 17, aWritable); // ...a global function that does the assignment
|
|
|
|
|
|
|
|
as opposed to the current signature
|
|
|
|
|
|
|
|
aReadable.Left(aWritable, 17); // ...a member function that does the assignment
|
|
|
|
|
|
|
|
or maybe just stamping them out in favor of |Substring|, they are just duplicate functionality
|
|
|
|
|
|
|
|
aWritable = Substring(aReadable, 0, 17);
|
|
|
|
*/
|
|
|
|
|
2000-03-25 10:55:07 +03:00
|
|
|
PRUint32 Left( basic_nsAWritableString<CharT>&, PRUint32 ) const;
|
|
|
|
PRUint32 Mid( basic_nsAWritableString<CharT>&, PRUint32, PRUint32 ) const;
|
|
|
|
PRUint32 Right( basic_nsAWritableString<CharT>&, PRUint32 ) const;
|
2000-03-07 04:02:10 +03:00
|
|
|
|
|
|
|
// Find( ... ) const;
|
|
|
|
// FindChar( ... ) const;
|
|
|
|
// FindCharInSet( ... ) const;
|
|
|
|
// RFind( ... ) const;
|
|
|
|
// RFindChar( ... ) const;
|
|
|
|
// RFindCharInSet( ... ) const;
|
|
|
|
|
|
|
|
|
2000-03-25 10:55:07 +03:00
|
|
|
int Compare( const basic_nsAReadableString<CharT>& rhs ) const;
|
2000-03-31 11:28:38 +04:00
|
|
|
int Compare( const CharT* ) const;
|
2000-05-15 02:32:30 +04:00
|
|
|
// int Compare( const CharT*, PRUint32 ) const;
|
2000-03-31 11:28:38 +04:00
|
|
|
// int Compare( CharT ) const;
|
2000-03-07 04:02:10 +03:00
|
|
|
|
2000-03-12 04:28:16 +03:00
|
|
|
// |Equals()| is a synonym for |Compare()|
|
2000-03-25 10:55:07 +03:00
|
|
|
PRBool Equals( const basic_nsAReadableString<CharT>& rhs ) const;
|
2000-03-31 11:28:38 +04:00
|
|
|
PRBool Equals( const CharT* ) const;
|
2000-05-15 04:13:57 +04:00
|
|
|
// PRBool Equals( const CharT*, PRUint32 ) const;
|
2000-03-31 11:28:38 +04:00
|
|
|
// PRBool Equals( CharT ) const;
|
2000-03-12 04:28:16 +03:00
|
|
|
|
2000-03-25 10:55:07 +03:00
|
|
|
// Comparison operators are all synonyms for |Compare()|
|
|
|
|
PRBool operator!=( const basic_nsAReadableString<CharT>& rhs ) const { return Compare(rhs)!=0; }
|
|
|
|
PRBool operator< ( const basic_nsAReadableString<CharT>& rhs ) const { return Compare(rhs)< 0; }
|
|
|
|
PRBool operator<=( const basic_nsAReadableString<CharT>& rhs ) const { return Compare(rhs)<=0; }
|
|
|
|
PRBool operator==( const basic_nsAReadableString<CharT>& rhs ) const { return Compare(rhs)==0; }
|
|
|
|
PRBool operator>=( const basic_nsAReadableString<CharT>& rhs ) const { return Compare(rhs)>=0; }
|
|
|
|
PRBool operator> ( const basic_nsAReadableString<CharT>& rhs ) const { return Compare(rhs)> 0; }
|
2000-03-12 04:28:16 +03:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Shouldn't be implemented because they're i18n sensitive.
|
|
|
|
Let's leave them in |nsString| for now.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// ToLowerCase
|
|
|
|
// ToUpperCase
|
|
|
|
// EqualsIgnoreCase
|
2000-03-07 04:02:10 +03:00
|
|
|
// IsASCII
|
|
|
|
// IsSpace
|
|
|
|
// IsAlpha
|
|
|
|
// IsDigit
|
2000-03-12 04:28:16 +03:00
|
|
|
// ToFloat
|
|
|
|
// ToInteger
|
2000-03-09 09:37:45 +03:00
|
|
|
|
2000-03-12 04:28:16 +03:00
|
|
|
// char* ToNewCString() const;
|
|
|
|
// char* ToNewUTF8String() const;
|
|
|
|
// PRUnichar* ToNewUnicode() const;
|
|
|
|
// char* ToCString( char*, PRUint32, PRUint32 ) const;
|
2000-03-09 09:37:45 +03:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
2000-03-12 04:28:16 +03:00
|
|
|
Shouldn't be implemented because it's wrong duplication.
|
|
|
|
Let's leave it in |nsString| for now.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// nsString* ToNewString() const;
|
|
|
|
// NO! The right way to say this is |new nsString( fromAReadableString )|
|
2000-03-09 09:37:45 +03:00
|
|
|
|
2000-03-12 04:28:16 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
Shouldn't be implemented because they're not generally applicable.
|
|
|
|
Let's leave them in |nsString| for now.
|
2000-03-09 09:37:45 +03:00
|
|
|
*/
|
|
|
|
|
2000-03-12 04:28:16 +03:00
|
|
|
// IsOrdered
|
|
|
|
// BinarySearch
|
|
|
|
|
2000-03-25 10:55:07 +03:00
|
|
|
// protected:
|
|
|
|
virtual const void* Implementation() const;
|
|
|
|
virtual const CharT* GetReadableFragment( nsReadableFragment<CharT>&, nsFragmentRequest, PRUint32 = 0 ) const = 0;
|
2000-04-28 00:01:28 +04:00
|
|
|
virtual PRBool Promises( const basic_nsAReadableString<CharT>& aString ) const { return &aString == this; }
|
2000-05-14 00:17:35 +04:00
|
|
|
// virtual PRBool PromisesExactly( const basic_nsAReadableString<CharT>& aString ) const { return false; }
|
2000-04-28 00:01:28 +04:00
|
|
|
|
|
|
|
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;
|
2000-03-07 04:02:10 +03:00
|
|
|
};
|
|
|
|
|
2000-05-14 00:29:18 +04:00
|
|
|
/*
|
|
|
|
The following macro defines a cast that helps us solve type-unification error problems on compilers
|
|
|
|
with poor template support. String clients probably _never_ need to use it. String implementors
|
|
|
|
sometimes will.
|
|
|
|
*/
|
|
|
|
|
2000-05-16 03:06:25 +04:00
|
|
|
#define NS_READABLE_CAST(CharT, expr) (NS_STATIC_CAST(const basic_nsAReadableString<CharT>&, (expr)))
|
2000-05-14 00:29:18 +04:00
|
|
|
|
2000-03-25 01:06:57 +03:00
|
|
|
template <class CharT>
|
|
|
|
inline
|
|
|
|
void
|
|
|
|
nsReadingIterator<CharT>::normalize_forward()
|
|
|
|
{
|
|
|
|
if ( mPosition == mFragment.mEnd )
|
|
|
|
if ( mOwningString->GetReadableFragment(mFragment, kNextFragment) )
|
|
|
|
mPosition = mFragment.mStart;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class CharT>
|
|
|
|
inline
|
|
|
|
void
|
|
|
|
nsReadingIterator<CharT>::normalize_backward()
|
|
|
|
{
|
|
|
|
if ( mPosition == mFragment.mStart )
|
|
|
|
if ( mOwningString->GetReadableFragment(mFragment, kPrevFragment) )
|
|
|
|
mPosition = mFragment.mEnd;
|
|
|
|
}
|
|
|
|
|
2000-03-25 10:55:07 +03:00
|
|
|
template <class CharT>
|
|
|
|
inline
|
|
|
|
nsReadingIterator<CharT>
|
|
|
|
basic_nsAReadableString<CharT>::BeginReading( PRUint32 aOffset ) const
|
|
|
|
{
|
|
|
|
nsReadableFragment<CharT> fragment;
|
|
|
|
const CharT* startPos = GetReadableFragment(fragment, kFragmentAt, aOffset);
|
|
|
|
return nsReadingIterator<CharT>(fragment, startPos, *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class CharT>
|
|
|
|
inline
|
|
|
|
nsReadingIterator<CharT>
|
|
|
|
basic_nsAReadableString<CharT>::EndReading( PRUint32 aOffset ) const
|
|
|
|
{
|
|
|
|
nsReadableFragment<CharT> fragment;
|
|
|
|
const CharT* startPos = GetReadableFragment(fragment, kFragmentAt, NS_MAX(0U, Length()-aOffset));
|
|
|
|
return nsReadingIterator<CharT>(fragment, startPos, *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class CharT>
|
|
|
|
inline
|
|
|
|
PRBool
|
|
|
|
basic_nsAReadableString<CharT>::IsEmpty() const
|
|
|
|
{
|
|
|
|
return Length() == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class CharT>
|
|
|
|
inline
|
|
|
|
PRBool
|
|
|
|
basic_nsAReadableString<CharT>::Equals( const basic_nsAReadableString<CharT>& rhs ) const
|
|
|
|
{
|
|
|
|
return Compare(rhs) == 0;
|
|
|
|
}
|
|
|
|
|
2000-03-25 03:47:02 +03:00
|
|
|
template <class CharT>
|
|
|
|
inline
|
|
|
|
PRBool
|
|
|
|
operator==( const nsReadingIterator<CharT>& lhs, const nsReadingIterator<CharT>& rhs )
|
|
|
|
{
|
|
|
|
return lhs.operator->() == rhs.operator->();
|
|
|
|
}
|
2000-04-04 10:42:59 +04:00
|
|
|
|
2000-03-25 03:47:02 +03:00
|
|
|
template <class CharT>
|
|
|
|
inline
|
|
|
|
PRBool
|
|
|
|
operator!=( const nsReadingIterator<CharT>& lhs, const nsReadingIterator<CharT>& rhs )
|
|
|
|
{
|
|
|
|
return lhs.operator->() != rhs.operator->();
|
|
|
|
}
|
|
|
|
|
2000-05-14 01:39:37 +04:00
|
|
|
|
|
|
|
#define NS_DEF_1_STRING_PTR_COMPARISON_OPERATOR(comp, _StringT, _CharT) \
|
|
|
|
inline \
|
|
|
|
PRBool \
|
|
|
|
operator comp( const _StringT& lhs, const _CharT* rhs ) \
|
|
|
|
{ \
|
|
|
|
return PRBool(Compare(NS_READABLE_CAST(_CharT, lhs), rhs) comp 0); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define NS_DEF_1_PTR_STRING_COMPARISON_OPERATOR(comp, _StringT, _CharT) \
|
|
|
|
inline \
|
|
|
|
PRBool \
|
|
|
|
operator comp( const _CharT* lhs, const _StringT& rhs ) \
|
|
|
|
{ \
|
|
|
|
return PRBool(Compare(lhs, NS_READABLE_CAST(_CharT, rhs)) comp 0); \
|
2000-03-12 04:28:16 +03:00
|
|
|
}
|
|
|
|
|
2000-05-15 09:14:40 +04:00
|
|
|
#define NS_DEF_1_STRING_STRING_COMPARISON_OPERATOR(comp, _StringT, _CharT) \
|
|
|
|
inline \
|
|
|
|
PRBool \
|
|
|
|
operator comp( const _StringT& lhs, const _StringT& rhs ) \
|
|
|
|
{ \
|
|
|
|
return PRBool(Compare(NS_READABLE_CAST(_CharT, lhs), NS_READABLE_CAST(_CharT, rhs)) comp 0); \
|
|
|
|
}
|
|
|
|
|
2000-05-14 01:39:37 +04:00
|
|
|
#define NS_DEF_2_TEMPLATE_STRING_COMPARISON_OPERATORS(comp, _StringT, _CharT) \
|
|
|
|
template <class _CharT> NS_DEF_1_STRING_PTR_COMPARISON_OPERATOR(comp, _StringT, _CharT) \
|
|
|
|
template <class _CharT> NS_DEF_1_PTR_STRING_COMPARISON_OPERATOR(comp, _StringT, _CharT)
|
|
|
|
|
2000-05-15 09:14:40 +04:00
|
|
|
#define NS_DEF_3_STRING_COMPARISON_OPERATORS(comp, _StringT, _CharT) \
|
|
|
|
NS_DEF_1_STRING_STRING_COMPARISON_OPERATOR(comp, _StringT, _CharT) \
|
|
|
|
NS_DEF_1_STRING_PTR_COMPARISON_OPERATOR(comp, _StringT, _CharT) \
|
2000-05-14 01:39:37 +04:00
|
|
|
NS_DEF_1_PTR_STRING_COMPARISON_OPERATOR(comp, _StringT, _CharT)
|
2000-03-22 11:19:48 +03:00
|
|
|
|
2000-05-14 01:39:37 +04:00
|
|
|
#define NS_DEF_TEMPLATE_STRING_COMPARISON_OPERATORS(_StringT, _CharT) \
|
|
|
|
NS_DEF_2_TEMPLATE_STRING_COMPARISON_OPERATORS(!=, _StringT, _CharT) \
|
|
|
|
NS_DEF_2_TEMPLATE_STRING_COMPARISON_OPERATORS(< , _StringT, _CharT) \
|
|
|
|
NS_DEF_2_TEMPLATE_STRING_COMPARISON_OPERATORS(<=, _StringT, _CharT) \
|
|
|
|
NS_DEF_2_TEMPLATE_STRING_COMPARISON_OPERATORS(==, _StringT, _CharT) \
|
|
|
|
NS_DEF_2_TEMPLATE_STRING_COMPARISON_OPERATORS(>=, _StringT, _CharT) \
|
|
|
|
NS_DEF_2_TEMPLATE_STRING_COMPARISON_OPERATORS(> , _StringT, _CharT)
|
2000-03-12 04:28:16 +03:00
|
|
|
|
2000-05-14 01:39:37 +04:00
|
|
|
#define NS_DEF_STRING_COMPARISON_OPERATORS(_StringT, _CharT) \
|
2000-05-15 09:14:40 +04:00
|
|
|
NS_DEF_3_STRING_COMPARISON_OPERATORS(!=, _StringT, _CharT) \
|
|
|
|
NS_DEF_3_STRING_COMPARISON_OPERATORS(< , _StringT, _CharT) \
|
|
|
|
NS_DEF_3_STRING_COMPARISON_OPERATORS(<=, _StringT, _CharT) \
|
|
|
|
NS_DEF_3_STRING_COMPARISON_OPERATORS(==, _StringT, _CharT) \
|
|
|
|
NS_DEF_3_STRING_COMPARISON_OPERATORS(>=, _StringT, _CharT) \
|
|
|
|
NS_DEF_3_STRING_COMPARISON_OPERATORS(> , _StringT, _CharT)
|
2000-03-12 04:28:16 +03:00
|
|
|
|
|
|
|
|
2000-05-14 01:39:37 +04:00
|
|
|
NS_DEF_TEMPLATE_STRING_COMPARISON_OPERATORS(basic_nsAReadableString<CharT>, CharT)
|
2000-03-09 09:37:45 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
2000-03-12 20:39:49 +03:00
|
|
|
template <class CharT>
|
2000-03-22 11:19:48 +03:00
|
|
|
const void*
|
2000-03-12 20:39:49 +03:00
|
|
|
basic_nsAReadableString<CharT>::Implementation() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-03-07 04:02:10 +03:00
|
|
|
|
2000-03-09 09:37:45 +03:00
|
|
|
|
2000-03-12 04:28:16 +03:00
|
|
|
/*
|
|
|
|
Note: the following four functions, |CharAt|, |operator[]|, |First|, and |Last|, are implemented
|
2000-03-24 00:15:01 +03:00
|
|
|
in the simplest reasonable scheme; by calling |GetReadableFragment| and resolving the pointer it
|
2000-03-12 04:28:16 +03:00
|
|
|
returns. The alternative is to force at least one of these methods to be |virtual|. The ideal
|
|
|
|
candidate for that change would be |CharAt|.
|
|
|
|
|
|
|
|
This is something to measure in the context of how string classes are actually used. In practice,
|
|
|
|
do people extract a character at a time in performance critical places? If so, can they use
|
|
|
|
iterators instead? If they must extract single characters, _and_ they can't use iterators, _and_
|
|
|
|
it happens enough to notice, then we'll take the hit and make |CharAt| virtual.
|
|
|
|
*/
|
|
|
|
|
|
|
|
template <class CharT>
|
|
|
|
inline
|
|
|
|
CharT
|
|
|
|
basic_nsAReadableString<CharT>::CharAt( PRUint32 aIndex ) const
|
|
|
|
{
|
|
|
|
// ??? Is |CharAt()| supposed to be the 'safe' version?
|
2000-03-25 01:06:57 +03:00
|
|
|
nsReadableFragment<CharT> fragment;
|
2000-03-24 00:15:01 +03:00
|
|
|
return *GetReadableFragment(fragment, kFragmentAt, aIndex);
|
2000-03-12 04:28:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class CharT>
|
|
|
|
inline
|
|
|
|
CharT
|
|
|
|
basic_nsAReadableString<CharT>::operator[]( PRUint32 aIndex ) const
|
|
|
|
{
|
|
|
|
return CharAt(aIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class CharT>
|
|
|
|
inline
|
|
|
|
CharT
|
|
|
|
basic_nsAReadableString<CharT>::First() const
|
|
|
|
{
|
|
|
|
return CharAt(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class CharT>
|
|
|
|
inline
|
|
|
|
CharT
|
|
|
|
basic_nsAReadableString<CharT>::Last() const
|
|
|
|
{
|
|
|
|
return CharAt(Length()-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class CharT>
|
|
|
|
PRUint32
|
|
|
|
basic_nsAReadableString<CharT>::CountChar( CharT c ) const
|
|
|
|
{
|
2000-04-26 04:55:37 +04:00
|
|
|
#if 0
|
2000-03-24 00:15:01 +03:00
|
|
|
return PRUint32(count(BeginReading(), EndReading(), c));
|
2000-03-22 11:19:48 +03:00
|
|
|
#else
|
|
|
|
PRUint32 result = 0;
|
|
|
|
PRUint32 lengthToExamine = Length();
|
|
|
|
|
2000-03-25 01:06:57 +03:00
|
|
|
nsReadingIterator<CharT> iter( BeginReading() );
|
2000-03-22 11:19:48 +03:00
|
|
|
for (;;)
|
|
|
|
{
|
2000-04-28 00:01:28 +04:00
|
|
|
PRInt32 lengthToExamineInThisFragment = iter.size_forward();
|
2000-03-22 11:19:48 +03:00
|
|
|
result += PRUint32(count(iter.operator->(), iter.operator->()+lengthToExamineInThisFragment, c));
|
|
|
|
if ( !(lengthToExamine -= lengthToExamineInThisFragment) )
|
|
|
|
return result;
|
|
|
|
iter += lengthToExamineInThisFragment;
|
|
|
|
}
|
|
|
|
#endif
|
2000-03-12 04:28:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class CharT>
|
|
|
|
PRUint32
|
2000-05-14 00:17:35 +04:00
|
|
|
basic_nsAReadableString<CharT>::Mid( basic_nsAWritableString<CharT>& aResult, PRUint32 aStartPos, PRUint32 aLengthToCopy ) const
|
2000-03-12 04:28:16 +03:00
|
|
|
{
|
2000-05-14 00:17:35 +04:00
|
|
|
// If we're just assigning our entire self, give |aResult| the opportunity to share
|
|
|
|
if ( aStartPos == 0 && aLengthToCopy >= Length() )
|
|
|
|
aResult = *this;
|
|
|
|
else
|
|
|
|
aResult = Substring(*this, aStartPos, aLengthToCopy);
|
|
|
|
|
2000-03-12 04:28:16 +03:00
|
|
|
return aResult.Length();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class CharT>
|
|
|
|
PRUint32
|
2000-05-14 00:17:35 +04:00
|
|
|
basic_nsAReadableString<CharT>::Left( basic_nsAWritableString<CharT>& aResult, PRUint32 aLengthToCopy ) const
|
2000-03-12 04:28:16 +03:00
|
|
|
{
|
2000-05-14 00:17:35 +04:00
|
|
|
return Mid(aResult, 0, aLengthToCopy);
|
2000-03-12 04:28:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class CharT>
|
|
|
|
PRUint32
|
|
|
|
basic_nsAReadableString<CharT>::Right( basic_nsAWritableString<CharT>& aResult, PRUint32 aLengthToCopy ) const
|
|
|
|
{
|
|
|
|
PRUint32 myLength = Length();
|
2000-03-24 03:39:44 +03:00
|
|
|
aLengthToCopy = NS_MIN(myLength, aLengthToCopy);
|
2000-05-14 00:17:35 +04:00
|
|
|
return Mid(aResult, myLength-aLengthToCopy, aLengthToCopy);
|
2000-03-12 04:28:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class CharT>
|
|
|
|
inline
|
|
|
|
int
|
|
|
|
basic_nsAReadableString<CharT>::Compare( const basic_nsAReadableString<CharT>& rhs ) const
|
|
|
|
{
|
|
|
|
return ::Compare(*this, rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// nsLiteral[C]String
|
|
|
|
//
|
|
|
|
|
2000-03-09 09:37:45 +03:00
|
|
|
template <class CharT>
|
|
|
|
class basic_nsLiteralString
|
|
|
|
: public basic_nsAReadableString<CharT>
|
2000-03-12 04:28:16 +03:00
|
|
|
/*
|
|
|
|
...this class wraps a constant literal string and lets it act like an |nsAReadable...|.
|
|
|
|
|
|
|
|
Use it like this:
|
|
|
|
|
|
|
|
SomeFunctionTakingACString( nsLiteralCString("Hello, World!") );
|
|
|
|
|
|
|
|
With some tweaking, I think I can make this work as well...
|
|
|
|
|
|
|
|
SomeStringFunc( nsLiteralString( L"Hello, World!" ) );
|
|
|
|
|
|
|
|
This class just holds a pointer. If you don't supply the length, it must calculate it.
|
|
|
|
No copying or allocations are performed.
|
|
|
|
|
|
|
|
|const basic_nsLiteralString<CharT>&| appears frequently in interfaces because it
|
|
|
|
allows the automatic conversion of a |CharT*|.
|
|
|
|
*/
|
2000-03-09 09:37:45 +03:00
|
|
|
{
|
|
|
|
protected:
|
2000-03-25 01:06:57 +03:00
|
|
|
virtual const CharT* GetReadableFragment( nsReadableFragment<CharT>&, nsFragmentRequest, PRUint32 ) const;
|
2000-03-09 09:37:45 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Note: _not_ explicit
|
|
|
|
basic_nsLiteralString( const CharT* aLiteral )
|
|
|
|
: mStart(aLiteral),
|
2000-05-14 00:17:35 +04:00
|
|
|
mEnd(mStart ? (mStart + nsCharTraits<CharT>::length(mStart)) : mStart)
|
2000-03-09 09:37:45 +03:00
|
|
|
{
|
|
|
|
// nothing else to do here
|
|
|
|
}
|
|
|
|
|
|
|
|
basic_nsLiteralString( const CharT* aLiteral, PRUint32 aLength )
|
2000-03-24 09:02:37 +03:00
|
|
|
: mStart(aLiteral),
|
2000-03-09 09:37:45 +03:00
|
|
|
mEnd(mStart + aLength)
|
|
|
|
{
|
2000-03-31 02:53:41 +04:00
|
|
|
// 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) )
|
2000-05-14 00:17:35 +04:00
|
|
|
{
|
2000-05-15 04:13:57 +04:00
|
|
|
// NS_WARNING("Tell scc: Caller constructing a string doesn't know the real length. Please use the other constructor.");
|
2000-05-15 07:10:19 +04:00
|
|
|
mEnd = mStart ? (mStart + nsCharTraits<CharT>::length(mStart)) : mStart;
|
2000-05-14 00:17:35 +04:00
|
|
|
}
|
2000-03-09 09:37:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual PRUint32 Length() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const CharT* mStart;
|
|
|
|
const CharT* mEnd;
|
|
|
|
};
|
|
|
|
|
2000-05-14 01:39:37 +04:00
|
|
|
NS_DEF_TEMPLATE_STRING_COMPARISON_OPERATORS(basic_nsLiteralString<CharT>, CharT)
|
2000-03-09 09:37:45 +03:00
|
|
|
|
2000-03-12 04:28:16 +03:00
|
|
|
template <class CharT>
|
|
|
|
const CharT*
|
2000-03-25 01:06:57 +03:00
|
|
|
basic_nsLiteralString<CharT>::GetReadableFragment( nsReadableFragment<CharT>& aFragment, nsFragmentRequest aRequest, PRUint32 aOffset ) const
|
2000-03-12 04:28:16 +03:00
|
|
|
{
|
|
|
|
switch ( aRequest )
|
|
|
|
{
|
|
|
|
case kFirstFragment:
|
|
|
|
case kLastFragment:
|
|
|
|
case kFragmentAt:
|
|
|
|
aFragment.mStart = mStart;
|
|
|
|
aFragment.mEnd = mEnd;
|
|
|
|
return mStart + aOffset;
|
|
|
|
|
|
|
|
case kPrevFragment:
|
|
|
|
case kNextFragment:
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class CharT>
|
|
|
|
PRUint32
|
|
|
|
basic_nsLiteralString<CharT>::Length() const
|
|
|
|
{
|
|
|
|
return PRUint32(mEnd - mStart);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-04 09:45:57 +04:00
|
|
|
// XXX Note that these are located here because some compilers are
|
|
|
|
// sensitive to the ordering of declarations with regard to templates.
|
|
|
|
template <class CharT>
|
|
|
|
inline
|
|
|
|
PRBool
|
|
|
|
basic_nsAReadableString<CharT>::Equals( const CharT* rhs ) const
|
|
|
|
{
|
|
|
|
return Compare(basic_nsLiteralString<CharT>(rhs)) == 0;
|
|
|
|
}
|
|
|
|
|
2000-05-15 04:16:30 +04:00
|
|
|
#if 0
|
2000-04-04 09:45:57 +04:00
|
|
|
template <class CharT>
|
|
|
|
inline
|
|
|
|
PRBool
|
|
|
|
basic_nsAReadableString<CharT>::Equals( const CharT* rhs, PRUint32 rhs_length ) const
|
|
|
|
{
|
|
|
|
return Compare(basic_nsLiteralString<CharT>(rhs, rhs_length)) == 0;
|
|
|
|
}
|
2000-05-15 04:16:30 +04:00
|
|
|
#endif
|
2000-04-04 09:45:57 +04:00
|
|
|
|
|
|
|
template <class CharT>
|
|
|
|
inline
|
|
|
|
int
|
|
|
|
basic_nsAReadableString<CharT>::Compare( const CharT* rhs ) const
|
|
|
|
{
|
2000-05-14 00:29:18 +04:00
|
|
|
return ::Compare(*this, NS_READABLE_CAST(CharT, basic_nsLiteralString<CharT>(rhs)));
|
2000-04-04 09:45:57 +04:00
|
|
|
}
|
|
|
|
|
2000-05-15 02:32:30 +04:00
|
|
|
#if 0
|
2000-04-04 09:45:57 +04:00
|
|
|
template <class CharT>
|
|
|
|
inline
|
|
|
|
int
|
|
|
|
basic_nsAReadableString<CharT>::Compare( const CharT* rhs, PRUint32 rhs_length ) const
|
|
|
|
{
|
2000-05-14 00:29:18 +04:00
|
|
|
return ::Compare(*this, NS_READABLE_CAST(CharT, basic_nsLiteralString<CharT>(rhs, rhs_length)));
|
2000-04-04 09:45:57 +04:00
|
|
|
}
|
2000-05-15 02:32:30 +04:00
|
|
|
#endif
|
2000-03-12 04:28:16 +03:00
|
|
|
|
|
|
|
|
2000-03-31 02:53:41 +04:00
|
|
|
//
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-03-12 04:28:16 +03:00
|
|
|
|
|
|
|
//
|
|
|
|
// nsPromiseConcatenation
|
|
|
|
//
|
|
|
|
|
2000-04-28 00:01:28 +04:00
|
|
|
template <class CharT> class nsPromiseReadable : public basic_nsAReadableString<CharT> { };
|
|
|
|
|
2000-03-09 09:37:45 +03:00
|
|
|
template <class CharT>
|
2000-03-10 05:30:14 +03:00
|
|
|
class nsPromiseConcatenation
|
2000-04-28 00:01:28 +04:00
|
|
|
: public nsPromiseReadable<CharT>
|
2000-03-09 09:37:45 +03:00
|
|
|
/*
|
2000-03-12 04:28:16 +03:00
|
|
|
NOT FOR USE BY HUMANS
|
|
|
|
|
|
|
|
Instances of this class only exist as anonymous temporary results from |operator+()|.
|
|
|
|
This is the machinery that makes string concatenation efficient. No allocations or
|
|
|
|
character copies are required unless and until a final assignment is made. It works
|
2000-03-24 00:15:01 +03:00
|
|
|
its magic by overriding and forwarding calls to |GetReadableFragment()|.
|
2000-03-12 04:28:16 +03:00
|
|
|
|
|
|
|
Note: |nsPromiseConcatenation| imposes some limits on string concatenation with |operator+()|.
|
|
|
|
- no more than 33 strings, e.g., |s1 + s2 + s3 + ... s32 + s33|
|
|
|
|
- left to right evaluation is required ... do not use parentheses to override this
|
|
|
|
|
|
|
|
In practice, neither of these is onerous. Parentheses do not change the semantics of the
|
|
|
|
concatenation, only the order in which the result is assembled ... so there's no reason
|
|
|
|
for a user to need to control it. Too many strings summed together can easily be worked
|
|
|
|
around with an intermediate assignment. I wouldn't have the parentheses limitation if I
|
|
|
|
assigned the identifier mask starting at the top, the first time anybody called
|
2000-03-24 00:15:01 +03:00
|
|
|
|GetReadableFragment()|.
|
2000-03-09 09:37:45 +03:00
|
|
|
*/
|
|
|
|
{
|
|
|
|
protected:
|
2000-03-25 01:06:57 +03:00
|
|
|
virtual const CharT* GetReadableFragment( nsReadableFragment<CharT>&, nsFragmentRequest, PRUint32 ) const;
|
2000-03-09 09:37:45 +03:00
|
|
|
|
2000-03-14 20:10:03 +03:00
|
|
|
enum { kLeftString, kRightString };
|
2000-03-09 09:37:45 +03:00
|
|
|
|
2000-03-10 10:04:09 +03:00
|
|
|
int
|
2000-03-25 01:06:57 +03:00
|
|
|
GetCurrentStringFromFragment( const nsReadableFragment<CharT>& aFragment ) const
|
2000-03-10 10:04:09 +03:00
|
|
|
{
|
|
|
|
return (aFragment.mFragmentIdentifier & mFragmentIdentifierMask) ? kRightString : kLeftString;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-03-25 01:06:57 +03:00
|
|
|
SetLeftStringInFragment( nsReadableFragment<CharT>& aFragment ) const
|
2000-03-10 10:04:09 +03:00
|
|
|
{
|
|
|
|
aFragment.mFragmentIdentifier &= ~mFragmentIdentifierMask;
|
|
|
|
return kLeftString;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-03-25 01:06:57 +03:00
|
|
|
SetRightStringInFragment( nsReadableFragment<CharT>& aFragment ) const
|
2000-03-10 10:04:09 +03:00
|
|
|
{
|
|
|
|
aFragment.mFragmentIdentifier |= mFragmentIdentifierMask;
|
|
|
|
return kRightString;
|
|
|
|
}
|
|
|
|
|
2000-03-09 09:37:45 +03:00
|
|
|
public:
|
2000-03-10 10:04:09 +03:00
|
|
|
nsPromiseConcatenation( const basic_nsAReadableString<CharT>& aLeftString, const basic_nsAReadableString<CharT>& aRightString, PRUint32 aMask = 1 )
|
|
|
|
: mFragmentIdentifierMask(aMask)
|
2000-03-09 09:37:45 +03:00
|
|
|
{
|
|
|
|
mStrings[kLeftString] = &aLeftString;
|
|
|
|
mStrings[kRightString] = &aRightString;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual PRUint32 Length() const;
|
2000-04-28 00:01:28 +04:00
|
|
|
virtual PRBool Promises( const basic_nsAReadableString<CharT>& ) const;
|
2000-05-14 00:17:35 +04:00
|
|
|
// virtual PRBool PromisesExactly( const basic_nsAReadableString<CharT>& ) const;
|
2000-03-09 09:37:45 +03:00
|
|
|
|
2000-03-10 10:04:09 +03:00
|
|
|
nsPromiseConcatenation<CharT> operator+( const basic_nsAReadableString<CharT>& rhs ) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void operator+( const nsPromiseConcatenation<CharT>& ); // NOT TO BE IMPLEMENTED
|
|
|
|
// making this |private| stops you from over parenthesizing concatenation expressions, e.g., |(A+B) + (C+D)|
|
|
|
|
// which would break the algorithm for distributing bits in the fragment identifier
|
|
|
|
|
2000-03-09 09:37:45 +03:00
|
|
|
private:
|
|
|
|
const basic_nsAReadableString<CharT>* mStrings[2];
|
2000-03-10 10:04:09 +03:00
|
|
|
PRUint32 mFragmentIdentifierMask;
|
2000-03-09 09:37:45 +03:00
|
|
|
};
|
|
|
|
|
2000-05-14 01:39:37 +04:00
|
|
|
NS_DEF_TEMPLATE_STRING_COMPARISON_OPERATORS(nsPromiseConcatenation<CharT>, CharT)
|
2000-03-09 09:37:45 +03:00
|
|
|
|
|
|
|
template <class CharT>
|
|
|
|
PRUint32
|
2000-03-10 05:30:14 +03:00
|
|
|
nsPromiseConcatenation<CharT>::Length() const
|
2000-03-09 09:37:45 +03:00
|
|
|
{
|
|
|
|
return mStrings[kLeftString]->Length() + mStrings[kRightString]->Length();
|
|
|
|
}
|
|
|
|
|
2000-04-28 00:01:28 +04:00
|
|
|
template <class CharT>
|
|
|
|
PRBool
|
|
|
|
nsPromiseConcatenation<CharT>::Promises( const basic_nsAReadableString<CharT>& aString ) const
|
|
|
|
{
|
|
|
|
return mStrings[0]->Promises(aString) || mStrings[1]->Promises(aString);
|
|
|
|
}
|
|
|
|
|
2000-05-14 00:17:35 +04:00
|
|
|
#if 0
|
|
|
|
PRBool
|
|
|
|
nsPromiseConcatenation<CharT>::PromisesExactly( const basic_nsAReadableString<CharT>& aString ) const
|
|
|
|
{
|
|
|
|
// Not really like this, test for the empty string, etc
|
|
|
|
return mStrings[0] == &aString && !mStrings[1] || !mStrings[0] && mStrings[1] == &aString;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-03-09 09:37:45 +03:00
|
|
|
template <class CharT>
|
|
|
|
const CharT*
|
2000-03-25 01:06:57 +03:00
|
|
|
nsPromiseConcatenation<CharT>::GetReadableFragment( nsReadableFragment<CharT>& aFragment, nsFragmentRequest aRequest, PRUint32 aPosition ) const
|
2000-03-09 09:37:45 +03:00
|
|
|
{
|
|
|
|
int whichString;
|
|
|
|
|
2000-03-24 00:15:01 +03:00
|
|
|
// based on the request, pick which string we will forward the |GetReadableFragment()| call into
|
2000-03-12 04:28:16 +03:00
|
|
|
|
2000-03-09 09:37:45 +03:00
|
|
|
switch ( aRequest )
|
|
|
|
{
|
|
|
|
case kPrevFragment:
|
|
|
|
case kNextFragment:
|
2000-03-12 04:28:16 +03:00
|
|
|
whichString = GetCurrentStringFromFragment(aFragment);
|
2000-03-09 09:37:45 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case kFirstFragment:
|
2000-03-12 04:28:16 +03:00
|
|
|
whichString = SetLeftStringInFragment(aFragment);
|
2000-03-09 09:37:45 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case kLastFragment:
|
2000-03-12 04:28:16 +03:00
|
|
|
whichString = SetRightStringInFragment(aFragment);
|
2000-03-09 09:37:45 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case kFragmentAt:
|
|
|
|
PRUint32 leftLength = mStrings[kLeftString]->Length();
|
|
|
|
if ( aPosition < leftLength )
|
2000-03-12 04:28:16 +03:00
|
|
|
whichString = SetLeftStringInFragment(aFragment);
|
2000-03-09 09:37:45 +03:00
|
|
|
else
|
|
|
|
{
|
2000-03-12 04:28:16 +03:00
|
|
|
whichString = SetRightStringInFragment(aFragment);
|
2000-03-09 09:37:45 +03:00
|
|
|
aPosition -= leftLength;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const CharT* result;
|
2000-04-28 00:01:28 +04:00
|
|
|
PRBool done;
|
2000-03-09 09:37:45 +03:00
|
|
|
do
|
|
|
|
{
|
2000-04-28 00:01:28 +04:00
|
|
|
done = PR_TRUE;
|
2000-03-24 00:15:01 +03:00
|
|
|
result = mStrings[whichString]->GetReadableFragment(aFragment, aRequest, aPosition);
|
2000-03-09 09:37:45 +03:00
|
|
|
|
|
|
|
if ( !result )
|
|
|
|
{
|
2000-04-28 00:01:28 +04:00
|
|
|
done = PR_FALSE;
|
2000-03-09 09:37:45 +03:00
|
|
|
if ( aRequest == kNextFragment && whichString == kLeftString )
|
|
|
|
{
|
|
|
|
aRequest = kFirstFragment;
|
2000-03-12 04:28:16 +03:00
|
|
|
whichString = SetRightStringInFragment(aFragment);
|
2000-03-09 09:37:45 +03:00
|
|
|
}
|
|
|
|
else if ( aRequest == kPrevFragment && whichString == kRightString )
|
|
|
|
{
|
|
|
|
aRequest = kLastFragment;
|
2000-03-12 04:28:16 +03:00
|
|
|
whichString = SetLeftStringInFragment(aFragment);
|
2000-03-09 09:37:45 +03:00
|
|
|
}
|
|
|
|
else
|
2000-04-28 00:01:28 +04:00
|
|
|
done = PR_TRUE;
|
2000-03-09 09:37:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
while ( !done );
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-03-10 10:04:09 +03:00
|
|
|
template <class CharT>
|
2000-03-25 01:06:57 +03:00
|
|
|
inline
|
2000-03-10 10:04:09 +03:00
|
|
|
nsPromiseConcatenation<CharT>
|
|
|
|
nsPromiseConcatenation<CharT>::operator+( const basic_nsAReadableString<CharT>& rhs ) const
|
|
|
|
{
|
|
|
|
return nsPromiseConcatenation<CharT>(*this, rhs, mFragmentIdentifierMask<<1);
|
|
|
|
}
|
|
|
|
|
2000-03-09 09:37:45 +03:00
|
|
|
|
2000-03-12 04:28:16 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// nsPromiseSubstring
|
|
|
|
//
|
|
|
|
|
2000-03-10 05:30:14 +03:00
|
|
|
template <class CharT>
|
|
|
|
class nsPromiseSubstring
|
2000-04-28 00:01:28 +04:00
|
|
|
: public nsPromiseReadable<CharT>
|
2000-03-12 04:28:16 +03:00
|
|
|
/*
|
|
|
|
NOT FOR USE BY HUMANS (mostly)
|
|
|
|
|
|
|
|
...not unlike |nsPromiseConcatenation|. Instances of this class exist only as anonymous
|
|
|
|
temporary results from |Substring()|. Like |nsPromiseConcatenation|, this class only
|
|
|
|
holds a pointer, no string data of its own. It does its magic by overriding and forwarding
|
2000-03-24 00:15:01 +03:00
|
|
|
calls to |GetReadableFragment()|.
|
2000-03-12 04:28:16 +03:00
|
|
|
*/
|
2000-03-10 05:30:14 +03:00
|
|
|
{
|
|
|
|
protected:
|
2000-03-25 01:06:57 +03:00
|
|
|
virtual const CharT* GetReadableFragment( nsReadableFragment<CharT>&, nsFragmentRequest, PRUint32 ) const;
|
2000-03-10 05:30:14 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
nsPromiseSubstring( const basic_nsAReadableString<CharT>& aString, PRUint32 aStartPos, PRUint32 aLength )
|
|
|
|
: mString(aString),
|
2000-03-24 03:39:44 +03:00
|
|
|
mStartPos( NS_MIN(aStartPos, aString.Length()) ),
|
|
|
|
mLength( NS_MIN(aLength, aString.Length()-mStartPos) )
|
2000-03-10 05:30:14 +03:00
|
|
|
{
|
|
|
|
// nothing else to do here
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual PRUint32 Length() const;
|
2000-04-28 00:01:28 +04:00
|
|
|
virtual PRBool Promises( const basic_nsAReadableString<CharT>& aString ) const { return mString.Promises(aString); }
|
2000-03-10 05:30:14 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
const basic_nsAReadableString<CharT>& mString;
|
|
|
|
PRUint32 mStartPos;
|
|
|
|
PRUint32 mLength;
|
|
|
|
};
|
|
|
|
|
2000-05-14 01:39:37 +04:00
|
|
|
NS_DEF_TEMPLATE_STRING_COMPARISON_OPERATORS(nsPromiseSubstring<CharT>, CharT)
|
2000-03-10 05:30:14 +03:00
|
|
|
|
|
|
|
template <class CharT>
|
|
|
|
PRUint32
|
|
|
|
nsPromiseSubstring<CharT>::Length() const
|
|
|
|
{
|
|
|
|
return mLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class CharT>
|
|
|
|
const CharT*
|
2000-03-25 01:06:57 +03:00
|
|
|
nsPromiseSubstring<CharT>::GetReadableFragment( nsReadableFragment<CharT>& aFragment, nsFragmentRequest aRequest, PRUint32 aPosition ) const
|
2000-03-10 05:30:14 +03:00
|
|
|
{
|
2000-03-12 04:28:16 +03:00
|
|
|
// Offset any request for a specific position (First, Last, At) by our
|
|
|
|
// substrings startpos within the owning string
|
|
|
|
|
2000-03-10 05:30:14 +03:00
|
|
|
if ( aRequest == kFirstFragment )
|
|
|
|
{
|
|
|
|
aPosition = mStartPos;
|
|
|
|
aRequest = kFragmentAt;
|
|
|
|
}
|
|
|
|
else if ( aRequest == kLastFragment )
|
|
|
|
{
|
2000-03-12 04:28:16 +03:00
|
|
|
aPosition = mStartPos + mLength;
|
2000-03-10 05:30:14 +03:00
|
|
|
aRequest = kFragmentAt;
|
|
|
|
}
|
|
|
|
else if ( aRequest == kFragmentAt )
|
|
|
|
aPosition += mStartPos;
|
|
|
|
|
2000-04-21 05:25:19 +04:00
|
|
|
const CharT* position_ptr = mString.GetReadableFragment(aFragment, aRequest, aPosition);
|
|
|
|
|
2000-05-14 00:17:35 +04:00
|
|
|
// if there's more physical data in the returned fragment than I logically have left...
|
2000-04-21 05:25:19 +04:00
|
|
|
size_t logical_size_forward = mLength - aPosition;
|
|
|
|
if ( aFragment.mEnd - position_ptr > logical_size_forward )
|
|
|
|
aFragment.mEnd = position_ptr + logical_size_forward;
|
|
|
|
|
|
|
|
return position_ptr;
|
2000-03-10 05:30:14 +03:00
|
|
|
}
|
|
|
|
|
2000-03-09 09:37:45 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-03-12 04:28:16 +03:00
|
|
|
//
|
|
|
|
// Global functions
|
|
|
|
//
|
2000-03-09 09:37:45 +03:00
|
|
|
|
2000-04-21 05:25:19 +04:00
|
|
|
template <class CharT>
|
|
|
|
inline
|
|
|
|
PRBool
|
|
|
|
SameImplementation( const basic_nsAReadableString<CharT>& lhs, const basic_nsAReadableString<CharT>& rhs )
|
|
|
|
{
|
|
|
|
const void* imp_tag = lhs.Implementation();
|
|
|
|
return imp_tag && (imp_tag==rhs.Implementation());
|
|
|
|
}
|
|
|
|
|
2000-03-25 03:47:02 +03:00
|
|
|
template <class InputIterator, class OutputIterator>
|
|
|
|
OutputIterator
|
2000-03-29 04:54:12 +04:00
|
|
|
copy_string( InputIterator first, InputIterator last, OutputIterator result )
|
2000-03-25 03:47:02 +03:00
|
|
|
{
|
2000-04-21 05:25:19 +04:00
|
|
|
typedef nsCharSourceTraits<InputIterator> source_traits;
|
|
|
|
typedef nsCharSinkTraits<OutputIterator> sink_traits;
|
2000-03-25 03:47:02 +03:00
|
|
|
|
|
|
|
while ( first != last )
|
2000-05-12 09:16:00 +04:00
|
|
|
{
|
2000-05-14 00:17:35 +04:00
|
|
|
PRInt32 count_copied = PRInt32(sink_traits::write(result, source_traits::read(first), source_traits::readable_distance(first, last)));
|
2000-05-12 09:16:00 +04:00
|
|
|
NS_ASSERTION(count_copied > 0, "|copy_string| will never terminate");
|
|
|
|
first += count_copied;
|
|
|
|
}
|
2000-03-25 03:47:02 +03:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-03-27 13:06:37 +04:00
|
|
|
template <class InputIterator, class OutputIterator>
|
|
|
|
OutputIterator
|
2000-03-29 04:54:12 +04:00
|
|
|
copy_string_backward( InputIterator first, InputIterator last, OutputIterator result )
|
2000-03-27 13:06:37 +04:00
|
|
|
{
|
|
|
|
while ( first != last )
|
|
|
|
{
|
|
|
|
PRUint32 lengthToCopy = PRUint32( NS_MIN(last.size_backward(), result.size_backward()) );
|
|
|
|
if ( first.fragment().mStart == last.fragment().mStart )
|
|
|
|
lengthToCopy = NS_MIN(lengthToCopy, PRUint32(last.operator->() - first.operator->()));
|
|
|
|
|
2000-03-29 04:54:12 +04:00
|
|
|
NS_ASSERTION(lengthToCopy, "|copy_string_backward| will never terminate");
|
2000-03-27 13:06:37 +04:00
|
|
|
|
2000-05-15 09:14:40 +04:00
|
|
|
nsCharTraits<OutputIterator::value_type>::move(result.operator->()-lengthToCopy, last.operator->()-lengthToCopy, lengthToCopy);
|
2000-03-27 13:06:37 +04:00
|
|
|
|
|
|
|
last -= PRInt32(lengthToCopy);
|
|
|
|
result -= PRInt32(lengthToCopy);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-03-07 04:02:10 +03:00
|
|
|
template <class CharT>
|
2000-03-12 04:28:16 +03:00
|
|
|
nsPromiseSubstring<CharT>
|
|
|
|
Substring( const basic_nsAReadableString<CharT>& aString, PRUint32 aStartPos, PRUint32 aSubstringLength )
|
2000-03-07 04:02:10 +03:00
|
|
|
{
|
2000-03-12 04:28:16 +03:00
|
|
|
return nsPromiseSubstring<CharT>(aString, aStartPos, aSubstringLength);
|
2000-03-07 04:02:10 +03:00
|
|
|
}
|
|
|
|
|
2000-03-09 00:57:14 +03:00
|
|
|
template <class CharT>
|
|
|
|
int
|
|
|
|
Compare( const basic_nsAReadableString<CharT>& lhs, const basic_nsAReadableString<CharT>& rhs )
|
|
|
|
{
|
2000-03-22 11:19:48 +03:00
|
|
|
if ( &lhs == &rhs )
|
|
|
|
return 0;
|
2000-03-09 09:37:45 +03:00
|
|
|
|
2000-03-09 00:57:14 +03:00
|
|
|
PRUint32 lLength = lhs.Length();
|
|
|
|
PRUint32 rLength = rhs.Length();
|
2000-03-24 03:39:44 +03:00
|
|
|
PRUint32 lengthToCompare = NS_MIN(lLength, rLength);
|
2000-03-09 00:57:14 +03:00
|
|
|
|
2000-03-25 01:06:57 +03:00
|
|
|
nsReadingIterator<CharT> leftIter( lhs.BeginReading() );
|
|
|
|
nsReadingIterator<CharT> rightIter( rhs.BeginReading() );
|
2000-03-09 00:57:14 +03:00
|
|
|
|
2000-03-22 11:19:48 +03:00
|
|
|
for (;;)
|
2000-03-09 00:57:14 +03:00
|
|
|
{
|
2000-03-24 03:39:44 +03:00
|
|
|
PRUint32 lengthAvailable = PRUint32( NS_MIN(leftIter.size_forward(), rightIter.size_forward()) );
|
2000-03-22 11:19:48 +03:00
|
|
|
|
|
|
|
if ( lengthAvailable > lengthToCompare )
|
|
|
|
lengthAvailable = lengthToCompare;
|
|
|
|
|
2000-03-24 00:15:01 +03:00
|
|
|
if ( int result = nsCharTraits<CharT>::compare(leftIter.operator->(), rightIter.operator->(), lengthAvailable) )
|
2000-03-22 11:19:48 +03:00
|
|
|
return result;
|
|
|
|
|
|
|
|
if ( !(lengthToCompare -= lengthAvailable) )
|
|
|
|
break;
|
2000-03-09 00:57:14 +03:00
|
|
|
|
2000-03-23 01:51:18 +03:00
|
|
|
leftIter += PRInt32(lengthAvailable);
|
|
|
|
rightIter += PRInt32(lengthAvailable);
|
2000-03-09 00:57:14 +03:00
|
|
|
}
|
|
|
|
|
2000-03-12 04:28:16 +03:00
|
|
|
if ( lLength < rLength )
|
|
|
|
return -1;
|
|
|
|
else if ( rLength < lLength )
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
2000-03-09 00:57:14 +03:00
|
|
|
}
|
|
|
|
|
2000-03-07 04:02:10 +03:00
|
|
|
template <class CharT>
|
2000-03-12 04:28:16 +03:00
|
|
|
inline
|
2000-03-07 04:02:10 +03:00
|
|
|
int
|
2000-03-09 09:37:45 +03:00
|
|
|
Compare( const basic_nsAReadableString<CharT>& lhs, const CharT* rhs )
|
2000-03-09 00:57:14 +03:00
|
|
|
{
|
2000-05-14 00:29:18 +04:00
|
|
|
return Compare(lhs, NS_READABLE_CAST(CharT, basic_nsLiteralString<CharT>(rhs)));
|
2000-03-09 00:57:14 +03:00
|
|
|
}
|
2000-03-07 04:02:10 +03:00
|
|
|
|
2000-03-09 00:57:14 +03:00
|
|
|
template <class CharT>
|
2000-03-12 04:28:16 +03:00
|
|
|
inline
|
2000-03-09 09:37:45 +03:00
|
|
|
int
|
|
|
|
Compare( const CharT* lhs, const basic_nsAReadableString<CharT>& rhs )
|
2000-03-09 00:57:14 +03:00
|
|
|
{
|
2000-05-14 00:29:18 +04:00
|
|
|
return Compare(NS_READABLE_CAST(CharT, basic_nsLiteralString<CharT>(lhs)), rhs);
|
2000-03-09 00:57:14 +03:00
|
|
|
}
|
2000-03-07 04:02:10 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
How shall we provide |operator+()|?
|
|
|
|
|
|
|
|
What would it return? It has to return a stack based object, because the client will
|
|
|
|
not be given an opportunity to handle memory management in an expression like
|
|
|
|
|
|
|
|
myWritableString = stringA + stringB + stringC;
|
|
|
|
|
|
|
|
...so the `obvious' answer of returning a new |nsSharedString| is no good. We could
|
|
|
|
return an |nsString|, if that name were in scope here, though there's no telling what the client
|
|
|
|
will really want to do with the result. What might be better, though,
|
|
|
|
is to return a `promise' to concatenate some strings...
|
|
|
|
|
2000-03-10 05:30:14 +03:00
|
|
|
By making |nsPromiseConcatenation| inherit from readable strings, we automatically handle
|
2000-03-07 04:02:10 +03:00
|
|
|
assignment and other interesting uses within writable strings, plus we drastically reduce
|
|
|
|
the number of cases we have to write |operator+()| for. The cost is extra temporary concat strings
|
|
|
|
in the evaluation of strings of '+'s, e.g., |A + B + C + D|, and that we have to do some work
|
|
|
|
to implement the virtual functions of readables.
|
|
|
|
*/
|
|
|
|
|
2000-05-14 00:17:35 +04:00
|
|
|
/*
|
|
|
|
I probably need to add |operator+()| for appropriate |CharT| and |CharT*| comparisons, since
|
|
|
|
automatic conversion to a literal string will not happen.
|
|
|
|
*/
|
|
|
|
|
2000-03-07 04:02:10 +03:00
|
|
|
template <class CharT>
|
2000-03-25 01:06:57 +03:00
|
|
|
inline
|
2000-03-10 05:30:14 +03:00
|
|
|
nsPromiseConcatenation<CharT>
|
2000-03-09 09:37:45 +03:00
|
|
|
operator+( const basic_nsAReadableString<CharT>& lhs, const basic_nsAReadableString<CharT>& rhs )
|
2000-03-07 04:02:10 +03:00
|
|
|
{
|
2000-03-10 05:30:14 +03:00
|
|
|
return nsPromiseConcatenation<CharT>(lhs, rhs);
|
2000-03-09 09:37:45 +03:00
|
|
|
}
|
2000-03-07 04:02:10 +03:00
|
|
|
|
2000-05-15 11:28:00 +04:00
|
|
|
#ifdef NEED_CPP_DERIVED_TEMPLATE_OPERATORS
|
|
|
|
#define NS_DEF_DERIVED_STRING_STRING_OPERATOR_PLUS(_String1T, _String2T, _CharT) \
|
|
|
|
inline \
|
|
|
|
nsPromiseConcatenation<_CharT> \
|
|
|
|
operator+( const _String1T& lhs, const _String2T& rhs ) \
|
|
|
|
{ \
|
|
|
|
return nsPromiseConcatenation<_CharT>(lhs, rhs); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define NS_DEF_DERIVED_STRING_OPERATOR_PLUS(_StringT, _CharT) \
|
|
|
|
NS_DEF_DERIVED_STRING_STRING_OPERATOR_PLUS(_StringT, _StringT, _CharT)
|
|
|
|
|
|
|
|
#define NS_DEF_2_STRING_STRING_OPERATOR_PLUS(_String1T, _String2T, _CharT) \
|
|
|
|
NS_DEF_DERIVED_STRING_STRING_OPERATOR_PLUS(_String1T, _String2T, _CharT) \
|
|
|
|
NS_DEF_DERIVED_STRING_STRING_OPERATOR_PLUS(_String2T, _String1T, _CharT)
|
|
|
|
|
|
|
|
#else
|
|
|
|
#define NS_DEF_DERIVED_STRING_OPERATOR_PLUS(_StringT, _CharT)
|
|
|
|
#define NS_DEF_2_STRING_STRING_OPERATOR_PLUS(_String1T, _String2T, _CharT)
|
|
|
|
#endif
|
|
|
|
|
2000-03-09 00:57:14 +03:00
|
|
|
template <class CharT>
|
2000-03-25 01:06:57 +03:00
|
|
|
inline
|
2000-03-10 05:30:14 +03:00
|
|
|
nsPromiseConcatenation<CharT>
|
2000-03-09 09:37:45 +03:00
|
|
|
operator+( const basic_nsAReadableString<CharT>& lhs, const basic_nsLiteralString<CharT>& rhs )
|
2000-03-09 00:57:14 +03:00
|
|
|
{
|
2000-03-10 05:30:14 +03:00
|
|
|
return nsPromiseConcatenation<CharT>(lhs, rhs);
|
2000-03-09 00:57:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class CharT>
|
2000-03-25 01:06:57 +03:00
|
|
|
inline
|
2000-03-10 05:30:14 +03:00
|
|
|
nsPromiseConcatenation<CharT>
|
2000-03-09 09:37:45 +03:00
|
|
|
operator+( const basic_nsLiteralString<CharT>& lhs, const basic_nsAReadableString<CharT>& rhs )
|
2000-03-09 00:57:14 +03:00
|
|
|
{
|
2000-03-10 05:30:14 +03:00
|
|
|
return nsPromiseConcatenation<CharT>(lhs, rhs);
|
2000-03-09 00:57:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class CharT>
|
2000-03-25 01:06:57 +03:00
|
|
|
inline
|
2000-03-10 05:30:14 +03:00
|
|
|
nsPromiseConcatenation<CharT>
|
2000-03-09 09:37:45 +03:00
|
|
|
operator+( const basic_nsLiteralString<CharT>& lhs, const basic_nsLiteralString<CharT>& rhs )
|
2000-03-09 00:57:14 +03:00
|
|
|
{
|
2000-03-10 05:30:14 +03:00
|
|
|
return nsPromiseConcatenation<CharT>(lhs, rhs);
|
2000-03-09 00:57:14 +03:00
|
|
|
}
|
2000-03-07 04:02:10 +03:00
|
|
|
|
2000-03-10 10:04:09 +03:00
|
|
|
|
|
|
|
|
2000-03-07 04:02:10 +03:00
|
|
|
typedef basic_nsAReadableString<PRUnichar> nsAReadableString;
|
|
|
|
typedef basic_nsAReadableString<char> nsAReadableCString;
|
|
|
|
|
2000-03-09 09:37:45 +03:00
|
|
|
typedef basic_nsLiteralString<PRUnichar> nsLiteralString;
|
|
|
|
typedef basic_nsLiteralString<char> nsLiteralCString;
|
|
|
|
|
2000-03-29 02:37:51 +04:00
|
|
|
#define NS_LITERAL_STRING(s) nsLiteralString(s, sizeof(s)/sizeof(wchar_t))
|
|
|
|
#define NS_LITERAL_CSTRING(s) nsLiteralCString(s, sizeof(s))
|
|
|
|
|
2000-03-31 02:53:41 +04:00
|
|
|
typedef basic_nsLiteralChar<char> nsLiteralChar;
|
|
|
|
typedef basic_nsLiteralChar<PRUnichar> nsLiteralPRUnichar;
|
|
|
|
|
2000-03-29 02:37:51 +04:00
|
|
|
|
2000-03-07 04:02:10 +03:00
|
|
|
#endif // !defined(_nsAReadableString_h__)
|