Bug #39686. Made an |NS_COUNT|. Put it in the new file "nsAlgorithm.h", to which I also moved |NS_MIN| and |NS_MAX| from "nscore.h", and |copy_string| and |copy_string_backward| from "nsAReadableString.h". Also fixed non-standard include-guards. r={sford, jag}

This commit is contained in:
scc%mozilla.org 2000-05-20 20:43:26 +00:00
Родитель 26693d73dc
Коммит 09ea95c306
17 изменённых файлов: 93 добавлений и 211 удалений

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

@ -23,18 +23,23 @@
* Contributor(s):
*/
#ifndef _nsAReadableString_h__
#define _nsAReadableString_h__
#ifndef nsAReadableString_h___
#define nsAReadableString_h___
#ifndef nscore_h___
#include "nscore.h"
// for |PRUnichar|
#endif
#ifndef _nsCharTraits_h__
#ifndef nsCharTraits_h___
#include "nsCharTraits.h"
#endif
#ifndef nsAlgorithm_h___
#include "nsAlgorithm.h"
// for |NS_MIN|, |NS_MAX|, and |NS_COUNT|...
#endif
/*
This file defines the abstract interfaces |nsAReadableString| and
|nsAReadableCString| (the 'A' is for 'abstract', as opposed to the 'I' in
@ -558,7 +563,7 @@ PRUint32
basic_nsAReadableString<CharT>::CountChar( CharT c ) const
{
#if 0
return PRUint32(count(BeginReading(), EndReading(), c));
return PRUint32(NS_COUNT(BeginReading(), EndReading(), c));
#else
PRUint32 result = 0;
PRUint32 lengthToExamine = Length();
@ -567,7 +572,7 @@ basic_nsAReadableString<CharT>::CountChar( CharT c ) const
for (;;)
{
PRInt32 lengthToExamineInThisFragment = iter.size_forward();
result += PRUint32(count(iter.operator->(), iter.operator->()+lengthToExamineInThisFragment, c));
result += PRUint32(NS_COUNT(iter.operator->(), iter.operator->()+lengthToExamineInThisFragment, c));
if ( !(lengthToExamine -= lengthToExamineInThisFragment) )
return result;
iter += lengthToExamineInThisFragment;
@ -1075,49 +1080,6 @@ SameImplementation( const basic_nsAReadableString<CharT>& lhs, const basic_nsARe
return imp_tag && (imp_tag==rhs.Implementation());
}
template <class InputIterator, class OutputIterator>
OutputIterator
copy_string( InputIterator first, InputIterator last, OutputIterator result )
{
typedef nsCharSourceTraits<InputIterator> source_traits;
typedef nsCharSinkTraits<OutputIterator> sink_traits;
while ( first != last )
{
PRInt32 count_copied = PRInt32(sink_traits::write(result, source_traits::read(first), source_traits::readable_distance(first, last)));
NS_ASSERTION(count_copied > 0, "|copy_string| will never terminate");
first += count_copied;
}
return result;
}
template <class InputIterator, class OutputIterator>
OutputIterator
copy_string_backward( InputIterator first, InputIterator last, OutputIterator result )
{
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->()));
NS_ASSERTION(lengthToCopy, "|copy_string_backward| will never terminate");
#ifdef _MSC_VER
// XXX Visual C++ can't stomach 'typename' where it rightfully should
nsCharTraits<OutputIterator::value_type>::move(result.operator->()-lengthToCopy, last.operator->()-lengthToCopy, lengthToCopy);
#else
nsCharTraits<typename OutputIterator::value_type>::move(result.operator->()-lengthToCopy, last.operator->()-lengthToCopy, lengthToCopy);
#endif
last -= PRInt32(lengthToCopy);
result -= PRInt32(lengthToCopy);
}
return result;
}
template <class CharT>
nsPromiseSubstring<CharT>
Substring( const basic_nsAReadableString<CharT>& aString, PRUint32 aStartPos, PRUint32 aSubstringLength )
@ -1275,4 +1237,4 @@ typedef basic_nsLiteralChar<char> nsLiteralChar;
typedef basic_nsLiteralChar<PRUnichar> nsLiteralPRUnichar;
#endif // !defined(_nsAReadableString_h__)
#endif // !defined(nsAReadableString_h___)

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

@ -23,11 +23,13 @@
* Contributor(s):
*/
#ifndef _nsAWritableString_h__
#define _nsAWritableString_h__
#ifndef nsAWritableString_h___
#define nsAWritableString_h___
// See also...
#ifndef nsAReadableString_h___
#include "nsAReadableString.h"
#endif
template <class CharT>
@ -684,4 +686,4 @@ basic_nsAWritableString<CharT>::ReplaceFromPromise( PRUint32 cutStart, PRUint32
typedef basic_nsAWritableString<PRUnichar> nsAWritableString;
typedef basic_nsAWritableString<char> nsAWritableCString;
#endif // !defined(_nsAWritableString_h__)
#endif // !defined(nsAWritableString_h___)

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

@ -23,8 +23,8 @@
* Contributor(s):
*/
#ifndef _nsCharTraits_h__
#define _nsCharTraits_h__
#ifndef nsCharTraits_h___
#define nsCharTraits_h___
#include <ctype.h>
// for |EOF|, |WEOF|
@ -632,4 +632,4 @@ struct nsCharSinkTraits<PRUnichar*>
#endif
#endif // !defined(_nsCharTraits_h__)
#endif // !defined(nsCharTraits_h___)

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

@ -23,12 +23,14 @@
* Contributor(s):
*/
#ifndef _nsFragmentedString_h__
#define _nsFragmentedString_h__
#ifndef nsFragmentedString_h___
#define nsFragmentedString_h___
// WORK IN PROGRESS
#ifndef nsAWritableString_h___
#include "nsAWritableString.h"
#endif
template <class CharT>
class basic_nsFragmentedString
@ -41,4 +43,4 @@ class basic_nsFragmentedString
// ...
};
#endif // !defined(_nsFragmentedStrign_h__)
#endif // !defined(nsFragmentedString_h___)

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

