1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/librazor/uri.h Tue Apr 24 19:27:29 2018 +0100
1.3 @@ -0,0 +1,50 @@
1.4 +/*
1.5 + * Copyright (C) 2016 J. Ali Harlow <ali@juiblex.co.uk>
1.6 + *
1.7 + * This program is free software; you can redistribute it and/or modify
1.8 + * it under the terms of the GNU General Public License as published by
1.9 + * the Free Software Foundation; either version 2 of the License, or
1.10 + * (at your option) any later version.
1.11 + *
1.12 + * This program is distributed in the hope that it will be useful,
1.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.15 + * GNU General Public License for more details.
1.16 + *
1.17 + * You should have received a copy of the GNU General Public License along
1.18 + * with this program; if not, write to the Free Software Foundation, Inc.,
1.19 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1.20 + */
1.21 +
1.22 +#define is_alpha(c) ((c) >= 'a' && (c) <= 'z' || (c) >= 'A' && (c) <= 'Z')
1.23 +
1.24 +#define is_alnum(c) (is_alpha(c) || (c) >= '0' && (c) <= '9')
1.25 +
1.26 +#define is_xdigit(c) ((c) >= '0' && (c) <= '9' || \
1.27 + (c) >= 'a' && (c) <= 'f' || \
1.28 + (c) >= 'A' && (c) <= 'F')
1.29 +
1.30 +#define is_unreserved(c) (is_alnum(c) || (c) == '-' || (c) == '.' || \
1.31 + (c) == '_' || (c) == '~')
1.32 +
1.33 +#define is_sub_delim(c) strchr("!$&'()*+,;=", c)
1.34 +
1.35 +#define is_pchar(c) (is_unreserved(c) || (c) == '%' || \
1.36 + is_sub_delim(c) || (c) == ':' || (c) == '@')
1.37 +
1.38 +#define xdigit_value(c) ((c) >= '0' && (c) <= '9' ? (c) - '0' : \
1.39 + (c) >= 'a' && (c) <= 'f' ? (c) - 'a' + 10 : \
1.40 + (c) >= 'A' && (c) <= 'F' ? (c) - 'A' + 10 : -1)
1.41 +
1.42 +#define pchar_get_char(p) ((p)[0] == '%' ? \
1.43 + xdigit_value((p)[1]) * 16 + xdigit_value((p)[2]) : \
1.44 + (p)[0])
1.45 +
1.46 +#define pchar_next_char(p) \
1.47 + do { \
1.48 + if ((p)[0] == '%') \
1.49 + (p) += 3; \
1.50 + else \
1.51 + (p)++; \
1.52 + } while(0)
1.53 +