2 * Copyright (C) 2016 J. Ali Harlow <ali@juiblex.co.uk>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #define is_alpha(c) ((c) >= 'a' && (c) <= 'z' || (c) >= 'A' && (c) <= 'Z')
21 #define is_alnum(c) (is_alpha(c) || (c) >= '0' && (c) <= '9')
23 #define is_xdigit(c) ((c) >= '0' && (c) <= '9' || \
24 (c) >= 'a' && (c) <= 'f' || \
25 (c) >= 'A' && (c) <= 'F')
27 #define is_unreserved(c) (is_alnum(c) || (c) == '-' || (c) == '.' || \
28 (c) == '_' || (c) == '~')
30 #define is_sub_delim(c) strchr("!$&'()*+,;=", c)
32 #define is_pchar(c) (is_unreserved(c) || (c) == '%' || \
33 is_sub_delim(c) || (c) == ':' || (c) == '@')
35 #define xdigit_value(c) ((c) >= '0' && (c) <= '9' ? (c) - '0' : \
36 (c) >= 'a' && (c) <= 'f' ? (c) - 'a' + 10 : \
37 (c) >= 'A' && (c) <= 'F' ? (c) - 'A' + 10 : -1)
39 #define pchar_get_char(p) ((p)[0] == '%' ? \
40 xdigit_value((p)[1]) * 16 + xdigit_value((p)[2]) : \
43 #define pchar_next_char(p) \