@ -23,10 +23,12 @@
* Contributor(s):
*/
#ifndef _nsSharedString_h__
#define _nsSharedString_h__
#ifndef nsSharedString_h___
#define nsSharedString_h___
#ifndef nsAReadableString_h___
#include "nsAReadableString.h"
#endif
template <class CharT>
class basic_nsSharedString
@ -186,4 +188,4 @@ typedef basic_nsSharedStringPtr<PRUnichar> nsSharedStringPtr;
typedef basic_nsSharedStringPtr<char> nsSharedCStringPtr;
#endif // !defined(_nsSharedString_h__)
#endif // !defined(nsSharedString_h___)

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

@ -250,29 +250,4 @@ typedef PRUint16 PRUnichar;
the semantics. So if you want to dynamic_cast, then just use it
"straight", no macro. */
/* Because this may be included bogously a C file (or an extern "C"
block), we'll "extern C++" it. There's a bug filed against that
somewhere. */
#ifdef __cplusplus
extern "C++" {
template <class T>
inline
const T&
NS_MIN( const T& a, const T& b )
{
return b < a ? b : a;
}
template <class T>
inline
const T&
NS_MAX( const T& a, const T& b )
{
return a > b ? a : b;
}
}
#endif /* __cplusplus */
#endif /* nscore_h___ */

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

