/work/obj-fuzz/dist/include/nsUnicharUtils.h
Line | Count | Source (jump to first uncovered line) |
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 "nsString.h" |
10 | | |
11 | | /* (0x3131u <= (u) && (u) <= 0x318eu) => Hangul Compatibility Jamo */ |
12 | | /* (0xac00u <= (u) && (u) <= 0xd7a3u) => Hangul Syllables */ |
13 | | #define IS_CJ_CHAR(u) \ |
14 | 0 | ((0x2e80u <= (u) && (u) <= 0x312fu) || \ |
15 | 0 | (0x3190u <= (u) && (u) <= 0xabffu) || \ |
16 | 0 | (0xf900u <= (u) && (u) <= 0xfaffu) || \ |
17 | 0 | (0xff00u <= (u) && (u) <= 0xffefu) ) |
18 | | |
19 | 0 | #define IS_ZERO_WIDTH_SPACE(u) ((u) == 0x200B) |
20 | | |
21 | 17.2M | #define IS_ASCII(u) ((u) < 0x80) |
22 | 0 | #define IS_ASCII_UPPER(u) (('A' <= (u)) && ((u) <= 'Z')) |
23 | 8.18M | #define IS_ASCII_LOWER(u) (('a' <= (u)) && ((u) <= 'z')) |
24 | | #define IS_ASCII_ALPHA(u) (IS_ASCII_UPPER(u) || IS_ASCII_LOWER(u)) |
25 | | #define IS_ASCII_SPACE(u) (' ' == (u)) |
26 | | |
27 | | void ToLowerCase(nsAString& aString); |
28 | | void ToLowerCaseASCII(nsAString& aString); |
29 | | void ToUpperCase(nsAString& aString); |
30 | | |
31 | | void ToLowerCase(const nsAString& aSource, nsAString& aDest); |
32 | | void ToLowerCaseASCII(const nsAString& aSource, nsAString& aDest); |
33 | | void ToUpperCase(const nsAString& aSource, nsAString& aDest); |
34 | | |
35 | | uint32_t ToLowerCase(uint32_t aChar); |
36 | | uint32_t ToUpperCase(uint32_t aChar); |
37 | | uint32_t ToTitleCase(uint32_t aChar); |
38 | | |
39 | | void ToLowerCase(const char16_t *aIn, char16_t *aOut, uint32_t aLen); |
40 | | void ToLowerCaseASCII(const char16_t *aIn, char16_t *aOut, uint32_t aLen); |
41 | | void ToUpperCase(const char16_t *aIn, char16_t *aOut, uint32_t aLen); |
42 | | |
43 | | char ToLowerCaseASCII(const char aChar); |
44 | | char16_t ToLowerCaseASCII(const char16_t aChar); |
45 | | char32_t ToLowerCaseASCII(const char32_t aChar); |
46 | | |
47 | | char ToUpperCaseASCII(const char aChar); |
48 | | char16_t ToUpperCaseASCII(const char16_t aChar); |
49 | | char32_t ToUpperCaseASCII(const char32_t aChar); |
50 | | |
51 | 0 | inline bool IsUpperCase(uint32_t c) { |
52 | 0 | return ToLowerCase(c) != c; |
53 | 0 | } |
54 | | |
55 | 0 | inline bool IsLowerCase(uint32_t c) { |
56 | 0 | return ToUpperCase(c) != c; |
57 | 0 | } |
58 | | |
59 | | #ifdef MOZILLA_INTERNAL_API |
60 | | |
61 | | class nsCaseInsensitiveStringComparator : public nsStringComparator |
62 | | { |
63 | | public: |
64 | 0 | nsCaseInsensitiveStringComparator() = default; |
65 | | |
66 | | virtual int32_t operator() (const char16_t*, |
67 | | const char16_t*, |
68 | | uint32_t, |
69 | | uint32_t) const override; |
70 | | }; |
71 | | |
72 | | class nsCaseInsensitiveUTF8StringComparator : public nsCStringComparator |
73 | | { |
74 | | public: |
75 | | virtual int32_t operator() (const char*, |
76 | | const char*, |
77 | | uint32_t, |
78 | | uint32_t) const override; |
79 | | }; |
80 | | |
81 | | class nsCaseInsensitiveStringArrayComparator |
82 | | { |
83 | | public: |
84 | | template<class A, class B> |
85 | | bool Equals(const A& a, const B& b) const { |
86 | | return a.Equals(b, nsCaseInsensitiveStringComparator()); |
87 | | } |
88 | | }; |
89 | | |
90 | | class nsASCIICaseInsensitiveStringComparator : public nsStringComparator |
91 | | { |
92 | | public: |
93 | 204k | nsASCIICaseInsensitiveStringComparator() {} |
94 | | virtual int operator() (const char16_t*, |
95 | | const char16_t*, |
96 | | uint32_t, |
97 | | uint32_t) const override; |
98 | | }; |
99 | | |
100 | | inline bool |
101 | | CaseInsensitiveFindInReadable(const nsAString& aPattern, |
102 | | nsAString::const_iterator& aSearchStart, |
103 | | nsAString::const_iterator& aSearchEnd) |
104 | 0 | { |
105 | 0 | return FindInReadable(aPattern, aSearchStart, aSearchEnd, |
106 | 0 | nsCaseInsensitiveStringComparator()); |
107 | 0 | } |
108 | | |
109 | | inline bool |
110 | | CaseInsensitiveFindInReadable(const nsAString& aPattern, |
111 | | const nsAString& aHay) |
112 | 0 | { |
113 | 0 | nsAString::const_iterator searchBegin, searchEnd; |
114 | 0 | return FindInReadable(aPattern, aHay.BeginReading(searchBegin), |
115 | 0 | aHay.EndReading(searchEnd), |
116 | 0 | nsCaseInsensitiveStringComparator()); |
117 | 0 | } |
118 | | |
119 | | #endif // MOZILLA_INTERNAL_API |
120 | | |
121 | | int32_t |
122 | | CaseInsensitiveCompare(const char16_t *a, const char16_t *b, uint32_t len); |
123 | | |
124 | | int32_t |
125 | | CaseInsensitiveCompare(const char* aLeft, const char* aRight, |
126 | | uint32_t aLeftBytes, uint32_t aRightBytes); |
127 | | |
128 | | /** |
129 | | * Calculates the lower-case of the codepoint of the UTF8 sequence starting at |
130 | | * aStr. Sets aNext to the byte following the end of the sequence. |
131 | | * |
132 | | * If the sequence is invalid, or if computing the codepoint would take us off |
133 | | * the end of the string (as marked by aEnd), returns -1 and does not set |
134 | | * aNext. Note that this function doesn't check that aStr < aEnd -- it assumes |
135 | | * you've done that already. |
136 | | */ |
137 | | uint32_t |
138 | | GetLowerUTF8Codepoint(const char* aStr, const char* aEnd, const char **aNext); |
139 | | |
140 | | /** |
141 | | * This function determines whether the UTF-8 sequence pointed to by aLeft is |
142 | | * case-insensitively-equal to the UTF-8 sequence pointed to by aRight, as |
143 | | * defined by having matching lower-cased codepoints. |
144 | | * |
145 | | * aLeftEnd marks the first memory location past aLeft that is not part of |
146 | | * aLeft; aRightEnd similarly marks the end of aRight. |
147 | | * |
148 | | * The function assumes that aLeft < aLeftEnd and aRight < aRightEnd. |
149 | | * |
150 | | * The function stores the addresses of the next characters in the sequence |
151 | | * into aLeftNext and aRightNext. It's up to the caller to make sure that the |
152 | | * returned pointers are valid -- i.e. the function may return aLeftNext >= |
153 | | * aLeftEnd or aRightNext >= aRightEnd. |
154 | | * |
155 | | * If the function encounters invalid text, it sets aErr to true and returns |
156 | | * false, possibly leaving aLeftNext and aRightNext uninitialized. If the |
157 | | * function returns true, aErr is guaranteed to be false and both aLeftNext and |
158 | | * aRightNext are guaranteed to be initialized. |
159 | | */ |
160 | | bool |
161 | | CaseInsensitiveUTF8CharsEqual(const char* aLeft, const char* aRight, |
162 | | const char* aLeftEnd, const char* aRightEnd, |
163 | | const char** aLeftNext, const char** aRightNext, |
164 | | bool* aErr); |
165 | | |
166 | | namespace mozilla { |
167 | | |
168 | | /** |
169 | | * Hash a UTF8 string as though it were a UTF16 string. |
170 | | * |
171 | | * The value returned is the same as if we converted the string to UTF16 and |
172 | | * then ran HashString() on the result. |
173 | | * |
174 | | * The given |length| is in bytes. |
175 | | */ |
176 | | uint32_t |
177 | | HashUTF8AsUTF16(const char* aUTF8, uint32_t aLength, bool* aErr); |
178 | | |
179 | | bool |
180 | | IsSegmentBreakSkipChar(uint32_t u); |
181 | | |
182 | | } // namespace mozilla |
183 | | |
184 | | #endif /* nsUnicharUtils_h__ */ |