2001-09-27 00:53:57 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Alec Flett <alecf@netscape.com>
|
|
|
|
*/
|
|
|
|
#include "nsUnicharUtils.h"
|
2001-10-03 05:55:09 +04:00
|
|
|
#include "nsReadableUtils.h"
|
2001-09-27 00:53:57 +04:00
|
|
|
#include "nsUnicharUtilCIID.h"
|
|
|
|
#include "nsICaseConversion.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
|
|
|
|
// global cache of the case conversion service
|
|
|
|
static nsICaseConversion *gCaseConv = nsnull;
|
|
|
|
static NS_DEFINE_CID(kUnicharUtilCID, NS_UNICHARUTIL_CID);
|
|
|
|
|
2001-10-03 05:55:09 +04:00
|
|
|
static nsresult NS_InitCaseConversion() {
|
2001-09-27 00:53:57 +04:00
|
|
|
if (gCaseConv) return NS_OK;
|
|
|
|
|
|
|
|
return nsServiceManager::GetService(kUnicharUtilCID,
|
|
|
|
NS_GET_IID(nsICaseConversion),
|
|
|
|
(nsISupports**)&gCaseConv);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-10-09 02:16:22 +04:00
|
|
|
// to be turned on for bug 100214
|
|
|
|
#if 0
|
2001-09-27 00:53:57 +04:00
|
|
|
class ConvertToLowerCase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef PRUnichar value_type;
|
|
|
|
|
|
|
|
PRUint32 write( const PRUnichar* aSource, PRUint32 aSourceLength)
|
|
|
|
{
|
2001-10-03 05:55:09 +04:00
|
|
|
NS_InitCaseConversion();
|
2001-09-27 00:53:57 +04:00
|
|
|
gCaseConv->ToLower(aSource, NS_CONST_CAST(PRUnichar*,aSource), aSourceLength);
|
2001-10-03 05:55:09 +04:00
|
|
|
return aSourceLength;
|
2001-09-27 00:53:57 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
ToLowerCase( nsAString& aString)
|
|
|
|
{
|
|
|
|
nsAString::iterator fromBegin, fromEnd;
|
|
|
|
ConvertToLowerCase converter;
|
|
|
|
copy_string(aString.BeginWriting(fromBegin), aString.EndWriting(fromEnd), converter);
|
|
|
|
}
|
|
|
|
|
|
|
|
class ConvertToUpperCase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef PRUnichar value_type;
|
|
|
|
|
|
|
|
PRUint32 write( const PRUnichar* aSource, PRUint32 aSourceLength)
|
|
|
|
{
|
2001-10-03 05:55:09 +04:00
|
|
|
NS_InitCaseConversion();
|
2001-09-27 00:53:57 +04:00
|
|
|
gCaseConv->ToUpper(aSource, NS_CONST_CAST(PRUnichar*,aSource), aSourceLength);
|
2001-10-12 04:01:19 +04:00
|
|
|
return aSourceLength;
|
2001-09-27 00:53:57 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
ToUpperCase( nsAString& aString )
|
|
|
|
{
|
|
|
|
nsAString::iterator fromBegin, fromEnd;
|
|
|
|
ConvertToUpperCase converter;
|
|
|
|
copy_string(aString.BeginWriting(fromBegin), aString.EndWriting(fromEnd), converter);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2001-10-03 05:55:09 +04:00
|
|
|
CaseInsensitiveFindInReadable( const nsAString& aPattern, nsAString::const_iterator& aSearchStart, nsAString::const_iterator& aSearchEnd )
|
2001-10-10 03:41:57 +04:00
|
|
|
{
|
2001-10-10 03:43:25 +04:00
|
|
|
return FindInReadable(aPattern, aSearchStart, aSearchEnd, nsCaseInsensitiveStringComparator());
|
2001-10-10 03:41:57 +04:00
|
|
|
}
|
2001-10-03 05:55:09 +04:00
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
nsCaseInsensitiveStringComparator::operator()( const PRUnichar* lhs, const PRUnichar* rhs, PRUint32 aLength ) const
|
2001-09-27 00:53:57 +04:00
|
|
|
{
|
2001-10-09 01:59:13 +04:00
|
|
|
NS_InitCaseConversion();
|
|
|
|
PRInt32 result;
|
2001-10-12 04:01:19 +04:00
|
|
|
gCaseConv->CaseInsensitiveCompare(lhs, rhs, aLength, &result);
|
2001-10-09 01:59:13 +04:00
|
|
|
return result;
|
2001-09-27 00:53:57 +04:00
|
|
|
}
|
|
|
|
|
2001-10-10 03:41:57 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2001-10-09 02:16:22 +04:00
|
|
|
#endif
|