@ -23,18 +23,23 @@
* Contributor(s):
*/
#ifndef _nsAReadableString_h__
#define _nsAReadableString_h__
#ifndef nsAReadableString_h___
#define nsAReadableString_h___
#ifndef nscore_h___
#include "nscore.h"
// for |PRUnichar|
#endif
#ifndef _nsCharTraits_h__
#ifndef nsCharTraits_h___
#include "nsCharTraits.h"
#endif
#ifndef nsAlgorithm_h___
#include "nsAlgorithm.h"
// for |NS_MIN|, |NS_MAX|, and |NS_COUNT|...
#endif
/*
This file defines the abstract interfaces |nsAReadableString| and
|nsAReadableCString| (the 'A' is for 'abstract', as opposed to the 'I' in
@ -558,7 +563,7 @@ PRUint32
basic_nsAReadableString<CharT>::CountChar( CharT c ) const
{
#if 0
return PRUint32(count(BeginReading(), EndReading(), c));
return PRUint32(NS_COUNT(BeginReading(), EndReading(), c));
#else
PRUint32 result = 0;
PRUint32 lengthToExamine = Length();
@ -567,7 +572,7 @@ basic_nsAReadableString<CharT>::CountChar( CharT c ) const
for (;;)
{
PRInt32 lengthToExamineInThisFragment = iter.size_forward();
result += PRUint32(count(iter.operator->(), iter.operator->()+lengthToExamineInThisFragment, c));
result += PRUint32(NS_COUNT(iter.operator->(), iter.operator->()+lengthToExamineInThisFragment, c));
if ( !(lengthToExamine -= lengthToExamineInThisFragment) )
return result;
iter += lengthToExamineInThisFragment;
@ -1075,49 +1080,6 @@ SameImplementation( const basic_nsAReadableString<CharT>& lhs, const basic_nsARe
return imp_tag && (imp_tag==rhs.Implementation());
}
template <class InputIterator, class OutputIterator>
OutputIterator
copy_string( InputIterator first, InputIterator last, OutputIterator result )
{
typedef nsCharSourceTraits<InputIterator> source_traits;
typedef nsCharSinkTraits<OutputIterator> sink_traits;
while ( first != last )
{
PRInt32 count_copied = PRInt32(sink_traits::write(result, source_traits::read(first), source_traits::readable_distance(first, last)));
NS_ASSERTION(count_copied > 0, "|copy_string| will never terminate");
first += count_copied;
}
return result;
}
template <class InputIterator, class OutputIterator>
OutputIterator
copy_string_backward( InputIterator first, InputIterator last, OutputIterator result )
{
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->()));
NS_ASSERTION(lengthToCopy, "|copy_string_backward| will never terminate");
#ifdef _MSC_VER
// XXX Visual C++ can't stomach 'typename' where it rightfully should
nsCharTraits<OutputIterator::value_type>::move(result.operator->()-lengthToCopy, last.operator->()-lengthToCopy, lengthToCopy);
#else
nsCharTraits<typename OutputIterator::value_type>::move(result.operator->()-lengthToCopy, last.operator->()-lengthToCopy, lengthToCopy);
#endif
last -= PRInt32(lengthToCopy);
result -= PRInt32(lengthToCopy);
}
return result;
}
template <class CharT>
nsPromiseSubstring<CharT>
Substring( const basic_nsAReadableString<CharT>& aString, PRUint32 aStartPos, PRUint32 aSubstringLength )
@ -1275,4 +1237,4 @@ typedef basic_nsLiteralChar<char> nsLiteralChar;
typedef basic_nsLiteralChar<PRUnichar> nsLiteralPRUnichar;
#endif // !defined(_nsAReadableString_h__)
#endif // !defined(nsAReadableString_h___)

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

@ -23,11 +23,13 @@
* Contributor(s):
*/
#ifndef _nsAWritableString_h__
#define _nsAWritableString_h__
#ifndef nsAWritableString_h___
#define nsAWritableString_h___
// See also...
#ifndef nsAReadableString_h___
#include "nsAReadableString.h"
#endif
template <class CharT>
@ -684,4 +686,4 @@ basic_nsAWritableString<CharT>::ReplaceFromPromise( PRUint32 cutStart, PRUint32
typedef basic_nsAWritableString<PRUnichar> nsAWritableString;
typedef basic_nsAWritableString<char> nsAWritableCString;
#endif // !defined(_nsAWritableString_h__)
#endif // !defined(nsAWritableString_h___)

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

@ -23,8 +23,8 @@
* Contributor(s):
*/
#ifndef _nsCharTraits_h__
#define _nsCharTraits_h__
#ifndef nsCharTraits_h___
#define nsCharTraits_h___
#include <ctype.h>
// for |EOF|, |WEOF|
@ -632,4 +632,4 @@ struct nsCharSinkTraits<PRUnichar*>
#endif
#endif // !defined(_nsCharTraits_h__)
#endif // !defined(nsCharTraits_h___)

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

@ -23,12 +23,14 @@
* Contributor(s):
*/
#ifndef _nsFragmentedString_h__
#define _nsFragmentedString_h__
#ifndef nsFragmentedString_h___
#define nsFragmentedString_h___
// WORK IN PROGRESS
#ifndef nsAWritableString_h___
#include "nsAWritableString.h"
#endif
template <class CharT>
class basic_nsFragmentedString
@ -41,4 +43,4 @@ class basic_nsFragmentedString
// ...
};
#endif // !defined(_nsFragmentedStrign_h__)
#endif // !defined(nsFragmentedString_h___)

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

