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.

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

mercurial