PageRenderTime 102ms CodeModel.GetById 60ms app.highlight 6ms RepoModel.GetById 34ms app.codeStats 0ms

/gecko_api/include/nsUnicharUtils.h

http://firefox-mac-pdf.googlecode.com/
C++ Header | 108 lines | 52 code | 16 blank | 40 comment | 9 complexity | 611f88b00864fa90a49ab7cbe8f5e0b3 MD5 | raw file
  1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2/* ***** BEGIN LICENSE BLOCK *****
  3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4 *
  5 * The contents of this file are subject to the Mozilla Public License Version
  6 * 1.1 (the "License"); you may not use this file except in compliance with
  7 * the License. You may obtain a copy of the License at
  8 * http://www.mozilla.org/MPL/
  9 *
 10 * Software distributed under the License is distributed on an "AS IS" basis,
 11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 12 * for the specific language governing rights and limitations under the
 13 * License.
 14 *
 15 * The Original Code is Unicode case conversion helpers.
 16 *
 17 * The Initial Developer of the Original Code is
 18 * Netscape Communications Corp..
 19 * Portions created by the Initial Developer are Copyright (C) 2002
 20 * the Initial Developer. All Rights Reserved.
 21 *
 22 * Contributor(s):
 23 *   Alec Flett <alecf@netscape.com>
 24 *   Benjamin Smedberg <benjamin@smedbergs.us>
 25 *
 26 * Alternatively, the contents of this file may be used under the terms of
 27 * either the GNU General Public License Version 2 or later (the "GPL"), or
 28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 29 * in which case the provisions of the GPL or the LGPL are applicable instead
 30 * of those above. If you wish to allow use of your version of this file only
 31 * under the terms of either the GPL or the LGPL, and not to allow others to
 32 * use your version of this file under the terms of the MPL, indicate your
 33 * decision by deleting the provisions above and replace them with the notice
 34 * and other provisions required by the GPL or the LGPL. If you do not delete
 35 * the provisions above, a recipient may use your version of this file under
 36 * the terms of any one of the MPL, the GPL or the LGPL.
 37 *
 38 * ***** END LICENSE BLOCK ***** */
 39
 40#ifndef nsUnicharUtils_h__
 41#define nsUnicharUtils_h__
 42
 43#include "nsStringGlue.h"
 44
 45/* (0x3131u <= (u) && (u) <= 0x318eu) => Hangul Compatibility Jamo */
 46/* (0xac00u <= (u) && (u) <= 0xd7a3u) => Hangul Syllables          */
 47#define IS_CJ_CHAR(u) \
 48  ((0x2e80u <= (u) && (u) <= 0x312fu) || \
 49   (0x3190u <= (u) && (u) <= 0xabffu) || \
 50   (0xf900u <= (u) && (u) <= 0xfaffu) || \
 51   (0xff00u <= (u) && (u) <= 0xffefu) )
 52
 53void ToLowerCase(nsAString&);
 54void ToUpperCase(nsAString&);
 55
 56void ToLowerCase(const nsAString& aSource, nsAString& aDest);
 57void ToUpperCase(const nsAString& aSource, nsAString& aDest);
 58
 59PRUnichar ToUpperCase(PRUnichar);
 60PRUnichar ToLowerCase(PRUnichar);
 61
 62inline PRBool IsUpperCase(PRUnichar c) {
 63  return ToLowerCase(c) != c;
 64}
 65
 66inline PRBool IsLowerCase(PRUnichar c) {
 67  return ToUpperCase(c) != c;
 68}
 69
 70#ifdef MOZILLA_INTERNAL_API
 71
 72class nsCaseInsensitiveStringComparator : public nsStringComparator
 73{
 74public:
 75  virtual int operator() (const PRUnichar*,
 76                          const PRUnichar*,
 77                          PRUint32 aLength) const;
 78  virtual int operator() (PRUnichar,
 79                          PRUnichar) const;
 80};
 81
 82inline PRBool
 83CaseInsensitiveFindInReadable(const nsAString& aPattern,
 84                              nsAString::const_iterator& aSearchStart,
 85                              nsAString::const_iterator& aSearchEnd)
 86{
 87  return FindInReadable(aPattern, aSearchStart, aSearchEnd,
 88                        nsCaseInsensitiveStringComparator());
 89}
 90
 91inline PRBool
 92CaseInsensitiveFindInReadable(const nsAString& aPattern,
 93                              const nsAString& aHay)
 94{
 95  nsAString::const_iterator searchBegin, searchEnd;
 96  return FindInReadable(aPattern, aHay.BeginReading(searchBegin),
 97                        aHay.EndReading(searchEnd),
 98                        nsCaseInsensitiveStringComparator());
 99}
100
101#else // MOZILLA_INTERNAL_API
102
103NS_HIDDEN_(PRInt32)
104CaseInsensitiveCompare(const PRUnichar *a, const PRUnichar *b, PRUint32 len);
105
106#endif // MOZILLA_INTERNAL_API
107
108#endif  /* nsUnicharUtils_h__ */