@ -23,10 +23,12 @@
* Contributor(s):
*/
#ifndef _nsSharedString_h__
#define _nsSharedString_h__
#ifndef nsSharedString_h___
#define nsSharedString_h___
#ifndef nsAReadableString_h___
#include "nsAReadableString.h"
#endif
template <class CharT>
class basic_nsSharedString
@ -186,4 +188,4 @@ typedef basic_nsSharedStringPtr<PRUnichar> nsSharedStringPtr;
typedef basic_nsSharedStringPtr<char> nsSharedCStringPtr;
#endif // !defined(_nsSharedString_h__)
#endif // !defined(nsSharedString_h___)

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

@ -23,18 +23,23 @@
* Contributor(s):
*/
#ifndef _nsAReadableString_h__
#define _nsAReadableString_h__
#ifndef nsAReadableString_h___
#define nsAReadableString_h___
#ifndef nscore_h___
#include "nscore.h"
// for |PRUnichar|
#endif
#ifndef _nsCharTraits_h__
#ifndef nsCharTraits_h___
#include "nsCharTraits.h"
#endif
#ifndef nsAlgorithm_h___
#include "nsAlgorithm.h"
// for |NS_MIN|, |NS_MAX|, and |NS_COUNT|...
#endif
/*
This file defines the abstract interfaces |nsAReadableString| and
|nsAReadableCString| (the 'A' is for 'abstract', as opposed to the 'I' in
@ -558,7 +563,7 @@ PRUint32
basic_nsAReadableString<CharT>::CountChar( CharT c ) const
{
#if 0
return PRUint32(count(BeginReading(), EndReading(), c));
return PRUint32(NS_COUNT(BeginReading(), EndReading(), c));
#else
PRUint32 result = 0;
PRUint32 lengthToExamine = Length();
@ -567,7 +572,7 @@ basic_nsAReadableString<CharT>::CountChar( CharT c ) const
for (;;)
{
PRInt32 lengthToExamineInThisFragment = iter.size_forward();
result += PRUint32(count(iter.operator->(), iter.operator->()+lengthToExamineInThisFragment, c));
result += PRUint32(NS_COUNT(iter.operator->(), iter.operator->()+lengthToExamineInThisFragment, c));
if ( !(lengthToExamine -= lengthToExamineInThisFragment) )
return result;
iter += lengthToExamineInThisFragment;
@ -1075,49 +1080,6 @@ SameImplementation( const basic_nsAReadableString<CharT>& lhs, const basic_nsARe
return imp_tag && (imp_tag==rhs.Implementation());
}
template <class InputIterator, class OutputIterator>
OutputIterator
copy_string( InputIterator first, InputIterator last, OutputIterator result )
{
typedef nsCharSourceTraits<InputIterator> source_traits;
typedef nsCharSinkTraits<OutputIterator> sink_traits;
while ( first != last )
{
PRInt32 count_copied = PRInt32(sink_traits::write(result, source_traits::read(first), source_traits::readable_distance(first, last)));
NS_ASSERTION(count_copied > 0, "|copy_string| will never terminate");
first += count_copied;
}
return result;
}
template <class InputIterator, class OutputIterator>
OutputIterator
copy_string_backward( InputIterator first, InputIterator last, OutputIterator result )
{
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->()));
NS_ASSERTION(lengthToCopy, "|copy_string_backward| will never terminate");
#ifdef _MSC_VER
// XXX Visual C++ can't stomach 'typename' where it rightfully should
nsCharTraits<OutputIterator::value_type>::move(result.operator->()-lengthToCopy, last.operator->()-lengthToCopy, lengthToCopy);
#else
nsCharTraits<typename OutputIterator::value_type>::move(result.operator->()-lengthToCopy, last.operator->()-lengthToCopy, lengthToCopy);
#endif
last -= PRInt32(lengthToCopy);
result -= PRInt32(lengthToCopy);
}
return result;
}
template <class CharT>
nsPromiseSubstring<CharT>
Substring( const basic_nsAReadableString<CharT>& aString, PRUint32 aStartPos, PRUint32 aSubstringLength )
@ -1275,4 +1237,4 @@ typedef basic_nsLiteralChar<char> nsLiteralChar;
typedef basic_nsLiteralChar<PRUnichar> nsLiteralPRUnichar;
#endif // !defined(_nsAReadableString_h__)
#endif // !defined(nsAReadableString_h___)

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

@ -23,11 +23,13 @@
* Contributor(s):
*/
#ifndef _nsAWritableString_h__
#define _nsAWritableString_h__
#ifndef nsAWritableString_h___
#define nsAWritableString_h___
// See also...
#ifndef nsAReadableString_h___
#include "nsAReadableString.h"
#endif
template <class CharT>
@ -684,4 +686,4 @@ basic_nsAWritableString<CharT>::ReplaceFromPromise( PRUint32 cutStart, PRUint32
typedef basic_nsAWritableString<PRUnichar> nsAWritableString;
typedef basic_nsAWritableString<char> nsAWritableCString;
#endif // !defined(_nsAWritableString_h__)
#endif // !defined(nsAWritableString_h___)

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

@ -23,8 +23,8 @@
* Contributor(s):
*/
#ifndef _nsCharTraits_h__
#define _nsCharTraits_h__
#ifndef nsCharTraits_h___
#define nsCharTraits_h___
#include <ctype.h>
// for |EOF|, |WEOF|
@ -632,4 +632,4 @@ struct nsCharSinkTraits<PRUnichar*>
#endif
#endif // !defined(_nsCharTraits_h__)
#endif // !defined(nsCharTraits_h___)

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

@ -23,12 +23,14 @@
* Contributor(s):
*/
#ifndef _nsFragmentedString_h__
#define _nsFragmentedString_h__
#ifndef nsFragmentedString_h___
#define nsFragmentedString_h___
// WORK IN PROGRESS
#ifndef nsAWritableString_h___
#include "nsAWritableString.h"
#endif
template <class CharT>
class basic_nsFragmentedString
@ -41,4 +43,4 @@ class basic_nsFragmentedString
// ...
};
#endif // !defined(_nsFragmentedStrign_h__)
#endif // !defined(nsFragmentedString_h___)

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

