Line data Source code
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/. */
5 :
6 : #ifndef nsUnicharUtils_h__
7 : #define nsUnicharUtils_h__
8 :
9 : #include "nsStringGlue.h"
10 :
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) )
18 :
19 : #define IS_ZERO_WIDTH_SPACE(u) ((u) == 0x200B)
20 :
21 : void ToLowerCase(nsAString&);
22 : void ToUpperCase(nsAString&);
23 :
24 : void ToLowerCase(const nsAString& aSource, nsAString& aDest);
25 : void ToUpperCase(const nsAString& aSource, nsAString& aDest);
26 :
27 : uint32_t ToLowerCase(uint32_t);
28 : uint32_t ToUpperCase(uint32_t);
29 : uint32_t ToTitleCase(uint32_t);
30 :
31 : void ToLowerCase(const char16_t*, char16_t*, uint32_t);
32 : void ToUpperCase(const char16_t*, char16_t*, uint32_t);
33 :
34 0 : inline bool IsUpperCase(uint32_t c) {
35 0 : return ToLowerCase(c) != c;
36 : }
37 :
38 : inline bool IsLowerCase(uint32_t c) {
39 : return ToUpperCase(c) != c;
40 : }
41 :
42 : #ifdef MOZILLA_INTERNAL_API
43 :
44 325 : class nsCaseInsensitiveStringComparator : public nsStringComparator
45 : {
46 : public:
47 : virtual int32_t operator() (const char16_t*,
48 : const char16_t*,
49 : uint32_t,
50 : uint32_t) const override;
51 : };
52 :
53 0 : class nsCaseInsensitiveUTF8StringComparator : public nsCStringComparator
54 : {
55 : public:
56 : virtual int32_t operator() (const char*,
57 : const char*,
58 : uint32_t,
59 : uint32_t) const override;
60 : };
61 :
62 : class nsCaseInsensitiveStringArrayComparator
63 : {
64 : public:
65 : template<class A, class B>
66 : bool Equals(const A& a, const B& b) const {
67 : return a.Equals(b, nsCaseInsensitiveStringComparator());
68 : }
69 : };
70 :
71 : class nsASCIICaseInsensitiveStringComparator : public nsStringComparator
72 : {
73 : public:
74 208 : nsASCIICaseInsensitiveStringComparator() {}
75 : virtual int operator() (const char16_t*,
76 : const char16_t*,
77 : uint32_t,
78 : uint32_t) const override;
79 : };
80 :
81 : inline bool
82 0 : CaseInsensitiveFindInReadable(const nsAString& aPattern,
83 : nsAString::const_iterator& aSearchStart,
84 : nsAString::const_iterator& aSearchEnd)
85 : {
86 : return FindInReadable(aPattern, aSearchStart, aSearchEnd,
87 0 : nsCaseInsensitiveStringComparator());
88 : }
89 :
90 : inline bool
91 0 : CaseInsensitiveFindInReadable(const nsAString& aPattern,
92 : const nsAString& aHay)
93 : {
94 0 : nsAString::const_iterator searchBegin, searchEnd;
95 0 : return FindInReadable(aPattern, aHay.BeginReading(searchBegin),
96 : aHay.EndReading(searchEnd),
97 0 : nsCaseInsensitiveStringComparator());
98 : }
99 :
100 : #endif // MOZILLA_INTERNAL_API
101 :
102 : int32_t
103 : CaseInsensitiveCompare(const char16_t *a, const char16_t *b, uint32_t len);
104 :
105 : int32_t
106 : CaseInsensitiveCompare(const char* aLeft, const char* aRight,
107 : uint32_t aLeftBytes, uint32_t aRightBytes);
108 :
109 : /**
110 : * This function determines whether the UTF-8 sequence pointed to by aLeft is
111 : * case-insensitively-equal to the UTF-8 sequence pointed to by aRight.
112 : *
113 : * aLeftEnd marks the first memory location past aLeft that is not part of
114 : * aLeft; aRightEnd similarly marks the end of aRight.
115 : *
116 : * The function assumes that aLeft < aLeftEnd and aRight < aRightEnd.
117 : *
118 : * The function stores the addresses of the next characters in the sequence
119 : * into aLeftNext and aRightNext. It's up to the caller to make sure that the
120 : * returned pointers are valid -- i.e. the function may return aLeftNext >=
121 : * aLeftEnd or aRightNext >= aRightEnd.
122 : *
123 : * If the function encounters invalid text, it sets aErr to true and returns
124 : * false, possibly leaving aLeftNext and aRightNext uninitialized. If the
125 : * function returns true, aErr is guaranteed to be false and both aLeftNext and
126 : * aRightNext are guaranteed to be initialized.
127 : */
128 : bool
129 : CaseInsensitiveUTF8CharsEqual(const char* aLeft, const char* aRight,
130 : const char* aLeftEnd, const char* aRightEnd,
131 : const char** aLeftNext, const char** aRightNext,
132 : bool* aErr);
133 :
134 : namespace mozilla {
135 :
136 : /**
137 : * Hash a UTF8 string as though it were a UTF16 string.
138 : *
139 : * The value returned is the same as if we converted the string to UTF16 and
140 : * then ran HashString() on the result.
141 : *
142 : * The given |length| is in bytes.
143 : */
144 : uint32_t
145 : HashUTF8AsUTF16(const char* aUTF8, uint32_t aLength, bool* aErr);
146 :
147 : bool
148 : IsSegmentBreakSkipChar(uint32_t u);
149 :
150 : } // namespace mozilla
151 :
152 : #endif /* nsUnicharUtils_h__ */
|