633 *xf++ = buf[b];
634 room--;
635 }
636 }
637 }
638 need = want;
639 }
640 }
641 }
642
643 end:
644 if (tr)
645 free(tr);
646 return (need);
647
648 fail:
649 if (tr)
650 free(tr);
651 return ((size_t)(-1));
652 }
|
633 *xf++ = buf[b];
634 room--;
635 }
636 }
637 }
638 need = want;
639 }
640 }
641 }
642
643 end:
644 if (tr)
645 free(tr);
646 return (need);
647
648 fail:
649 if (tr)
650 free(tr);
651 return ((size_t)(-1));
652 }
653
654 /*
655 * __collate_equiv_value returns the primary collation value for the given
656 * collating symbol specified by str and len. Zero or negative is returned
657 * if the collating symbol was not found.
658 */
659 int
660 __collate_equiv_value(locale_t loc, const wchar_t *str, size_t len)
661 {
662 const struct lc_collate *lcc = loc->collate;
663 int32_t e;
664
665 if (len < 1 || len >= COLLATE_STR_LEN)
666 return (-1);
667
668 if (lcc->lc_is_posix)
669 return ((len == 1 && *str <= UCHAR_MAX) ? *str : -1);
670
671 if (len == 1) {
672 e = -1;
673 if (*str <= UCHAR_MAX)
674 e = lcc->lc_char_table[*str].pri[0];
675 else if (lcc->lc_large_count > 0) {
676 collate_large_t *match_large;
677
678 match_large = largesearch(lcc, *str);
679 if (match_large != NULL)
680 e = match_large->pri.pri[0];
681 }
682 if (e == 0)
683 return (1);
684 return (e > 0 ? e : 0);
685 }
686 if (lcc->lc_chain_count > 0) {
687 wchar_t name[COLLATE_STR_LEN];
688 collate_chain_t *match_chain;
689 int clen;
690
691 wcsncpy(name, str, len);
692 name[len] = 0;
693 match_chain = chainsearch(lcc, name, &clen);
694 if (match_chain != NULL) {
695 e = match_chain->pri[0];
696 if (e == 0)
697 return (1);
698 return (e < 0 ? -e : e);
699 }
700 }
701
702 return (0);
703 }
|