librazor/uri.h
author J. Ali Harlow <ali@juiblex.co.uk>
Tue Mar 06 12:39:15 2018 +0000 (2018-03-06)
changeset 495 5196f8110473
permissions -rw-r--r--
Release 0.6.3.111
ali@475
     1
/*
ali@475
     2
 * Copyright (C) 2016  J. Ali Harlow <ali@juiblex.co.uk>
ali@475
     3
 *
ali@475
     4
 * This program is free software; you can redistribute it and/or modify
ali@475
     5
 * it under the terms of the GNU General Public License as published by
ali@475
     6
 * the Free Software Foundation; either version 2 of the License, or
ali@475
     7
 * (at your option) any later version.
ali@475
     8
 *
ali@475
     9
 * This program is distributed in the hope that it will be useful,
ali@475
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ali@475
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ali@475
    12
 * GNU General Public License for more details.
ali@475
    13
 *
ali@475
    14
 * You should have received a copy of the GNU General Public License along
ali@475
    15
 * with this program; if not, write to the Free Software Foundation, Inc.,
ali@475
    16
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
ali@475
    17
 */
ali@475
    18
ali@475
    19
#define is_alpha(c)	  ((c) >= 'a' && (c) <= 'z' || (c) >= 'A' && (c) <= 'Z')
ali@475
    20
ali@475
    21
#define is_alnum(c)	  (is_alpha(c) || (c) >= '0' && (c) <= '9')
ali@475
    22
ali@475
    23
#define is_xdigit(c)	  ((c) >= '0' && (c) <= '9' || \
ali@475
    24
			   (c) >= 'a' && (c) <= 'f' || \
ali@475
    25
			   (c) >= 'A' && (c) <= 'F')
ali@475
    26
ali@475
    27
#define is_unreserved(c)  (is_alnum(c) || (c) == '-' || (c) == '.' || \
ali@475
    28
			   (c) == '_' || (c) == '~')
ali@475
    29
ali@475
    30
#define is_sub_delim(c)	  strchr("!$&'()*+,;=", c)
ali@475
    31
ali@475
    32
#define is_pchar(c)	  (is_unreserved(c) || (c) == '%' || \
ali@475
    33
			   is_sub_delim(c) || (c) == ':' || (c) == '@')
ali@475
    34
ali@475
    35
#define xdigit_value(c)	  ((c) >= '0' && (c) <= '9' ? (c) - '0' : \
ali@475
    36
			   (c) >= 'a' && (c) <= 'f' ? (c) - 'a' + 10 : \
ali@475
    37
			   (c) >= 'A' && (c) <= 'F' ? (c) - 'A' + 10 : -1)
ali@475
    38
ali@475
    39
#define pchar_get_char(p) ((p)[0] == '%' ? \
ali@475
    40
			   xdigit_value((p)[1]) * 16 + xdigit_value((p)[2]) : \
ali@475
    41
			   (p)[0])
ali@475
    42
ali@475
    43
#define pchar_next_char(p) \
ali@475
    44
	    do { \
ali@475
    45
		    if ((p)[0] == '%') \
ali@475
    46
			    (p) += 3; \
ali@475
    47
		    else \
ali@475
    48
			    (p)++; \
ali@475
    49
	    } while(0)
ali@475
    50