2
* Copyright (C) 2001 - 2004 Mike Wray <mike.wray@hp.com>
4
* This library is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License as
6
* published by the Free Software Foundation; either version 2.1 of the
7
* License, or (at your option) any later version. This library is
8
* distributed in the hope that it will be useful, but WITHOUT ANY
9
* WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
* FITNESS FOR A PARTICULAR PURPOSE.
11
* See the GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this library; if not, write to the Free Software Foundation,
15
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
#ifndef _XUTIL_LEXIS_H_
19
#define _XUTIL_LEXIS_H_
21
#include "sys_string.h"
24
# include <linux/ctype.h>
33
/** Class of characters treated as space. */
34
#define space_class ((char []){ '\n', '\r', '\t', ' ', '\f' , 0 })
36
/** Class of separator characters. */
37
#define sep_class "{}()<>[]!;\"'"
39
#define comment_class "#"
41
/** Determine if a character is in a given class.
43
* @param c character to test
44
* @param s null-terminated string of characters in the class
45
* @return 1 if c is in the class, 0 otherwise.
47
static inline int in_class(int c, const char *s){
48
return s && (strchr(s, c) != 0);
51
/** Determine if a character is in the space class.
53
* @param c character to test
54
* @return 1 if c is in the class, 0 otherwise.
56
static inline int in_space_class(int c){
57
return in_class(c, space_class);
60
static inline int in_comment_class(int c){
61
return in_class(c, comment_class);
64
/** Determine if a character is in the separator class.
65
* Separator characters terminate tokens, and do not need space
68
* @param c character to test
69
* @return 1 if c is in the class, 0 otherwise.
71
static inline int in_sep_class(int c){
72
return in_class(c, sep_class);
75
/** Determine if a character is in the alpha class.
77
* @param c character to test
78
* @return 1 if c is in the class, 0 otherwise.
80
static inline int in_alpha_class(int c){
84
/** Determine if a character is in the octal digit class.
86
* @param c character to test
87
* @return 1 if c is in the class, 0 otherwise.
89
static inline int in_octal_digit_class(int c){
90
return '0' <= c && c <= '7';
93
/** Determine if a character is in the decimal digit class.
95
* @param c character to test
96
* @return 1 if c is in the class, 0 otherwise.
98
static inline int in_decimal_digit_class(int c){
102
/** Determine if a character is in the hex digit class.
104
* @param c character to test
105
* @return 1 if c is in the class, 0 otherwise.
107
static inline int in_hex_digit_class(int c){
108
return isdigit(c) || in_class(c, "abcdefABCDEF");
112
static inline int in_string_quote_class(int c){
113
return in_class(c, "'\"");
116
static inline int in_printable_class(int c){
117
return ('A' <= c && c <= 'Z')
118
|| ('a' <= c && c <= 'z')
119
|| ('0' <= c && c <= '9')
120
|| in_class(c, "!$%&*+,-./:;<=>?@^_`{|}~");
123
extern int is_decimal_number(const char *s, int n);
124
extern int is_hex_number(const char *s, int n);
125
extern int is_keyword(const char *s, const char *k);
126
extern int is_keychar(const char *s, char c);
128
#endif /* !_XUTIL_LEXIS_H_ */