[erlang-questions] binary:part/2/3

41 views
Skip to first unread message

Zabrane Mickael

unread,
Aug 13, 2012, 1:52:15 PM8/13/12
to Erlang Questions
Hi guys,

I'd like to know if the binary returned by "binary:part/2/3" (http://www.erlang.org/doc/man/binary.html#part-2)
is always referencing Subject (i.e a sub-binary) or not?

The doc is clear about this fact for "binary:split/2/3" but nothing is mentionned for "binary:part/2/3".

Regards,
Zabrane

Jesper Louis Andersen

unread,
Aug 14, 2012, 5:54:30 AM8/14/12
to Zabrane Mickael, Erlang Questions
Try looking at the source. If I remember correctly, binary:split uses binary:part inside. If this is the case, then you can update the documentation as well to reflect the fact.

Jesper Louis Andersen
Erlang Solutions Ltd., Copenhagen
> _______________________________________________
> erlang-questions mailing list
> erlang-q...@erlang.org
> http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
erlang-q...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions

Zabrane Mickael

unread,
Aug 14, 2012, 6:10:29 AM8/14/12
to Jesper Louis Andersen, Erlang Questions
Hi Jesper,

You're right. From "binary.erl" source code:

[..]
split(Haystack,Needles,Options) ->
...
do_split(Haystack,MList,0,Trim)
...


do_split(H,[],N,true) when N >= byte_size(H) ->
[];
do_split(H,[],N,_) ->
[binary:part(H,{N,byte_size(H)-N})]; <---- HERE
do_split(H,[{A,B}|T],N,Trim) ->
case binary:part(H,{N,A-N}) of <---- HERE
...

So yes, binary:split uses binary:part for sure.

Can OTP guys confirm this fact now?

Regards,
Zabrane
Reply all
Reply to author
Forward
0 new messages