intl/unicharutil/util/nsUnicharUtils.h

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef nsUnicharUtils_h__
michael@0 7 #define nsUnicharUtils_h__
michael@0 8
michael@0 9 #include "nsStringGlue.h"
michael@0 10
michael@0 11 /* (0x3131u <= (u) && (u) <= 0x318eu) => Hangul Compatibility Jamo */
michael@0 12 /* (0xac00u <= (u) && (u) <= 0xd7a3u) => Hangul Syllables */
michael@0 13 #define IS_CJ_CHAR(u) \
michael@0 14 ((0x2e80u <= (u) && (u) <= 0x312fu) || \
michael@0 15 (0x3190u <= (u) && (u) <= 0xabffu) || \
michael@0 16 (0xf900u <= (u) && (u) <= 0xfaffu) || \
michael@0 17 (0xff00u <= (u) && (u) <= 0xffefu) )
michael@0 18
michael@0 19 void ToLowerCase(nsAString&);
michael@0 20 void ToUpperCase(nsAString&);
michael@0 21
michael@0 22 void ToLowerCase(const nsAString& aSource, nsAString& aDest);
michael@0 23 void ToUpperCase(const nsAString& aSource, nsAString& aDest);
michael@0 24
michael@0 25 uint32_t ToLowerCase(uint32_t);
michael@0 26 uint32_t ToUpperCase(uint32_t);
michael@0 27 uint32_t ToTitleCase(uint32_t);
michael@0 28
michael@0 29 void ToLowerCase(const char16_t*, char16_t*, uint32_t);
michael@0 30 void ToUpperCase(const char16_t*, char16_t*, uint32_t);
michael@0 31
michael@0 32 inline bool IsUpperCase(uint32_t c) {
michael@0 33 return ToLowerCase(c) != c;
michael@0 34 }
michael@0 35
michael@0 36 inline bool IsLowerCase(uint32_t c) {
michael@0 37 return ToUpperCase(c) != c;
michael@0 38 }
michael@0 39
michael@0 40 #ifdef MOZILLA_INTERNAL_API
michael@0 41
michael@0 42 class nsCaseInsensitiveStringComparator : public nsStringComparator
michael@0 43 {
michael@0 44 public:
michael@0 45 virtual int32_t operator() (const char16_t*,
michael@0 46 const char16_t*,
michael@0 47 uint32_t,
michael@0 48 uint32_t) const;
michael@0 49 };
michael@0 50
michael@0 51 class nsCaseInsensitiveUTF8StringComparator : public nsCStringComparator
michael@0 52 {
michael@0 53 public:
michael@0 54 virtual int32_t operator() (const char*,
michael@0 55 const char*,
michael@0 56 uint32_t,
michael@0 57 uint32_t) const;
michael@0 58 };
michael@0 59
michael@0 60 class nsCaseInsensitiveStringArrayComparator
michael@0 61 {
michael@0 62 public:
michael@0 63 template<class A, class B>
michael@0 64 bool Equals(const A& a, const B& b) const {
michael@0 65 return a.Equals(b, nsCaseInsensitiveStringComparator());
michael@0 66 }
michael@0 67 };
michael@0 68
michael@0 69 class nsASCIICaseInsensitiveStringComparator : public nsStringComparator
michael@0 70 {
michael@0 71 public:
michael@0 72 nsASCIICaseInsensitiveStringComparator() {}
michael@0 73 virtual int operator() (const char16_t*,
michael@0 74 const char16_t*,
michael@0 75 uint32_t,
michael@0 76 uint32_t) const;
michael@0 77 };
michael@0 78
michael@0 79 inline bool
michael@0 80 CaseInsensitiveFindInReadable(const nsAString& aPattern,
michael@0 81 nsAString::const_iterator& aSearchStart,
michael@0 82 nsAString::const_iterator& aSearchEnd)
michael@0 83 {
michael@0 84 return FindInReadable(aPattern, aSearchStart, aSearchEnd,
michael@0 85 nsCaseInsensitiveStringComparator());
michael@0 86 }
michael@0 87
michael@0 88 inline bool
michael@0 89 CaseInsensitiveFindInReadable(const nsAString& aPattern,
michael@0 90 const nsAString& aHay)
michael@0 91 {
michael@0 92 nsAString::const_iterator searchBegin, searchEnd;
michael@0 93 return FindInReadable(aPattern, aHay.BeginReading(searchBegin),
michael@0 94 aHay.EndReading(searchEnd),
michael@0 95 nsCaseInsensitiveStringComparator());
michael@0 96 }
michael@0 97
michael@0 98 #endif // MOZILLA_INTERNAL_API
michael@0 99
michael@0 100 int32_t
michael@0 101 CaseInsensitiveCompare(const char16_t *a, const char16_t *b, uint32_t len);
michael@0 102
michael@0 103 int32_t
michael@0 104 CaseInsensitiveCompare(const char* aLeft, const char* aRight,
michael@0 105 uint32_t aLeftBytes, uint32_t aRightBytes);
michael@0 106
michael@0 107 /**
michael@0 108 * This function determines whether the UTF-8 sequence pointed to by aLeft is
michael@0 109 * case-insensitively-equal to the UTF-8 sequence pointed to by aRight.
michael@0 110 *
michael@0 111 * aLeftEnd marks the first memory location past aLeft that is not part of
michael@0 112 * aLeft; aRightEnd similarly marks the end of aRight.
michael@0 113 *
michael@0 114 * The function assumes that aLeft < aLeftEnd and aRight < aRightEnd.
michael@0 115 *
michael@0 116 * The function stores the addresses of the next characters in the sequence
michael@0 117 * into aLeftNext and aRightNext. It's up to the caller to make sure that the
michael@0 118 * returned pointers are valid -- i.e. the function may return aLeftNext >=
michael@0 119 * aLeftEnd or aRightNext >= aRightEnd.
michael@0 120 *
michael@0 121 * If the function encounters invalid text, it sets aErr to true and returns
michael@0 122 * false, possibly leaving aLeftNext and aRightNext uninitialized. If the
michael@0 123 * function returns true, aErr is guaranteed to be false and both aLeftNext and
michael@0 124 * aRightNext are guaranteed to be initialized.
michael@0 125 */
michael@0 126 bool
michael@0 127 CaseInsensitiveUTF8CharsEqual(const char* aLeft, const char* aRight,
michael@0 128 const char* aLeftEnd, const char* aRightEnd,
michael@0 129 const char** aLeftNext, const char** aRightNext,
michael@0 130 bool* aErr);
michael@0 131
michael@0 132 namespace mozilla {
michael@0 133
michael@0 134 /**
michael@0 135 * Hash a UTF8 string as though it were a UTF16 string.
michael@0 136 *
michael@0 137 * The value returned is the same as if we converted the string to UTF16 and
michael@0 138 * then ran HashString() on the result.
michael@0 139 *
michael@0 140 * The given |length| is in bytes.
michael@0 141 */
michael@0 142 uint32_t
michael@0 143 HashUTF8AsUTF16(const char* aUTF8, uint32_t aLength, bool* aErr);
michael@0 144
michael@0 145 } // namespace mozilla
michael@0 146
michael@0 147 #endif /* nsUnicharUtils_h__ */

mercurial