summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Wragg <dpw@lshift.net>2010-04-30 12:25:45 +0100
committerDavid Wragg <dpw@lshift.net>2010-04-30 12:25:45 +0100
commita4b80f1c9576b23837aa7c47b5df35170eee6ab8 (patch)
treeb00e02c8480de135f4165769beb426fc281da950 /src
parentdc4f18c5b3ea2198d4fd04902354349b20ed5604 (diff)
downloadrabbitmq-server-git-a4b80f1c9576b23837aa7c47b5df35170eee6ab8.tar.gz
Take advantage of R12's re in rabbit_misc:string_to_pid
Diffstat (limited to 'src')
-rw-r--r--src/rabbit_misc.erl50
1 files changed, 9 insertions, 41 deletions
diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl
index 2c1808465f..33b9b64511 100644
--- a/src/rabbit_misc.erl
+++ b/src/rabbit_misc.erl
@@ -537,51 +537,19 @@ pid_to_string(Pid) when is_pid(Pid) ->
%% inverse of above
string_to_pid(Str) ->
- ErrorFun = fun () -> throw({error, {invalid_pid_syntax, Str}}) end,
- %% TODO: simplify this code by using the 're' module, once we drop
- %% support for R11
- %%
- %% 1) sanity check
%% The \ before the trailing $ is only there to keep emacs
%% font-lock from getting confused.
- case regexp:first_match(Str, "^<.*\\.[0-9]+\\.[0-9]+>\$") of
- {match, _, _} ->
- %% 2) strip <>
- Str1 = string:substr(Str, 2, string:len(Str) - 2),
- %% 3) extract three constituent parts, taking care to
- %% handle dots in the node part (hence the reverse and concat)
- [SerStr, IdStr | Rest] = lists:reverse(string:tokens(Str1, ".")),
- NodeStr = lists:concat(lists:reverse(Rest)),
- %% 4) construct a triple term from the three parts
- TripleStr = lists:flatten(io_lib:format("{~s,~s,~s}.",
- [NodeStr, IdStr, SerStr])),
- %% 5) parse the triple
- Tokens = case erl_scan:string(TripleStr) of
- {ok, Tokens1, _} -> Tokens1;
- {error, _, _} -> ErrorFun()
- end,
- Term = case erl_parse:parse_term(Tokens) of
- {ok, Term1} -> Term1;
- {error, _} -> ErrorFun()
- end,
- {Node, Id, Ser} =
- case Term of
- {Node1, Id1, Ser1} when is_atom(Node1) andalso
- is_integer(Id1) andalso
- is_integer(Ser1) ->
- Term;
- _ ->
- ErrorFun()
- end,
- %% 6) turn the triple into a pid - see pid_to_string
- <<131,NodeEnc/binary>> = term_to_binary(Node),
+ case re:run(Str, "^<(.*)\\.([0-9]+)\\.([0-9]+)>\$",
+ [{capture,all_but_first,list}]) of
+ {match, [NodeStr, IdStr, SerStr]} ->
+ %% turn the triple into a pid - see pid_to_string
+ <<131,NodeEnc/binary>> = term_to_binary(list_to_atom(NodeStr)),
+ Id = list_to_integer(IdStr),
+ Ser = list_to_integer(SerStr),
binary_to_term(<<131,103,NodeEnc/binary,Id:32,Ser:32,0:8>>);
nomatch ->
- ErrorFun();
- Error ->
- %% invalid regexp - shouldn't happen
- throw(Error)
- end.
+ throw({error, {invalid_pid_syntax, Str}})
+ end.
version_compare(A, B, lte) ->
case version_compare(A, B) of