intl/unicharutil/util/nsUnicharUtils.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/unicharutil/util/nsUnicharUtils.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,147 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef nsUnicharUtils_h__
    1.10 +#define nsUnicharUtils_h__
    1.11 +
    1.12 +#include "nsStringGlue.h"
    1.13 +
    1.14 +/* (0x3131u <= (u) && (u) <= 0x318eu) => Hangul Compatibility Jamo */
    1.15 +/* (0xac00u <= (u) && (u) <= 0xd7a3u) => Hangul Syllables          */
    1.16 +#define IS_CJ_CHAR(u) \
    1.17 +  ((0x2e80u <= (u) && (u) <= 0x312fu) || \
    1.18 +   (0x3190u <= (u) && (u) <= 0xabffu) || \
    1.19 +   (0xf900u <= (u) && (u) <= 0xfaffu) || \
    1.20 +   (0xff00u <= (u) && (u) <= 0xffefu) )
    1.21 +
    1.22 +void ToLowerCase(nsAString&);
    1.23 +void ToUpperCase(nsAString&);
    1.24 +
    1.25 +void ToLowerCase(const nsAString& aSource, nsAString& aDest);
    1.26 +void ToUpperCase(const nsAString& aSource, nsAString& aDest);
    1.27 +
    1.28 +uint32_t ToLowerCase(uint32_t);
    1.29 +uint32_t ToUpperCase(uint32_t);
    1.30 +uint32_t ToTitleCase(uint32_t);
    1.31 +
    1.32 +void ToLowerCase(const char16_t*, char16_t*, uint32_t);
    1.33 +void ToUpperCase(const char16_t*, char16_t*, uint32_t);
    1.34 +
    1.35 +inline bool IsUpperCase(uint32_t c) {
    1.36 +  return ToLowerCase(c) != c;
    1.37 +}
    1.38 +
    1.39 +inline bool IsLowerCase(uint32_t c) {
    1.40 +  return ToUpperCase(c) != c;
    1.41 +}
    1.42 +
    1.43 +#ifdef MOZILLA_INTERNAL_API
    1.44 +
    1.45 +class nsCaseInsensitiveStringComparator : public nsStringComparator
    1.46 +{
    1.47 +public:
    1.48 +  virtual int32_t operator() (const char16_t*,
    1.49 +                              const char16_t*,
    1.50 +                              uint32_t,
    1.51 +                              uint32_t) const;
    1.52 +};
    1.53 +
    1.54 +class nsCaseInsensitiveUTF8StringComparator : public nsCStringComparator
    1.55 +{
    1.56 +public:
    1.57 +  virtual int32_t operator() (const char*,
    1.58 +                              const char*,
    1.59 +                              uint32_t,
    1.60 +                              uint32_t) const;
    1.61 +};
    1.62 +
    1.63 +class nsCaseInsensitiveStringArrayComparator
    1.64 +{
    1.65 +public:
    1.66 +  template<class A, class B>
    1.67 +  bool Equals(const A& a, const B& b) const {
    1.68 +    return a.Equals(b, nsCaseInsensitiveStringComparator());
    1.69 +  }
    1.70 +};
    1.71 +
    1.72 +class nsASCIICaseInsensitiveStringComparator : public nsStringComparator
    1.73 +{
    1.74 +public:
    1.75 +  nsASCIICaseInsensitiveStringComparator() {}
    1.76 +  virtual int operator() (const char16_t*,
    1.77 +                          const char16_t*,
    1.78 +                          uint32_t,
    1.79 +                          uint32_t) const;
    1.80 +};
    1.81 +
    1.82 +inline bool
    1.83 +CaseInsensitiveFindInReadable(const nsAString& aPattern,
    1.84 +                              nsAString::const_iterator& aSearchStart,
    1.85 +                              nsAString::const_iterator& aSearchEnd)
    1.86 +{
    1.87 +  return FindInReadable(aPattern, aSearchStart, aSearchEnd,
    1.88 +                        nsCaseInsensitiveStringComparator());
    1.89 +}
    1.90 +
    1.91 +inline bool
    1.92 +CaseInsensitiveFindInReadable(const nsAString& aPattern,
    1.93 +                              const nsAString& aHay)
    1.94 +{
    1.95 +  nsAString::const_iterator searchBegin, searchEnd;
    1.96 +  return FindInReadable(aPattern, aHay.BeginReading(searchBegin),
    1.97 +                        aHay.EndReading(searchEnd),
    1.98 +                        nsCaseInsensitiveStringComparator());
    1.99 +}
   1.100 +
   1.101 +#endif // MOZILLA_INTERNAL_API
   1.102 +
   1.103 +int32_t
   1.104 +CaseInsensitiveCompare(const char16_t *a, const char16_t *b, uint32_t len);
   1.105 +
   1.106 +int32_t
   1.107 +CaseInsensitiveCompare(const char* aLeft, const char* aRight,
   1.108 +                       uint32_t aLeftBytes, uint32_t aRightBytes);
   1.109 +
   1.110 +/**
   1.111 + * This function determines whether the UTF-8 sequence pointed to by aLeft is
   1.112 + * case-insensitively-equal to the UTF-8 sequence pointed to by aRight.
   1.113 + *
   1.114 + * aLeftEnd marks the first memory location past aLeft that is not part of
   1.115 + * aLeft; aRightEnd similarly marks the end of aRight.
   1.116 + *
   1.117 + * The function assumes that aLeft < aLeftEnd and aRight < aRightEnd.
   1.118 + *
   1.119 + * The function stores the addresses of the next characters in the sequence
   1.120 + * into aLeftNext and aRightNext.  It's up to the caller to make sure that the
   1.121 + * returned pointers are valid -- i.e. the function may return aLeftNext >=
   1.122 + * aLeftEnd or aRightNext >= aRightEnd.
   1.123 + *
   1.124 + * If the function encounters invalid text, it sets aErr to true and returns
   1.125 + * false, possibly leaving aLeftNext and aRightNext uninitialized.  If the
   1.126 + * function returns true, aErr is guaranteed to be false and both aLeftNext and
   1.127 + * aRightNext are guaranteed to be initialized.
   1.128 + */
   1.129 +bool
   1.130 +CaseInsensitiveUTF8CharsEqual(const char* aLeft, const char* aRight,
   1.131 +                              const char* aLeftEnd, const char* aRightEnd,
   1.132 +                              const char** aLeftNext, const char** aRightNext,
   1.133 +                              bool* aErr);
   1.134 +
   1.135 +namespace mozilla {
   1.136 +
   1.137 +/**
   1.138 + * Hash a UTF8 string as though it were a UTF16 string.
   1.139 + *
   1.140 + * The value returned is the same as if we converted the string to UTF16 and
   1.141 + * then ran HashString() on the result.
   1.142 + *
   1.143 + * The given |length| is in bytes.
   1.144 + */
   1.145 +uint32_t
   1.146 +HashUTF8AsUTF16(const char* aUTF8, uint32_t aLength, bool* aErr);
   1.147 +
   1.148 +} // namespace mozilla
   1.149 +
   1.150 +#endif  /* nsUnicharUtils_h__ */

mercurial