From cd82ef1d9e3a065cc7d51909348aa04b487ad5c8 Mon Sep 17 00:00:00 2001 From: "alecf%netscape.com" Date: Tue, 9 Oct 2001 23:41:57 +0000 Subject: [PATCH] add 2nd operator() to prepare for future FindInReadable work in bug 100214 not part of build --- intl/unicharutil/util/nsUnicharUtils.cpp | 40 +++++++++--------------- intl/unicharutil/util/nsUnicharUtils.h | 1 + 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/intl/unicharutil/util/nsUnicharUtils.cpp b/intl/unicharutil/util/nsUnicharUtils.cpp index 1c17048f817d..930f339c6ff8 100644 --- a/intl/unicharutil/util/nsUnicharUtils.cpp +++ b/intl/unicharutil/util/nsUnicharUtils.cpp @@ -83,34 +83,12 @@ ToUpperCase( nsAString& aString ) copy_string(aString.BeginWriting(fromBegin), aString.EndWriting(fromEnd), converter); } - -class CaseInsensitivePRUnicharComparator - { - public: - PRBool operator()( PRUnichar lhs, PRUnichar rhs ) const { - NS_InitCaseConversion(); - - PRUnichar lhsUpper; PRUnichar rhsUpper; - gCaseConv->ToUpper(lhs, &lhsUpper); - gCaseConv->ToUpper(rhs, &rhsUpper); - return lhsUpper = rhsUpper; - } - }; - PRBool CaseInsensitiveFindInReadable( const nsAString& aPattern, nsAString::const_iterator& aSearchStart, nsAString::const_iterator& aSearchEnd ) - { - nsAutoString lowerPattern(aPattern); - ToLowerCase(lowerPattern); +{ + return FindInReadable(aPattern, aStart, aEnd, nsCaseInsensitiveStringComparator()); +} - nsAutoString lowerString; - CopyUnicodeTo(aSearchStart, aSearchEnd, lowerString); - - nsAString::const_iterator match_start, match_end; - return FindInReadable(lowerPattern, - lowerString.BeginReading(match_start), - lowerString.EndReading(match_end)); - } int nsCaseInsensitiveStringComparator::operator()( const PRUnichar* lhs, const PRUnichar* rhs, PRUint32 aLength ) const @@ -121,4 +99,16 @@ nsCaseInsensitiveStringComparator::operator()( const PRUnichar* lhs, const PRUni return result; } +PRBool +nsCaseInsensitiveStringComparator::operator()( PRUnichar lhs, PRUnichar rhs ) const + { + if (lhs == rhs) return PR_TRUE; + NS_InitCaseConversion(); + + gCaseConv->ToUpper(lhs, &lhs); + gCaseConv->ToUpper(rhs, &rhs); + + return lhs == rhs; + } + #endif diff --git a/intl/unicharutil/util/nsUnicharUtils.h b/intl/unicharutil/util/nsUnicharUtils.h index 2f41ae415c06..02836315f17b 100644 --- a/intl/unicharutil/util/nsUnicharUtils.h +++ b/intl/unicharutil/util/nsUnicharUtils.h @@ -34,6 +34,7 @@ class nsCaseInsensitiveStringComparator { public: virtual int operator()( const PRUnichar*, const PRUnichar*, PRUint32 aLength ) const; + virtual int operator()( PRUnichar, PRUnichar ) const; }; #endif