From 34291d5bb42c03d92522dfa18d38aa0d22bcb8ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Wed, 18 Dec 2019 21:13:04 +0100 Subject: Add cow_uri_templates Implements RFC6570 level 4. --- include/cow_inline.hrl | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/cow_parse.hrl | 4 ++++ 2 files changed, 60 insertions(+) (limited to 'include') diff --git a/include/cow_inline.hrl b/include/cow_inline.hrl index e4e6c89..f0d12eb 100644 --- a/include/cow_inline.hrl +++ b/include/cow_inline.hrl @@ -388,4 +388,60 @@ end). C -> Function(Rest, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, << Acc/binary, C >>) end). +%% HEX(C) + +-define(HEX(C), (?HEXHL(C bsr 4)), (?HEXHL(C band 16#0f))). + +-define(HEXHL(HL), + case HL of + 0 -> $0; + 1 -> $1; + 2 -> $2; + 3 -> $3; + 4 -> $4; + 5 -> $5; + 6 -> $6; + 7 -> $7; + 8 -> $8; + 9 -> $9; + 10 -> $A; + 11 -> $B; + 12 -> $C; + 13 -> $D; + 14 -> $E; + 15 -> $F + end +). + +%% UNHEX(H, L) + +-define(UNHEX(H, L), (?UNHEX(H) bsl 4 bor ?UNHEX(L))). + +-define(UNHEX(C), + case C of + $0 -> 0; + $1 -> 1; + $2 -> 2; + $3 -> 3; + $4 -> 4; + $5 -> 5; + $6 -> 6; + $7 -> 7; + $8 -> 8; + $9 -> 9; + $A -> 10; + $B -> 11; + $C -> 12; + $D -> 13; + $E -> 14; + $F -> 15; + $a -> 10; + $b -> 11; + $c -> 12; + $d -> 13; + $e -> 14; + $f -> 15 + end +). + -endif. diff --git a/include/cow_parse.hrl b/include/cow_parse.hrl index 48b410c..ee4af70 100644 --- a/include/cow_parse.hrl +++ b/include/cow_parse.hrl @@ -66,6 +66,10 @@ ?IS_ALPHA(C) or ?IS_DIGIT(C) or (C =:= $-) or (C =:= $.) or (C =:= $_) or (C =:= $~)). +-define(IS_URI_GEN_DELIMS(C), + (C =:= $:) or (C =:= $/) or (C =:= $?) or (C =:= $#) or + (C =:= $[) or (C =:= $]) or (C =:= $@)). + -define(IS_URI_SUB_DELIMS(C), (C =:= $!) or (C =:= $$) or (C =:= $&) or (C =:= $') or (C =:= $() or (C =:= $)) or (C =:= $*) or (C =:= $+) or -- cgit v1.2.3