Lines Matching +full:no +full:- +full:high +full:- +full:z

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
54 #include "un-namespace.h"
74 {{0}, "C.UTF-8"}, 1, 0, 0, 0
84 if (table->map && (table->maplen > 0)) { in destruct_collate()
85 (void) munmap(table->map, table->maplen); in destruct_collate()
97 else if (strcmp(encoding, "C.UTF-8") == 0) in __collate_load()
104 table->header.header.destructor = destruct_collate; in __collate_load()
130 int i, chains, z; in __collate_load_tables_l() local
138 table->__collate_load_error = 1; in __collate_load_tables_l()
146 if (asprintf(&buf, "%s/%s/LC_COLLATE", _PathLocale, encoding) == -1) in __collate_load_tables_l()
177 strlcat(table->header.version, TMP, sizeof (table->header.version)); in __collate_load_tables_l()
183 if ((info->directive_count < 1) || in __collate_load_tables_l()
184 (info->directive_count >= COLL_WEIGHTS_MAX) || in __collate_load_tables_l()
185 ((chains = info->chain_count) < 0)) { in __collate_load_tables_l()
193 (sizeof (collate_large_t) * info->large_count); in __collate_load_tables_l()
194 for (z = 0; z < info->directive_count; z++) { in __collate_load_tables_l()
195 i += sizeof (collate_subst_t) * info->subst_count[z]; in __collate_load_tables_l()
197 if (i != (sbuf.st_size - (TMP - map))) { in __collate_load_tables_l()
203 if (table->map && (table->maplen > 0)) { in __collate_load_tables_l()
204 (void) munmap(table->map, table->maplen); in __collate_load_tables_l()
206 table->map = map; in __collate_load_tables_l()
207 table->maplen = sbuf.st_size; in __collate_load_tables_l()
208 table->info = info; in __collate_load_tables_l()
209 table->char_pri_table = (void *)TMP; in __collate_load_tables_l()
212 for (z = 0; z < info->directive_count; z++) { in __collate_load_tables_l()
213 if (info->subst_count[z] > 0) { in __collate_load_tables_l()
214 table->subst_table[z] = (void *)TMP; in __collate_load_tables_l()
215 TMP += info->subst_count[z] * sizeof (collate_subst_t); in __collate_load_tables_l()
217 table->subst_table[z] = NULL; in __collate_load_tables_l()
222 table->chain_pri_table = (void *)TMP; in __collate_load_tables_l()
225 table->chain_pri_table = NULL; in __collate_load_tables_l()
226 if (info->large_count > 0) in __collate_load_tables_l()
227 table->large_pri_table = (void *)TMP; in __collate_load_tables_l()
229 table->large_pri_table = NULL; in __collate_load_tables_l()
231 table->__collate_load_error = 0; in __collate_load_tables_l()
239 int n = table->info->subst_count[pass]; in substsearch()
244 if (pass >= table->info->directive_count) in substsearch()
250 p = table->subst_table[pass] + (key & ~COLLATE_SUBST_PRIORITY); in substsearch()
251 assert(p->key == key); in substsearch()
253 return (p->pri); in substsearch()
260 int high = table->info->chain_count - 1; in chainsearch() local
263 collate_chain_t *tab = table->chain_pri_table; in chainsearch()
265 if (high < 0) in chainsearch()
268 while (low <= high) { in chainsearch()
269 next = (low + high) / 2; in chainsearch()
271 compar = *key - *p->str; in chainsearch()
273 l = wcsnlen(p->str, COLLATE_STR_LEN); in chainsearch()
274 compar = wcsncmp(key, p->str, l); in chainsearch()
283 high = next - 1; in chainsearch()
292 int high = table->info->large_count - 1; in largesearch() local
295 collate_large_t *tab = table->large_pri_table; in largesearch()
297 if (high < 0) in largesearch()
300 while (low <= high) { in largesearch()
301 next = (low + high) / 2; in largesearch()
303 compar = key - p->val; in largesearch()
309 high = next - 1; in largesearch()
327 if (which >= table->info->directive_count) { in _collate_lookup()
349 /* No active substitutions */ in _collate_lookup()
354 * single element (aka chains or collating-elements). in _collate_lookup()
357 ((p = p2->pri[which]) >= 0)) { in _collate_lookup()
365 * Character is a small (8-bit) character. in _collate_lookup()
368 *pri = table->char_pri_table[*t].pri[which]; in _collate_lookup()
370 } else if ((table->info->large_count > 0) && in _collate_lookup()
376 *pri = match->pri.pri[which]; in _collate_lookup()
382 if (table->info->directive[which] & DIRECTIVE_UNDEFINED) { in _collate_lookup()
386 *pri = table->info->undef_pri[which]; in _collate_lookup()
388 /* No substitutions for undefined characters! */ in _collate_lookup()
430 int ndir = table->info->directive_count; in _collate_wxfrm()
442 room--; in _collate_wxfrm()
451 direc = table->info->directive[pass]; in _collate_wxfrm()
464 fp = tr + wcslen(tr) - 1; in _collate_wxfrm()
468 *fp-- = c; in _collate_wxfrm()
487 room--; in _collate_wxfrm()
506 room--; in _collate_wxfrm()
518 return ((size_t)(-1)); in _collate_wxfrm()
522 * In the non-POSIX case, we transform each character into a string of
529 * 31-bits wide. (But: be careful using priorities where the high
530 * order bit is set -- i.e. the priority is negative. The sort order
542 #define XFRM_MASK ((1 << XFRM_SHIFT) - 1)
549 uint32_t val = (uint32_t)table->info->pri_count[pass]; in xfrm()
577 int ndir = table->info->directive_count; in _collate_sxfrm()
589 room--; in _collate_sxfrm()
598 direc = table->info->directive[pass]; in _collate_sxfrm()
611 fp = tr + wcslen(tr) - 1; in _collate_sxfrm()
615 *fp-- = c; in _collate_sxfrm()
638 b--; in _collate_sxfrm()
641 room--; in _collate_sxfrm()
665 b--; in _collate_sxfrm()
668 room--; in _collate_sxfrm()
681 return ((size_t)(-1)); in _collate_sxfrm()
696 return (-1); in __collate_equiv_value()
700 (struct xlocale_collate*)locale->components[XLC_COLLATE]; in __collate_equiv_value()
702 if (table->__collate_load_error) in __collate_equiv_value()
703 return ((len == 1 && *str <= UCHAR_MAX) ? *str : -1); in __collate_equiv_value()
706 e = -1; in __collate_equiv_value()
708 e = table->char_pri_table[*str].pri[0]; in __collate_equiv_value()
709 else if (table->info->large_count > 0) { in __collate_equiv_value()
713 e = match_large->pri.pri[0]; in __collate_equiv_value()
719 if (table->info->chain_count > 0) { in __collate_equiv_value()
728 e = match_chain->pri[0]; in __collate_equiv_value()
731 return (e < 0 ? -e : e); in __collate_equiv_value()
743 * copied to dst is returned if successful. Zero is returned if no such
744 * collating symbol exists. (size_t)-1 is returned if there are wide-character
759 (struct xlocale_collate *)__get_locale()->components[XLC_COLLATE]; in __collate_collating_symbol()
761 if (table->__collate_load_error) { in __collate_collating_symbol()
763 return ((size_t)-1); in __collate_collating_symbol()
771 if (l == (size_t)-1 || l == (size_t)-2) in __collate_collating_symbol()
772 return ((size_t)-1); in __collate_collating_symbol()
776 return ((size_t)-1); in __collate_collating_symbol()
779 slen -= l; in __collate_collating_symbol()
782 return ((size_t)-1); in __collate_collating_symbol()
785 if (table->char_pri_table[*wname].pri[0] >= 0) { in __collate_collating_symbol()
791 } else if (table->info->large_count > 0) { in __collate_collating_symbol()
794 if (match && match->pri.pri[0] >= 0) { in __collate_collating_symbol()
803 if (table->info->chain_count > 0) { in __collate_collating_symbol()
819 * specified by src and slen, using ps to convert from multi-byte to wide
821 * class. -1 is returned if there are wide character conversion errors,
822 * if there are any greater-than-8-bit characters or if a multi-byte symbol
836 (struct xlocale_collate *)__get_locale()->components[XLC_COLLATE]; in __collate_equiv_class()
838 if (table->__collate_load_error) in __collate_equiv_class()
842 if (l == (size_t)-1 || l == (size_t)-2) in __collate_equiv_class()
843 return (-1); in __collate_equiv_class()
847 return (-1); in __collate_equiv_class()
850 slen -= l; in __collate_equiv_class()
853 return (-1); in __collate_equiv_class()
855 e = -1; in __collate_equiv_class()
857 e = table->char_pri_table[*wname].pri[0]; in __collate_equiv_class()
858 else if (table->info->large_count > 0) { in __collate_equiv_class()
862 e = match->pri.pri[0]; in __collate_equiv_class()
869 if (table->info->chain_count > 0) { in __collate_equiv_class()
874 e = match->pri[0]; in __collate_equiv_class()
877 return (e < 0 ? -e : e); in __collate_equiv_class()
885 * __collate_equiv_match tries to match any single or multi-character symbol
886 * in equivalence class equiv_class in the multi-byte string specified by src
887 * and slen. If start is non-zero, it is taken to be the first (pre-converted)
890 * is returned (including the start character). If dst is non-NULL, the
891 * matched wide-character string is copied to dst, a wide character array of
892 * length dlen (the results are not zero-terminated). If rlen is non-NULL,
894 * returned by __collate_equiv_match if there is no match. (size_t)-1 is
896 * to accept the results. On no match or error, ps is restored to its incoming
914 (struct xlocale_collate *)__get_locale()->components[XLC_COLLATE]; in __collate_equiv_match()
916 if (table->__collate_load_error) in __collate_equiv_match()
917 return ((size_t)-1); in __collate_equiv_match()
929 while (sl > 0 && len < table->info->chain_max_len) { in __collate_equiv_match()
931 if (l == (size_t)-1 || l == (size_t)-2 || l == 0) in __collate_equiv_match()
936 sl -= l; in __collate_equiv_match()
941 int e = ch->pri[0]; in __collate_equiv_match()
943 e = -e; in __collate_equiv_match()
950 if (equiv_class == table->char_pri_table[*buf].pri[0]) in __collate_equiv_match()
952 } else if (table->info->large_count > 0) { in __collate_equiv_match()
955 if (match && equiv_class == match->pri.pri[0]) in __collate_equiv_match()
958 /* no match */ in __collate_equiv_match()
972 i--; in __collate_equiv_match()
974 while (i-- > 0) { in __collate_equiv_match()
978 slen -= l; in __collate_equiv_match()
985 return ((size_t)-1); in __collate_equiv_match()
987 for (wp = buf; len > 0; len--) in __collate_equiv_match()