2008-10-01 04:50:42 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2002-05-09 00:48:26 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2001-09-27 00:53:57 +04:00
|
|
|
*
|
2002-05-09 00:48:26 +04:00
|
|
|
* The contents of this file are subject to the Mozilla 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/MPL/
|
2001-09-27 00:53:57 +04:00
|
|
|
*
|
2002-05-09 00:48:26 +04:00
|
|
|
* 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.
|
2001-09-27 00:53:57 +04:00
|
|
|
*
|
2002-05-09 00:48:26 +04:00
|
|
|
* The Original Code is Unicode case conversion helpers.
|
2001-09-27 00:53:57 +04:00
|
|
|
*
|
2002-05-09 00:48:26 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corp..
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2002
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2001-09-27 00:53:57 +04:00
|
|
|
*
|
2002-05-09 00:48:26 +04:00
|
|
|
* Contributor(s):
|
|
|
|
* Alec Flett <alecf@netscape.com>
|
2006-06-07 20:25:40 +04:00
|
|
|
* Benjamin Smedberg <benjamin@smedbergs.us>
|
2002-05-09 00:48:26 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2002-03-27 06:28:34 +03:00
|
|
|
#ifndef nsUnicharUtils_h__
|
|
|
|
#define nsUnicharUtils_h__
|
2005-11-15 21:17:22 +03:00
|
|
|
|
2006-06-07 20:25:40 +04:00
|
|
|
#include "nsStringGlue.h"
|
2005-11-15 21:17:22 +03:00
|
|
|
|
2006-09-27 21:44:27 +04:00
|
|
|
/* (0x3131u <= (u) && (u) <= 0x318eu) => Hangul Compatibility Jamo */
|
|
|
|
/* (0xac00u <= (u) && (u) <= 0xd7a3u) => Hangul Syllables */
|
|
|
|
#define IS_CJ_CHAR(u) \
|
|
|
|
((0x2e80u <= (u) && (u) <= 0x312fu) || \
|
|
|
|
(0x3190u <= (u) && (u) <= 0xabffu) || \
|
|
|
|
(0xf900u <= (u) && (u) <= 0xfaffu) || \
|
|
|
|
(0xff00u <= (u) && (u) <= 0xffefu) )
|
|
|
|
|
|
|
|
void ToLowerCase(nsAString&);
|
|
|
|
void ToUpperCase(nsAString&);
|
|
|
|
|
|
|
|
void ToLowerCase(const nsAString& aSource, nsAString& aDest);
|
|
|
|
void ToUpperCase(const nsAString& aSource, nsAString& aDest);
|
|
|
|
|
|
|
|
PRUnichar ToLowerCase(PRUnichar);
|
2010-07-29 23:22:16 +04:00
|
|
|
PRUnichar ToUpperCase(PRUnichar);
|
|
|
|
PRUnichar ToTitleCase(PRUnichar);
|
|
|
|
|
|
|
|
void ToLowerCase(const PRUnichar*, PRUnichar*, PRUint32);
|
|
|
|
void ToUpperCase(const PRUnichar*, PRUnichar*, PRUint32);
|
2001-12-23 05:56:41 +03:00
|
|
|
|
2006-09-27 21:44:27 +04:00
|
|
|
inline PRBool IsUpperCase(PRUnichar c) {
|
|
|
|
return ToLowerCase(c) != c;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline PRBool IsLowerCase(PRUnichar c) {
|
|
|
|
return ToUpperCase(c) != c;
|
|
|
|
}
|
2001-09-27 00:53:57 +04:00
|
|
|
|
2006-06-07 20:25:40 +04:00
|
|
|
#ifdef MOZILLA_INTERNAL_API
|
2006-09-27 21:44:27 +04:00
|
|
|
|
|
|
|
class nsCaseInsensitiveStringComparator : public nsStringComparator
|
|
|
|
{
|
|
|
|
public:
|
2010-07-29 23:22:16 +04:00
|
|
|
virtual PRInt32 operator() (const PRUnichar*,
|
|
|
|
const PRUnichar*,
|
2010-09-01 05:03:40 +04:00
|
|
|
PRUint32,
|
|
|
|
PRUint32) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
class nsCaseInsensitiveUTF8StringComparator : public nsCStringComparator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual PRInt32 operator() (const char*,
|
|
|
|
const char*,
|
|
|
|
PRUint32,
|
|
|
|
PRUint32) const;
|
2006-09-27 21:44:27 +04:00
|
|
|
};
|
|
|
|
|
2008-10-01 04:50:42 +04:00
|
|
|
class nsCaseInsensitiveStringArrayComparator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
template<class A, class B>
|
|
|
|
PRBool Equals(const A& a, const B& b) const {
|
|
|
|
return a.Equals(b, nsCaseInsensitiveStringComparator());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-08-03 02:19:04 +04:00
|
|
|
class nsASCIICaseInsensitiveStringComparator : public nsStringComparator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual int operator() (const PRUnichar*,
|
|
|
|
const PRUnichar*,
|
2010-09-01 05:03:40 +04:00
|
|
|
PRUint32,
|
|
|
|
PRUint32) const;
|
2010-08-03 02:19:04 +04:00
|
|
|
};
|
|
|
|
|
2006-09-27 21:44:27 +04:00
|
|
|
inline PRBool
|
|
|
|
CaseInsensitiveFindInReadable(const nsAString& aPattern,
|
|
|
|
nsAString::const_iterator& aSearchStart,
|
|
|
|
nsAString::const_iterator& aSearchEnd)
|
|
|
|
{
|
2005-02-24 18:50:57 +03:00
|
|
|
return FindInReadable(aPattern, aSearchStart, aSearchEnd,
|
|
|
|
nsCaseInsensitiveStringComparator());
|
|
|
|
}
|
|
|
|
|
2006-09-27 21:44:27 +04:00
|
|
|
inline PRBool
|
|
|
|
CaseInsensitiveFindInReadable(const nsAString& aPattern,
|
|
|
|
const nsAString& aHay)
|
|
|
|
{
|
2005-02-24 18:50:57 +03:00
|
|
|
nsAString::const_iterator searchBegin, searchEnd;
|
2006-09-27 21:44:27 +04:00
|
|
|
return FindInReadable(aPattern, aHay.BeginReading(searchBegin),
|
2005-02-24 18:50:57 +03:00
|
|
|
aHay.EndReading(searchEnd),
|
|
|
|
nsCaseInsensitiveStringComparator());
|
|
|
|
}
|
2001-10-20 02:51:11 +04:00
|
|
|
|
2010-07-29 23:22:16 +04:00
|
|
|
#endif // MOZILLA_INTERNAL_API
|
2010-07-04 17:27:16 +04:00
|
|
|
|
2010-07-29 23:22:16 +04:00
|
|
|
PRInt32
|
2010-07-04 17:27:16 +04:00
|
|
|
CaseInsensitiveCompare(const PRUnichar *a, const PRUnichar *b, PRUint32 len);
|
|
|
|
|
2010-09-01 05:03:40 +04:00
|
|
|
PRInt32
|
|
|
|
CaseInsensitiveCompare(const char* aLeft, const char* aRight,
|
|
|
|
PRUint32 aLeftBytes, PRUint32 aRightBytes);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function determines whether the UTF-8 sequence pointed to by aLeft is
|
|
|
|
* case-insensitively-equal to the UTF-8 sequence pointed to by aRight.
|
|
|
|
*
|
|
|
|
* aLeftEnd marks the first memory location past aLeft that is not part of
|
|
|
|
* aLeft; aRightEnd similarly marks the end of aRight.
|
|
|
|
*
|
|
|
|
* The function assumes that aLeft < aLeftEnd and aRight < aRightEnd.
|
|
|
|
*
|
|
|
|
* The function stores the addresses of the next characters in the sequence
|
|
|
|
* into aLeftNext and aRightNext. It's up to the caller to make sure that the
|
|
|
|
* returned pointers are valid -- i.e. the function may return aLeftNext >=
|
|
|
|
* aLeftEnd or aRightNext >= aRightEnd.
|
|
|
|
*
|
|
|
|
* If the function encounters invalid text, it sets aErr to true and returns
|
|
|
|
* false, possibly leaving aLeftNext and aRightNext uninitialized. If the
|
|
|
|
* function returns true, aErr is guaranteed to be false and both aLeftNext and
|
|
|
|
* aRightNext are guaranteed to be initialized.
|
|
|
|
*/
|
|
|
|
PRBool
|
|
|
|
CaseInsensitiveUTF8CharsEqual(const char* aLeft, const char* aRight,
|
|
|
|
const char* aLeftEnd, const char* aRightEnd,
|
|
|
|
const char** aLeftNext, const char** aRightNext,
|
|
|
|
PRBool* aErr);
|
|
|
|
|
2002-03-27 06:28:34 +03:00
|
|
|
#endif /* nsUnicharUtils_h__ */
|