diff options
author | Patrik Nyblom <[email protected]> | 2010-04-28 20:26:46 +0200 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2010-05-17 15:51:50 +0200 |
commit | 02af6209ed16b8588b76e8c1972000eee12ba225 (patch) | |
tree | ce624079dd3e65138b90f43b21674b6fff72cf7d /lib/stdlib/test/binref.erl | |
parent | 9d2fe9d9af19ab94ff3feb1e7b9ffd83fa6927ff (diff) | |
download | otp-02af6209ed16b8588b76e8c1972000eee12ba225.tar.gz otp-02af6209ed16b8588b76e8c1972000eee12ba225.tar.bz2 otp-02af6209ed16b8588b76e8c1972000eee12ba225.zip |
Add bin_to_list/{1,2,3}
Add testcases for bin_to_list.
Teach binref.erl bin_to_list.
Diffstat (limited to 'lib/stdlib/test/binref.erl')
-rw-r--r-- | lib/stdlib/test/binref.erl | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/lib/stdlib/test/binref.erl b/lib/stdlib/test/binref.erl index e98b1b2bc8..e09a0f2743 100644 --- a/lib/stdlib/test/binref.erl +++ b/lib/stdlib/test/binref.erl @@ -4,7 +4,7 @@ split/2,split/3,replace/3,replace/4,first/1,last/1,at/2, part/2,part/3,copy/1,copy/2,encode_unsigned/1,encode_unsigned/2, decode_unsigned/1,decode_unsigned/2,referenced_byte_size/1, - longest_common_prefix/1,longest_common_suffix/1 ]). + longest_common_prefix/1,longest_common_suffix/1,bin_to_list/1, bin_to_list/2, bin_to_list/3 ]). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -318,6 +318,39 @@ at(Subject,X) -> erlang:error(badarg) end. +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% bin_to_list +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +bin_to_list(Subject) -> + try + binary_to_list(Subject) + catch + _:_ -> + erlang:error(badarg) + end. + +bin_to_list(Subject,T) -> + try + {A0,B0} = T, + {A,B} = if + B0 < 0 -> + {A0+B0,-B0}; + true -> + {A0,B0} + end, + binary_to_list(Subject,A+1,A+B) + catch + _:_ -> + erlang:error(badarg) + end. + +bin_to_list(Subject,A,B) -> + try + bin_to_list(Subject,{A,B}) + catch + _:_ -> + erlang:error(badarg) + end. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% longest_common_prefix |