path_decode(Path) -> path_decode(Path, <<>>).
path_decode(<<$%, Hi, Lo, Tail/binary>>, Acc) ->
- Hex = hex_to_integer([Hi, Lo]),
+ Hex = list_to_integer([Hi, Lo], 16),
if Hex == 0 -> exit(badurl);
true -> ok
end,
{K, misc:expand_keyword(<<"@VERSION@">>, V, ?VERSION)}
end, Headers).
-%% hex_to_integer
-
-hex_to_integer(Hex) ->
- case catch list_to_integer(Hex, 16) of
- {'EXIT', _} -> old_hex_to_integer(Hex);
- X -> X
- end.
-
-old_hex_to_integer(Hex) ->
- DEHEX = fun (H) when H >= $a, H =< $f -> H - $a + 10;
- (H) when H >= $A, H =< $F -> H - $A + 10;
- (H) when H >= $0, H =< $9 -> H - $0
- end,
- lists:foldl(fun (E, Acc) -> Acc * 16 + DEHEX(E) end, 0,
- Hex).
-
code_to_phrase(100) -> <<"Continue">>;
code_to_phrase(101) -> <<"Switching Protocols ">>;
code_to_phrase(200) -> <<"OK">>;
parse_urlencoded(<<$%, Hi, Lo, Tail/binary>>, Last, Cur,
State) ->
- Hex = hex_to_integer([Hi, Lo]),
+ Hex = list_to_integer([Hi, Lo], 16),
parse_urlencoded(Tail, Last, <<Cur/binary, Hex>>, State);
parse_urlencoded(<<$&, Tail/binary>>, _Last, Cur, key) ->
[{Cur, <<"">>} | parse_urlencoded(Tail,
H == $: ->
url_encode(T, <<Acc/binary, H>>);
url_encode(<<H:8, T/binary>>, Acc) ->
- case integer_to_hex(H) of
+ case integer_to_list(H, 16) of
[X, Y] -> url_encode(T, <<Acc/binary, $%, X, Y>>);
[X] -> url_encode(T, <<Acc/binary, $%, $0, X>>)
end;
url_encode(<<>>, Acc) ->
Acc.
-integer_to_hex(I) ->
- case catch erlang:integer_to_list(I, 16) of
- {'EXIT', _} -> old_integer_to_hex(I);
- Int -> Int
- end.
-
-old_integer_to_hex(I) when I < 10 -> integer_to_list(I);
-old_integer_to_hex(I) when I < 16 -> [I - 10 + $A];
-old_integer_to_hex(I) when I >= 16 ->
- N = trunc(I / 16),
- old_integer_to_hex(N) ++ old_integer_to_hex(I rem 16).
-
-spec set_node_id(string(), binary()) -> pid().
set_node_id(PidStr, NodeBin) ->
ExtPidStr = erlang:pid_to_list(