Lines Matching +full:key +full:- +full:code

1 // SPDX-License-Identifier: GPL-2.0
3 * ucs.c - Universal Character Set processing
23 static int interval16_cmp(const void *key, const void *element) in interval16_cmp() argument
25 u16 cp = *(u16 *)key; in interval16_cmp()
28 if (cp < entry->first) in interval16_cmp()
29 return -1; in interval16_cmp()
30 if (cp > entry->last) in interval16_cmp()
35 static int interval32_cmp(const void *key, const void *element) in interval32_cmp() argument
37 u32 cp = *(u32 *)key; in interval32_cmp()
40 if (cp < entry->first) in interval32_cmp()
41 return -1; in interval32_cmp()
42 if (cp > entry->last) in interval32_cmp()
49 if (cp < ranges[0].first || cp > ranges[size - 1].last) in cp_in_range16()
58 if (cp < ranges[0].first || cp > ranges[size - 1].last) in cp_in_range32()
68 * ucs_is_zero_width() - Determine if a Unicode code point is zero-width.
69 * @cp: Unicode code point (UCS-4)
71 * Return: true if the character is zero-width, false otherwise
84 * ucs_is_double_width() - Determine if a Unicode code point is double-width.
85 * @cp: Unicode code point (UCS-4)
87 * Return: true if the character is double-width, false otherwise
116 static int recomposition_cmp(const void *key, const void *element) in recomposition_cmp() argument
118 const struct compare_key *search_key = key; in recomposition_cmp()
122 if (search_key->base < entry->base) in recomposition_cmp()
123 return -1; in recomposition_cmp()
124 if (search_key->base > entry->base) in recomposition_cmp()
128 if (search_key->mark < entry->mark) in recomposition_cmp()
129 return -1; in recomposition_cmp()
130 if (search_key->mark > entry->mark) in recomposition_cmp()
138 * ucs_recompose() - Attempt to recompose two Unicode characters into a single character.
139 * @base: Base Unicode code point (UCS-4)
140 * @mark: Combining mark Unicode code point (UCS-4)
142 * Return: Recomposed Unicode code point, or 0 if no recomposition is possible
151 struct compare_key key = { base, mark }; in ucs_recompose() local
153 __inline_bsearch(&key, ucs_recomposition_table, in ucs_recompose()
158 return result ? result->recomposed : 0; in ucs_recompose()
162 * The fallback table structures implement a 2-level lookup.
166 u8 page; /* Page index (high byte of code points) */
172 u8 offset; /* Offset within page (0-255) */
178 static int ucs_page_desc_cmp(const void *key, const void *element) in ucs_page_desc_cmp() argument
180 u8 page = *(u8 *)key; in ucs_page_desc_cmp()
183 if (page < entry->page) in ucs_page_desc_cmp()
184 return -1; in ucs_page_desc_cmp()
185 if (page > entry->page) in ucs_page_desc_cmp()
190 static int ucs_page_entry_cmp(const void *key, const void *element) in ucs_page_entry_cmp() argument
192 u8 offset = *(u8 *)key; in ucs_page_entry_cmp()
195 if (offset < entry->offset) in ucs_page_entry_cmp()
196 return -1; in ucs_page_entry_cmp()
197 if (entry->fallback == UCS_PAGE_ENTRY_RANGE_MARKER) { in ucs_page_entry_cmp()
201 if (offset > entry->offset) in ucs_page_entry_cmp()
208 * ucs_get_fallback() - Get a substitution for the provided Unicode character
209 * @cp: Unicode code point (UCS-4)
216 * Return: Fallback Unicode code point, or 0 if none is available
228 * Full-width to ASCII mapping (covering all printable ASCII 33-126) in ucs_get_fallback()
229 * 0xFF01 (!) to 0xFF5E (~) -> ASCII 33 (!) to 126 (~) in ucs_get_fallback()
233 return cp - 0xFF01 + 33; in ucs_get_fallback()
242 entry = __inline_bsearch(&offset, ucs_fallback_entries + page->start, in ucs_get_fallback()
243 page->count, sizeof(*ucs_fallback_entries), in ucs_get_fallback()
248 if (entry->fallback == UCS_PAGE_ENTRY_RANGE_MARKER) in ucs_get_fallback()
250 return entry->fallback; in ucs_get_fallback()