import less(1)
[unleashed/tickless.git] / usr / src / lib / libc / port / locale / isdigit.c
blob2ffb5fe96a01df54a0c83b705244a775888630e1
1 /*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright 2013 Garrett D'Amore <garrett@damore.org>
14 * Copyright 2017 Nexenta Systems, Inc.
18 * This file contains the implementation of various functional forms
19 * of the ctype tests, specifically the required by ISO C. These are defined
20 * in the "C" (POSIX) locale.
23 #include "lint.h"
24 #include <ctype.h>
25 #include <locale.h>
26 #include "localeimpl.h"
27 #include "_ctype.h"
28 #include "lctype.h"
31 * As far as we know, *every* encoding we support is a strict superset of ASCII,
32 * so we can make things faster by trying ASCII first. Next check if argument
33 * can be represented as unsigned char, and that locale is not multibyte - every
34 * multibyte encoding we support has non-ASCII code points undefined. Finally,
35 * lookup the result in locale specific table.
37 #define ISTYPE_L(c, mask, loc) \
38 (isascii(c) ? (__ctype_mask[c] & (mask)) : \
39 ((unsigned)c > 255 || loc->ctype->lc_max_mblen > 1) ? 0 : \
40 (loc->ctype->lc_ctype_mask[c] & mask))
42 #define ISTYPE(c, mask) ISTYPE_L(c, mask, uselocale(NULL))
44 #define DEFN_ISTYPE(type, mask) \
45 int \
46 is##type##_l(int c, locale_t l) \
47 { \
48 return (ISTYPE_L(c, mask, l)); \
49 } \
51 int \
52 is##type(int c) \
53 { \
54 return (ISTYPE(c, mask)); \
58 * We are supplying functional forms, so make sure to suppress any macros
59 * we might have imported.
61 #undef isblank
62 #undef isupper
63 #undef islower
64 #undef isdigit
65 #undef isxdigit
66 #undef isalpha
67 #undef isalnum
68 #undef isspace
69 #undef iscntrl
70 #undef isgraph
71 #undef ispunct
72 #undef isprint
74 DEFN_ISTYPE(blank, _ISBLANK)
75 DEFN_ISTYPE(upper, _ISUPPER)
76 DEFN_ISTYPE(lower, _ISLOWER)
77 DEFN_ISTYPE(digit, _ISDIGIT)
78 DEFN_ISTYPE(xdigit, _ISXDIGIT)
79 DEFN_ISTYPE(alpha, _ISALPHA)
80 DEFN_ISTYPE(alnum, _ISALNUM)
81 DEFN_ISTYPE(space, _ISSPACE)
82 DEFN_ISTYPE(cntrl, _ISCNTRL)
83 DEFN_ISTYPE(graph, _ISGRAPH)
84 DEFN_ISTYPE(punct, _ISPUNCT)
85 DEFN_ISTYPE(print, _ISPRINT)