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 (c) 2002 Tim J. Robbins.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -24,30 +25,31 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "lint.h"
+#include <note.h>
#include <errno.h>
#include <string.h>
#include <wctype.h>
+#include <locale.h>
enum {
_WCT_ERROR = 0,
_WCT_TOLOWER = 1,
_WCT_TOUPPER = 2
};
wint_t
-towctrans(wint_t wc, wctrans_t desc)
+towctrans_l(wint_t wc, wctrans_t desc, locale_t loc)
{
-
switch (desc) {
case _WCT_TOLOWER:
- wc = towlower(wc);
+ wc = towlower_l(wc, loc);
break;
case _WCT_TOUPPER:
- wc = towupper(wc);
+ wc = towupper_l(wc, loc);
break;
case _WCT_ERROR:
default:
errno = EINVAL;
break;
@@ -54,12 +56,22 @@
}
return (wc);
}
+wint_t
+towctrans(wint_t wc, wctrans_t desc)
+{
+ return (towctrans_l(wc, desc, uselocale(NULL)));
+}
+
+/*
+ * For *now* we don't support locale sensitive transforms besides toupper
+ * and tolower.
+ */
wctrans_t
-wctrans(const char *charclass)
+wctrans_l(const char *charclass, locale_t loc)
{
struct {
const char *name;
wctrans_t trans;
} ccls[] = {
@@ -66,14 +78,21 @@
{ "tolower", _WCT_TOLOWER },
{ "toupper", _WCT_TOUPPER },
{ NULL, _WCT_ERROR }, /* Default */
};
int i;
+ _NOTE(ARGUNUSED(loc));
i = 0;
while (ccls[i].name != NULL && strcmp(ccls[i].name, charclass) != 0)
i++;
if (ccls[i].trans == _WCT_ERROR)
errno = EINVAL;
return (ccls[i].trans);
+}
+
+wctrans_t
+wctrans(const char *charclass)
+{
+ return (wctrans_l(charclass, uselocale(NULL)));
}