mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 06:11:37 +00:00
bug #54712, r=rjc, a=waterson. Added a |Distance| function to calculate the span between two iterators, then added a constructor and appropriate global function to allow |Substring|s to be made from iterators in addition to the old scheme of {index,length}
This commit is contained in:
parent
e8afc1691f
commit
64e5d4cbd1
@ -1184,6 +1184,15 @@ class nsPromiseSubstring
|
||||
// nothing else to do here
|
||||
}
|
||||
|
||||
nsPromiseSubstring( const nsReadingIterator<CharT>& aStart, const nsReadingIterator<CharT>& aEnd )
|
||||
: mString(*aStart.mOwningString)
|
||||
{
|
||||
nsReadingIterator<CharT> zeroPoint;
|
||||
mOwningString.BeginReading(zeroPoint);
|
||||
mStartPos = Distance(zeroPoint, aStart);
|
||||
mLength = Distance(aStart, aEnd);
|
||||
}
|
||||
|
||||
// nsPromiseSubstring( const nsPromiseSubstring<CharT>& ); // auto-generated copy-constructor should be OK
|
||||
// ~nsPromiseSubstring(); // auto-generated destructor OK
|
||||
|
||||
@ -1278,6 +1287,13 @@ Substring( const basic_nsAReadableString<CharT>& aString, PRUint32 aStartPos, PR
|
||||
return nsPromiseSubstring<CharT>(aString, aStartPos, aSubstringLength);
|
||||
}
|
||||
|
||||
template <class CharT>
|
||||
nsPromiseSubstring<CharT>
|
||||
Substring( const nsReadingIterator<CharT>& aStart, const nsReadingIterator<CharT>& aEnd )
|
||||
{
|
||||
return nsPromiseSubstring<Chart>(aStart, aEnd);
|
||||
}
|
||||
|
||||
template <class CharT>
|
||||
int
|
||||
Compare( const basic_nsAReadableString<CharT>& lhs, const basic_nsAReadableString<CharT>& rhs )
|
||||
|
@ -35,6 +35,11 @@
|
||||
#include "nsAWritableString.h"
|
||||
#endif
|
||||
|
||||
NS_COM size_t Distance( const nsReadingIterator<PRUnichar>&, const nsReadingIterator<PRUnichar>& );
|
||||
NS_COM size_t Distance( const nsReadingIterator<char>&, const nsReadingIterator<char>& );
|
||||
|
||||
|
||||
|
||||
NS_COM void CopyUCS2toASCII( const nsAReadableString& aSource, nsAWritableCString& aDest );
|
||||
NS_COM void CopyASCIItoUCS2( const nsAReadableCString& aSource, nsAWritableString& aDest );
|
||||
|
||||
|
@ -27,6 +27,45 @@
|
||||
#include "nsCRT.h"
|
||||
|
||||
|
||||
template <class CharT> class CalculateLength
|
||||
{
|
||||
public:
|
||||
typedef CharT value_type;
|
||||
|
||||
CalculateLength() : mDistance(0) { }
|
||||
size_t GetDistance() const { return mDistance; }
|
||||
|
||||
PRUint32 write( const CharT*, PRUint32 N )
|
||||
{ mDistance += N; return N; }
|
||||
private:
|
||||
size_t mDistance;
|
||||
};
|
||||
|
||||
template <class CharT>
|
||||
inline
|
||||
size_t
|
||||
Distance_Impl( const nsReadingIterator<CharT>& aStart,
|
||||
const nsReadingIterator<CharT>& aEnd )
|
||||
{
|
||||
CalculateLength<CharT> sink;
|
||||
nsReadingIterator<CharT> fromBegin(aStart);
|
||||
copy_string(fromBegin, aEnd, sink);
|
||||
return sink.GetDistance();
|
||||
}
|
||||
|
||||
NS_COM
|
||||
size_t
|
||||
Distance( const nsReadingIterator<PRUnichar>& aStart, const nsReadingIterator<PRUnichar>& aEnd )
|
||||
{
|
||||
return Distance_Impl(aStart, aEnd);
|
||||
}
|
||||
|
||||
NS_COM
|
||||
size_t
|
||||
Distance( const nsReadingIterator<char>& aStart, const nsReadingIterator<char>& aEnd )
|
||||
{
|
||||
return Distance_Impl(aStart, aEnd);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1184,6 +1184,15 @@ class nsPromiseSubstring
|
||||
// nothing else to do here
|
||||
}
|
||||
|
||||
nsPromiseSubstring( const nsReadingIterator<CharT>& aStart, const nsReadingIterator<CharT>& aEnd )
|
||||
: mString(*aStart.mOwningString)
|
||||
{
|
||||
nsReadingIterator<CharT> zeroPoint;
|
||||
mOwningString.BeginReading(zeroPoint);
|
||||
mStartPos = Distance(zeroPoint, aStart);
|
||||
mLength = Distance(aStart, aEnd);
|
||||
}
|
||||
|
||||
// nsPromiseSubstring( const nsPromiseSubstring<CharT>& ); // auto-generated copy-constructor should be OK
|
||||
// ~nsPromiseSubstring(); // auto-generated destructor OK
|
||||
|
||||
@ -1278,6 +1287,13 @@ Substring( const basic_nsAReadableString<CharT>& aString, PRUint32 aStartPos, PR
|
||||
return nsPromiseSubstring<CharT>(aString, aStartPos, aSubstringLength);
|
||||
}
|
||||
|
||||
template <class CharT>
|
||||
nsPromiseSubstring<CharT>
|
||||
Substring( const nsReadingIterator<CharT>& aStart, const nsReadingIterator<CharT>& aEnd )
|
||||
{
|
||||
return nsPromiseSubstring<Chart>(aStart, aEnd);
|
||||
}
|
||||
|
||||
template <class CharT>
|
||||
int
|
||||
Compare( const basic_nsAReadableString<CharT>& lhs, const basic_nsAReadableString<CharT>& rhs )
|
||||
|
@ -27,6 +27,45 @@
|
||||
#include "nsCRT.h"
|
||||
|
||||
|
||||
template <class CharT> class CalculateLength
|
||||
{
|
||||
public:
|
||||
typedef CharT value_type;
|
||||
|
||||
CalculateLength() : mDistance(0) { }
|
||||
size_t GetDistance() const { return mDistance; }
|
||||
|
||||
PRUint32 write( const CharT*, PRUint32 N )
|
||||
{ mDistance += N; return N; }
|
||||
private:
|
||||
size_t mDistance;
|
||||
};
|
||||
|
||||
template <class CharT>
|
||||
inline
|
||||
size_t
|
||||
Distance_Impl( const nsReadingIterator<CharT>& aStart,
|
||||
const nsReadingIterator<CharT>& aEnd )
|
||||
{
|
||||
CalculateLength<CharT> sink;
|
||||
nsReadingIterator<CharT> fromBegin(aStart);
|
||||
copy_string(fromBegin, aEnd, sink);
|
||||
return sink.GetDistance();
|
||||
}
|
||||
|
||||
NS_COM
|
||||
size_t
|
||||
Distance( const nsReadingIterator<PRUnichar>& aStart, const nsReadingIterator<PRUnichar>& aEnd )
|
||||
{
|
||||
return Distance_Impl(aStart, aEnd);
|
||||
}
|
||||
|
||||
NS_COM
|
||||
size_t
|
||||
Distance( const nsReadingIterator<char>& aStart, const nsReadingIterator<char>& aEnd )
|
||||
{
|
||||
return Distance_Impl(aStart, aEnd);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -35,6 +35,11 @@
|
||||
#include "nsAWritableString.h"
|
||||
#endif
|
||||
|
||||
NS_COM size_t Distance( const nsReadingIterator<PRUnichar>&, const nsReadingIterator<PRUnichar>& );
|
||||
NS_COM size_t Distance( const nsReadingIterator<char>&, const nsReadingIterator<char>& );
|
||||
|
||||
|
||||
|
||||
NS_COM void CopyUCS2toASCII( const nsAReadableString& aSource, nsAWritableCString& aDest );
|
||||
NS_COM void CopyASCIItoUCS2( const nsAReadableCString& aSource, nsAWritableString& aDest );
|
||||
|
||||
|
@ -1184,6 +1184,15 @@ class nsPromiseSubstring
|
||||
// nothing else to do here
|
||||
}
|
||||
|
||||
nsPromiseSubstring( const nsReadingIterator<CharT>& aStart, const nsReadingIterator<CharT>& aEnd )
|
||||
: mString(*aStart.mOwningString)
|
||||
{
|
||||
nsReadingIterator<CharT> zeroPoint;
|
||||
mOwningString.BeginReading(zeroPoint);
|
||||
mStartPos = Distance(zeroPoint, aStart);
|
||||
mLength = Distance(aStart, aEnd);
|
||||
}
|
||||
|
||||
// nsPromiseSubstring( const nsPromiseSubstring<CharT>& ); // auto-generated copy-constructor should be OK
|
||||
// ~nsPromiseSubstring(); // auto-generated destructor OK
|
||||
|
||||
@ -1278,6 +1287,13 @@ Substring( const basic_nsAReadableString<CharT>& aString, PRUint32 aStartPos, PR
|
||||
return nsPromiseSubstring<CharT>(aString, aStartPos, aSubstringLength);
|
||||
}
|
||||
|
||||
template <class CharT>
|
||||
nsPromiseSubstring<CharT>
|
||||
Substring( const nsReadingIterator<CharT>& aStart, const nsReadingIterator<CharT>& aEnd )
|
||||
{
|
||||
return nsPromiseSubstring<Chart>(aStart, aEnd);
|
||||
}
|
||||
|
||||
template <class CharT>
|
||||
int
|
||||
Compare( const basic_nsAReadableString<CharT>& lhs, const basic_nsAReadableString<CharT>& rhs )
|
||||
|
@ -35,6 +35,11 @@
|
||||
#include "nsAWritableString.h"
|
||||
#endif
|
||||
|
||||
NS_COM size_t Distance( const nsReadingIterator<PRUnichar>&, const nsReadingIterator<PRUnichar>& );
|
||||
NS_COM size_t Distance( const nsReadingIterator<char>&, const nsReadingIterator<char>& );
|
||||
|
||||
|
||||
|
||||
NS_COM void CopyUCS2toASCII( const nsAReadableString& aSource, nsAWritableCString& aDest );
|
||||
NS_COM void CopyASCIItoUCS2( const nsAReadableCString& aSource, nsAWritableString& aDest );
|
||||
|
||||
|
@ -27,6 +27,45 @@
|
||||
#include "nsCRT.h"
|
||||
|
||||
|
||||
template <class CharT> class CalculateLength
|
||||
{
|
||||
public:
|
||||
typedef CharT value_type;
|
||||
|
||||
CalculateLength() : mDistance(0) { }
|
||||
size_t GetDistance() const { return mDistance; }
|
||||
|
||||
PRUint32 write( const CharT*, PRUint32 N )
|
||||
{ mDistance += N; return N; }
|
||||
private:
|
||||
size_t mDistance;
|
||||
};
|
||||
|
||||
template <class CharT>
|
||||
inline
|
||||
size_t
|
||||
Distance_Impl( const nsReadingIterator<CharT>& aStart,
|
||||
const nsReadingIterator<CharT>& aEnd )
|
||||
{
|
||||
CalculateLength<CharT> sink;
|
||||
nsReadingIterator<CharT> fromBegin(aStart);
|
||||
copy_string(fromBegin, aEnd, sink);
|
||||
return sink.GetDistance();
|
||||
}
|
||||
|
||||
NS_COM
|
||||
size_t
|
||||
Distance( const nsReadingIterator<PRUnichar>& aStart, const nsReadingIterator<PRUnichar>& aEnd )
|
||||
{
|
||||
return Distance_Impl(aStart, aEnd);
|
||||
}
|
||||
|
||||
NS_COM
|
||||
size_t
|
||||
Distance( const nsReadingIterator<char>& aStart, const nsReadingIterator<char>& aEnd )
|
||||
{
|
||||
return Distance_Impl(aStart, aEnd);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user