diff options
author | Hans Bolinder <[email protected]> | 2011-05-13 14:04:23 +0200 |
---|---|---|
committer | Hans Bolinder <[email protected]> | 2011-05-13 14:04:23 +0200 |
commit | 22f3c9720cb7d19a3aafac613f03aede91d6283f (patch) | |
tree | bc0961a8b4d9377d5e0e19204061f9d12e0ed4a9 /lib/stdlib/src/binary.erl | |
parent | 8c3a2a93b6b60253faa8397e5a02206b882b811f (diff) | |
parent | 76ca320fd37cecdcf225ddcc094bc72a607b0453 (diff) | |
download | otp-22f3c9720cb7d19a3aafac613f03aede91d6283f.tar.gz otp-22f3c9720cb7d19a3aafac613f03aede91d6283f.tar.bz2 otp-22f3c9720cb7d19a3aafac613f03aede91d6283f.zip |
Merge branch 'hb/stdlib/specs/OTP-9267' into dev
* hb/stdlib/specs/OTP-9267:
Types and specifications have been modified and added
Conflicts:
lib/stdlib/src/timer.erl
Diffstat (limited to 'lib/stdlib/src/binary.erl')
-rw-r--r-- | lib/stdlib/src/binary.erl | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/lib/stdlib/src/binary.erl b/lib/stdlib/src/binary.erl index f6489788b2..cb1e12ae46 100644 --- a/lib/stdlib/src/binary.erl +++ b/lib/stdlib/src/binary.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2010. All Rights Reserved. +%% Copyright Ericsson AB 2010-2011. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -38,11 +38,28 @@ %% Implemented in this module: -export([split/2,split/3,replace/3,replace/4]). +-opaque cp() :: tuple(). +-type part() :: {Start :: non_neg_integer(), Length :: integer()}. + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% split %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +-spec split(Subject, Pattern) -> Parts when + Subject :: binary(), + Pattern :: binary() | [binary()] | cp(), + Parts :: [binary()]. + split(H,N) -> split(H,N,[]). + +-spec split(Subject, Pattern, Options) -> Parts when + Subject :: binary(), + Pattern :: binary() | [binary()] | cp(), + Options :: [Option], + Option :: {scope, part()} | trim | global, + Parts :: [binary()]. + split(Haystack,Needles,Options) -> try {Part,Global,Trim} = get_opts_split(Options,{no,false,false}), @@ -89,8 +106,26 @@ do_split(H,[{A,B}|T],N,Trim) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% replace %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +-spec replace(Subject, Pattern, Replacement) -> Result when + Subject :: binary(), + Pattern :: binary() | [ binary() ] | cp(), + Replacement :: binary(), + Result :: binary(). + replace(H,N,R) -> replace(H,N,R,[]). + +-spec replace(Subject, Pattern, Replacement, Options) -> Result when + Subject :: binary(), + Pattern :: binary() | [ binary() ] | cp(), + Replacement :: binary(), + Options :: [Option], + Option :: global | {scope, part()} | {insert_replaced, InsPos}, + InsPos :: OnePos | [ OnePos ], + OnePos :: non_neg_integer(), + Result :: binary(). + replace(Haystack,Needles,Replacement,Options) -> try true = is_binary(Replacement), % Make badarg instead of function clause |