@ -23,10 +23,12 @@
* Contributor(s):
*/
#ifndef _nsSharedString_h__
#define _nsSharedString_h__
#ifndef nsSharedString_h___
#define nsSharedString_h___
#ifndef nsAReadableString_h___
#include "nsAReadableString.h"
#endif
template <class CharT>
class basic_nsSharedString
@ -186,4 +188,4 @@ typedef basic_nsSharedStringPtr<PRUnichar> nsSharedStringPtr;
typedef basic_nsSharedStringPtr<char> nsSharedCStringPtr;
#endif // !defined(_nsSharedString_h__)
#endif // !defined(nsSharedString_h___)

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

@ -23,11 +23,14 @@
* Contributor(s):
*/
#ifndef _nsStdStringWrapper_h__
#define _nsStdStringWrapper_h__
#ifndef nsStdStringWrapper_h___
#define nsStdStringWrapper_h___
#include <string>
#ifndef nsAWritableString_h___
#include "nsAWritableString.h"
#endif
template <class T>
@ -212,4 +215,4 @@ typedef basic_nsStdStringWrapper<PRUnichar> nsStdString;
typedef basic_nsStdStringWrapper<char> nsStdCString;
#endif // !defined(_basic_nsStdStringWrapper_h__)
#endif // !defined(nsStdStringWrapper_h___)