Skip to content

Commit

Permalink
quote_plus is now exported by mochiweb_util, removed copied code
Browse files Browse the repository at this point in the history
  • Loading branch information
Maas-Maarten Zeeman committed Sep 5, 2011
1 parent c9381be commit 5819442
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions src/support/z_utils.erl
Expand Up @@ -222,9 +222,11 @@ depickle(Data, Context) ->

%%% URL ENCODE %%%

url_encode(S) -> quote_plus(S).
url_encode(S) ->
%% @todo possible speedups for binaries
mochiweb_util:quote_plus(S).

% quote_plus and hexdigit are from Mochiweb.
% hexdigit is from Mochiweb.

-define(PERCENT, 37). % $\%
-define(FULLSTOP, 46). % $\.
Expand All @@ -237,24 +239,6 @@ url_encode(S) -> quote_plus(S).
hexdigit(C) when C < 10 -> $0 + C;
hexdigit(C) when C < 16 -> $A + (C - 10).

quote_plus(Atom) when is_atom(Atom) ->
quote_plus(atom_to_list(Atom));
quote_plus(Int) when is_integer(Int) ->
quote_plus(integer_to_list(Int));
quote_plus(String) ->
quote_plus(String, []).

quote_plus([], Acc) ->
lists:reverse(Acc);
quote_plus([C | Rest], Acc) when ?QS_SAFE(C) ->
quote_plus(Rest, [C | Acc]);
quote_plus([$\s | Rest], Acc) ->
quote_plus(Rest, [$+ | Acc]);
quote_plus([C | Rest], Acc) ->
<<Hi:4, Lo:4>> = <<C>>,
quote_plus(Rest, [hexdigit(Lo), hexdigit(Hi), ?PERCENT | Acc]).


%%% URL PATH ENCODE %%%

%% url spec for path part
Expand Down

0 comments on commit 5819442

Please sign in to comment.