From 74c2a9db0caa376ea375614fcc67c3a9295737d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Dimitrov?= Date: Fri, 3 Nov 2017 10:07:12 +0100 Subject: stdlib: Refactor functions in uri_string --- lib/stdlib/src/uri_string.erl | 111 +++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 61 deletions(-) diff --git a/lib/stdlib/src/uri_string.erl b/lib/stdlib/src/uri_string.erl index b8e0432fd6..f4acf1885d 100644 --- a/lib/stdlib/src/uri_string.erl +++ b/lib/stdlib/src/uri_string.erl @@ -366,9 +366,9 @@ transcode(URIString, Options) when is_binary(URIString) -> try InEnc = proplists:get_value(in_encoding, Options, utf8), OutEnc = proplists:get_value(out_encoding, Options, utf8), - List = convert_list(URIString, InEnc), + List = convert_to_list(URIString, InEnc), Output = transcode(List, [], InEnc, OutEnc), - convert_binary(Output, utf8, OutEnc) + convert_to_binary(Output, utf8, OutEnc) catch throw:{error, Atom, RestData} -> {error, Atom, RestData} end; @@ -421,7 +421,7 @@ compose_query([{Key,Value}|Rest], Options, IsList, Acc) -> compose_query(Rest, Options, IsListNew, < - normalize_http(Map, Port, Path); - <<"http">> -> - normalize_http(Map, Port, Path); - "https" -> - normalize_https(Map, Port, Path); - <<"https">> -> - normalize_https(Map, Port, Path); - "ftp" -> - normalize_ftp(Map, Port); - <<"ftp">> -> - normalize_ftp(Map, Port); - "ssh" -> - normalize_ssh_sftp(Map, Port); - <<"ssh">> -> - normalize_ssh_sftp(Map, Port); - "sftp" -> - normalize_ssh_sftp(Map, Port); - <<"sftp">> -> - normalize_ssh_sftp(Map, Port); - "tftp" -> - normalize_tftp(Map, Port); - <<"tftp">> -> - normalize_tftp(Map, Port); - _Else -> Map - end. + normalize_scheme_based(Map, Scheme, Port, Path). +%% +normalize_scheme_based(Map, Scheme, Port, Path) + when Scheme =:= "http"; Scheme =:= <<"http">> -> + normalize_http(Map, Port, Path); +normalize_scheme_based(Map, Scheme, Port, Path) + when Scheme =:= "https"; Scheme =:= <<"https">> -> + normalize_https(Map, Port, Path); +normalize_scheme_based(Map, Scheme, Port, _Path) + when Scheme =:= "ftp"; Scheme =:= <<"ftp">> -> + normalize_ftp(Map, Port); +normalize_scheme_based(Map, Scheme, Port, _Path) + when Scheme =:= "ssh"; Scheme =:= <<"ssh">> -> + normalize_ssh_sftp(Map, Port); +normalize_scheme_based(Map, Scheme, Port, _Path) + when Scheme =:= "sftp"; Scheme =:= <<"sftp">> -> + normalize_ssh_sftp(Map, Port); +normalize_scheme_based(Map, Scheme, Port, _Path) + when Scheme =:= "tftp"; Scheme =:= <<"tftp">> -> + normalize_tftp(Map, Port); +normalize_scheme_based(Map, _, _, _) -> + Map. normalize_http(Map, Port, Path) -> -- cgit v1.2.3