Print this page
2964 need POSIX 2008 locale object support
Reviewed by: Robert Mustacchi <rm@joyent.com>

@@ -1,6 +1,7 @@
 /*
+ * Copyright 2013 Garrett D'Amore <garrett@damore.org>
  * Copyright 2010 Nexenta Systems, Inc.  All rights reserved.
  * Copyright 2012 Milan Jurik. All rights reserved.
  * Copyright (c) 1992, 1993, 1994 Henry Spencer.
  * Copyright (c) 1992, 1993, 1994
  *      The Regents of the University of California.  All rights reserved.

@@ -723,10 +724,11 @@
 p_b_term(struct parse *p, cset *cs)
 {
         char c;
         wint_t start, finish;
         wint_t i;
+        locale_t loc = uselocale(NULL);
 
         /* classify what we've got */
         switch ((MORE()) ? PEEK() : '\0') {
         case '[':
                 c = (MORE2()) ? PEEK2() : '\0';

@@ -770,20 +772,22 @@
                 } else
                         finish = start;
                 if (start == finish)
                         CHadd(p, cs, start);
                 else {
-                        if (_collate_load_error) {
+                        if (loc->collate->lc_is_posix) {
                                 (void) REQUIRE((uch)start <= (uch)finish,
                                     REG_ERANGE);
                                 CHaddrange(p, cs, start, finish);
                         } else {
                                 (void) REQUIRE(_collate_range_cmp(start,
-                                    finish) <= 0, REG_ERANGE);
+                                    finish, loc) <= 0, REG_ERANGE);
                                 for (i = 0; i <= UCHAR_MAX; i++) {
-                                        if (_collate_range_cmp(start, i) <= 0 &&
-                                            _collate_range_cmp(i, finish) <= 0)
+                                        if (_collate_range_cmp(start, i, loc)
+                                            <= 0 &&
+                                            _collate_range_cmp(i, finish, loc)
+                                            <= 0)
                                                 CHadd(p, cs, i);
                                 }
                         }
                 }
                 break;

@@ -1365,10 +1369,11 @@
         char *cp;
         int offset;
         char buf[MB_LEN_MAX];
         size_t clen;
         mbstate_t mbs;
+        locale_t loc = uselocale(NULL);
 
         /* avoid making error situations worse */
         if (p->error != 0)
                 return;
 

@@ -1376,11 +1381,11 @@
          * It's not generally safe to do a ``char'' substring search on
          * multibyte character strings, but it's safe for at least
          * UTF-8 (see RFC 3629).
          */
         if (MB_CUR_MAX > 1 &&
-            strcmp(_CurrentRuneLocale->__encoding, "UTF-8") != 0)
+            strcmp(loc->runelocale->__encoding, "UTF-8") != 0)
                 return;
 
         /* find the longest OCHAR sequence in strip */
         newlen = 0;
         offset = 0;