PageRenderTime 29ms CodeModel.GetById 16ms RepoModel.GetById 0ms 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. #ifndef nsUnicharUtils_h__
  40. #define nsUnicharUtils_h__
  41. #include "nsStringGlue.h"
  42. /* (0x3131u <= (u) && (u) <= 0x318eu) => Hangul Compatibility Jamo */
  43. /* (0xac00u <= (u) && (u) <= 0xd7a3u) => Hangul Syllables */
  44. #define IS_CJ_CHAR(u) \
  45. ((0x2e80u <= (u) && (u) <= 0x312fu) || \
  46. (0x3190u <= (u) && (u) <= 0xabffu) || \
  47. (0xf900u <= (u) && (u) <= 0xfaffu) || \
  48. (0xff00u <= (u) && (u) <= 0xffefu) )
  49. void ToLowerCase(nsAString&);
  50. void ToUpperCase(nsAString&);
  51. void ToLowerCase(const nsAString& aSource, nsAString& aDest);
  52. void ToUpperCase(const nsAString& aSource, nsAString& aDest);
  53. PRUnichar ToUpperCase(PRUnichar);
  54. PRUnichar ToLowerCase(PRUnichar);
  55. inline PRBool IsUpperCase(PRUnichar c) {
  56. return ToLowerCase(c) != c;
  57. }
  58. inline PRBool IsLowerCase(PRUnichar c) {
  59. return ToUpperCase(c) != c;
  60. }
  61. #ifdef MOZILLA_INTERNAL_API
  62. class nsCaseInsensitiveStringComparator : public nsStringComparator
  63. {
  64. public:
  65. virtual int operator() (const PRUnichar*,
  66. const PRUnichar*,
  67. PRUint32 aLength) const;
  68. virtual int operator() (PRUnichar,
  69. PRUnichar) const;
  70. };
  71. inline PRBool
  72. CaseInsensitiveFindInReadable(const nsAString& aPattern,
  73. nsAString::const_iterator& aSearchStart,
  74. nsAString::const_iterator& aSearchEnd)
  75. {
  76. return FindInReadable(aPattern, aSearchStart, aSearchEnd,
  77. nsCaseInsensitiveStringComparator());
  78. }
  79. inline PRBool
  80. CaseInsensitiveFindInReadable(const nsAString& aPattern,
  81. const nsAString& aHay)
  82. {
  83. nsAString::const_iterator searchBegin, searchEnd;
  84. return FindInReadable(aPattern, aHay.BeginReading(searchBegin),
  85. aHay.EndReading(searchEnd),
  86. nsCaseInsensitiveStringComparator());
  87. }
  88. #else // MOZILLA_INTERNAL_API
  89. NS_HIDDEN_(PRInt32)
  90. CaseInsensitiveCompare(const PRUnichar *a, const PRUnichar *b, PRUint32 len);
  91. #endif // MOZILLA_INTERNAL_API
  92. #endif /* nsUnicharUtils_h__ */