Skip to content
Browse files

Allow spaceless strings in from_str/2

  • Loading branch information...
1 parent 334a314 commit b080744bd508a2d23b6908c9e94ae13fcfcd976d @aerosol aerosol committed Nov 8, 2011
Showing with 7 additions and 4 deletions.
  1. +7 −4 src/binpp.erl
View
11 src/binpp.erl
@@ -77,10 +77,13 @@ cmprint(Bin1, Bin2) when is_binary(Bin1) orelse is_bitstring(Bin1),
-spec from_str(string(), hex) -> binary().
from_str(Str, hex) when is_list(Str) ->
- Bytes = string:tokens(Str, " "),
- list_to_binary(lists:map(fun(Byte) ->
- list_to_integer(Byte, 16)
- end, Bytes)).
+ case lists:member($ , Str) of
+ true ->
+ Bytes = string:tokens(Str, " ");
+ false when length(Str) rem 2 =:= 0 ->
+ Bytes = buckets(2, Str)
+ end,
+ list_to_binary([ list_to_integer(B,16) || B <- Bytes]).
-spec from_str(string()) -> binary().

0 comments on commit b080744

Please sign in to comment.
Something went wrong with that request. Please try again.