librazor/uri.h
author J. Ali Harlow <ali@juiblex.co.uk>
Mon Jul 11 13:54:54 2016 +0100 (2016-07-11)
changeset 488 7c6d932f291f
permissions -rw-r--r--
Release 0.6.3.104
     1 /*
     2  * Copyright (C) 2016  J. Ali Harlow <ali@juiblex.co.uk>
     3  *
     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.
     8  *
     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.
    13  *
    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.
    17  */
    18 
    19 #define is_alpha(c)	  ((c) >= 'a' && (c) <= 'z' || (c) >= 'A' && (c) <= 'Z')
    20 
    21 #define is_alnum(c)	  (is_alpha(c) || (c) >= '0' && (c) <= '9')
    22 
    23 #define is_xdigit(c)	  ((c) >= '0' && (c) <= '9' || \
    24 			   (c) >= 'a' && (c) <= 'f' || \
    25 			   (c) >= 'A' && (c) <= 'F')
    26 
    27 #define is_unreserved(c)  (is_alnum(c) || (c) == '-' || (c) == '.' || \
    28 			   (c) == '_' || (c) == '~')
    29 
    30 #define is_sub_delim(c)	  strchr("!$&'()*+,;=", c)
    31 
    32 #define is_pchar(c)	  (is_unreserved(c) || (c) == '%' || \
    33 			   is_sub_delim(c) || (c) == ':' || (c) == '@')
    34 
    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)
    38 
    39 #define pchar_get_char(p) ((p)[0] == '%' ? \
    40 			   xdigit_value((p)[1]) * 16 + xdigit_value((p)[2]) : \
    41 			   (p)[0])
    42 
    43 #define pchar_next_char(p) \
    44 	    do { \
    45 		    if ((p)[0] == '%') \
    46 			    (p) += 3; \
    47 		    else \
    48 			    (p)++; \
    49 	    } while(0)
    50