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