[erlang-questions] Validating binaries

zxq9 zxq9@REDACTED
Tue Aug 11 17:14:38 CEST 2015


On 2015年8月11日 火曜日 10:01:12 Sean Cribbs wrote:
> This looks like a case where you could use a binary comprehension.
> 
> validate_lower_case_hex(Value, Length) when is_binary(Value),
>                                             byte_size(Value) == Length ->
>     Value == << <<C>> ||  <<C:8>> <= Value,
>                           (C >= $0 andalso C =< $9) orelse
>                           (C >= $a andalso C =< $f) >>;
> 
> validate_lower_case_hex(Value, _) when is_binary(Value) ->
>     false.

O.o

Neato!

-Craig



More information about the erlang-questions mailing list