Print this page
9083 replace regex implementation with tre

@@ -648,5 +648,56 @@
 fail:
         if (tr)
                 free(tr);
         return ((size_t)(-1));
 }
+
+/*
+ * __collate_equiv_value returns the primary collation value for the given
+ * collating symbol specified by str and len.  Zero or negative is returned
+ * if the collating symbol was not found.
+ */
+int
+__collate_equiv_value(locale_t loc, const wchar_t *str, size_t len)
+{
+        const struct lc_collate *lcc = loc->collate;
+        int32_t e;
+
+        if (len < 1 || len >= COLLATE_STR_LEN)
+                return (-1);
+
+        if (lcc->lc_is_posix)
+                return ((len == 1 && *str <= UCHAR_MAX) ? *str : -1);
+
+        if (len == 1) {
+                e = -1;
+                if (*str <= UCHAR_MAX)
+                        e = lcc->lc_char_table[*str].pri[0];
+                else if (lcc->lc_large_count > 0) {
+                        collate_large_t *match_large;
+
+                        match_large = largesearch(lcc, *str);
+                        if (match_large != NULL)
+                                e = match_large->pri.pri[0];
+                }
+                if (e == 0)
+                        return (1);
+                return (e > 0 ? e : 0);
+        }
+        if (lcc->lc_chain_count > 0) {
+                wchar_t name[COLLATE_STR_LEN];
+                collate_chain_t *match_chain;
+                int clen;
+
+                wcsncpy(name, str, len);
+                name[len] = 0;
+                match_chain = chainsearch(lcc, name, &clen);
+                if (match_chain != NULL) {
+                        e = match_chain->pri[0];
+                        if (e == 0)
+                                return (1);
+                        return (e < 0 ? -e : e);
+                }
+        }
+
+        return (0);
+}