1 /* ----------------------------------------------------------------------- *
3 * Copyright 1996-2018 The NASM Authors - All Rights Reserved
4 * See the file AUTHORS included with the NASM distribution for
5 * the specific copyright holders.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * ----------------------------------------------------------------------- */
35 * ctype-like functions specific to NASM
42 void nasm_ctype_init(void);
44 extern unsigned char nasm_tolower_tab
[256];
45 static inline char nasm_tolower(char x
)
47 return nasm_tolower_tab
[(unsigned char)x
];
57 NCT_LOWER
= 0x0008, /* isalpha(x) && tolower(x) == x */
58 NCT_UPPER
= 0x0010, /* isalpha(x) && tolower(x) != x */
63 NCT_MINUS
= 0x0200, /* - */
64 NCT_DOLLAR
= 0x0400, /* $ */
65 NCT_UNDER
= 0x0800, /* _ */
66 NCT_QUOTE
= 0x1000 /* " ' ` */
69 extern uint16_t nasm_ctype_tab
[256];
70 static inline bool nasm_ctype(unsigned char x
, enum nasm_ctype mask
)
72 return (nasm_ctype_tab
[x
] & mask
) != 0;
75 static inline bool nasm_isspace(char x
)
77 return nasm_ctype(x
, NCT_SPACE
);
80 static inline bool nasm_isalpha(char x
)
82 return nasm_ctype(x
, NCT_LOWER
|NCT_UPPER
);
85 static inline bool nasm_isdigit(char x
)
87 return nasm_ctype(x
, NCT_DIGIT
);
89 static inline bool nasm_isalnum(char x
)
91 return nasm_ctype(x
, NCT_LOWER
|NCT_UPPER
|NCT_DIGIT
);
93 static inline bool nasm_isxdigit(char x
)
95 return nasm_ctype(x
, NCT_HEX
);
97 static inline bool nasm_isidstart(char x
)
99 return nasm_ctype(x
, NCT_IDSTART
);
101 static inline bool nasm_isidchar(char x
)
103 return nasm_ctype(x
, NCT_ID
);
105 static inline bool nasm_isbrcchar(char x
)
107 return nasm_ctype(x
, NCT_ID
|NCT_MINUS
);
109 static inline bool nasm_isnumstart(char x
)
111 return nasm_ctype(x
, NCT_DIGIT
|NCT_DOLLAR
);
113 static inline bool nasm_isnumchar(char x
)
115 return nasm_ctype(x
, NCT_DIGIT
|NCT_LOWER
|NCT_UPPER
|NCT_UNDER
);
117 static inline bool nasm_isquote(char x
)
119 return nasm_ctype(x
, NCT_QUOTE
);
122 static inline void nasm_ctype_tasm_mode(void)
124 /* No differences at the present moment */
127 #endif /* NASM_NCTYPE_H */