mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
Remove old hex conversion functions
Depend on list_to_integer/2 and integer_to_list/2 being available.
This commit is contained in:
parent
a2e1f5c882
commit
df651d893e
@ -679,7 +679,7 @@ url_decode_q_split(<<>>, Ack) ->
|
|||||||
path_decode(Path) -> path_decode(Path, <<>>).
|
path_decode(Path) -> path_decode(Path, <<>>).
|
||||||
|
|
||||||
path_decode(<<$%, Hi, Lo, Tail/binary>>, Acc) ->
|
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);
|
if Hex == 0 -> exit(badurl);
|
||||||
true -> ok
|
true -> ok
|
||||||
end,
|
end,
|
||||||
@ -716,22 +716,6 @@ expand_custom_headers(Headers) ->
|
|||||||
{K, misc:expand_keyword(<<"@VERSION@">>, V, ?VERSION)}
|
{K, misc:expand_keyword(<<"@VERSION@">>, V, ?VERSION)}
|
||||||
end, Headers).
|
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(100) -> <<"Continue">>;
|
||||||
code_to_phrase(101) -> <<"Switching Protocols ">>;
|
code_to_phrase(101) -> <<"Switching Protocols ">>;
|
||||||
code_to_phrase(200) -> <<"OK">>;
|
code_to_phrase(200) -> <<"OK">>;
|
||||||
@ -802,7 +786,7 @@ parse_urlencoded(S) ->
|
|||||||
|
|
||||||
parse_urlencoded(<<$%, Hi, Lo, Tail/binary>>, Last, Cur,
|
parse_urlencoded(<<$%, Hi, Lo, Tail/binary>>, Last, Cur,
|
||||||
State) ->
|
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, Last, <<Cur/binary, Hex>>, State);
|
||||||
parse_urlencoded(<<$&, Tail/binary>>, _Last, Cur, key) ->
|
parse_urlencoded(<<$&, Tail/binary>>, _Last, Cur, key) ->
|
||||||
[{Cur, <<"">>} | parse_urlencoded(Tail,
|
[{Cur, <<"">>} | parse_urlencoded(Tail,
|
||||||
|
14
src/misc.erl
14
src/misc.erl
@ -278,25 +278,13 @@ url_encode(<<H:8, T/binary>>, Acc) when
|
|||||||
H == $: ->
|
H == $: ->
|
||||||
url_encode(T, <<Acc/binary, H>>);
|
url_encode(T, <<Acc/binary, H>>);
|
||||||
url_encode(<<H:8, T/binary>>, Acc) ->
|
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, Y] -> url_encode(T, <<Acc/binary, $%, X, Y>>);
|
||||||
[X] -> url_encode(T, <<Acc/binary, $%, $0, X>>)
|
[X] -> url_encode(T, <<Acc/binary, $%, $0, X>>)
|
||||||
end;
|
end;
|
||||||
url_encode(<<>>, Acc) ->
|
url_encode(<<>>, Acc) ->
|
||||||
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().
|
-spec set_node_id(string(), binary()) -> pid().
|
||||||
set_node_id(PidStr, NodeBin) ->
|
set_node_id(PidStr, NodeBin) ->
|
||||||
ExtPidStr = erlang:pid_to_list(
|
ExtPidStr = erlang:pid_to_list(
|
||||||
|
Loading…
Reference in New Issue
Block a user