Skip to content

Commit

Permalink
fixup! Polish documentation for the binary module
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorng committed Mar 6, 2025
1 parent 9c049fd commit 1482d40
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions lib/stdlib/src/binary.erl
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ first(_) ->
Returns the last byte of binary `Subject` as an integer.

If the size of `Subject` is zero, a `badarg` exception is raised.

a
## Examples

```erlang
Expand Down Expand Up @@ -467,17 +467,6 @@ position and length.
The function returns `{Pos, Length}` for the binary in `Pattern`, starting at
the lowest position in `Subject`.

## Examples

```erlang
> binary:match(<<"abcde">>, [<<"bcde">>, <<"cd">>],[]).
{1,4}
```

Even though `<<"cd">>` ends before `<<"bcde">>`, `<<"bcde">>` begins first and
is therefore the first match. If two overlapping matches begin at the same
position, the longest is returned.

Summary of the options:

- **\{scope, \{Start, Length\}\}** - Only the specified part is searched. Return
Expand All @@ -491,6 +480,22 @@ For a description of `Pattern`, see function `compile_pattern/1`.
If `{scope, {Start,Length}}` is specified in the options such that `Start` >
size of `Subject`, `Start` \+ `Length` < 0 or `Start` \+ `Length` > size of
`Subject`, a `badarg` exception is raised.

## Examples

```erlang
> binary:match(<<"abcde">>, [<<"bcde">>, <<"cd">>],[]).
{1,4}
```

Even though `<<"cd">>` ends before `<<"bcde">>`, `<<"bcde">>` begins first and
is therefore the first match. If two overlapping matches begin at the same
position, the longest is returned.

```erlang
> binary:match(~"the rain in spain", ~"ain", []).
{5,3}
```
""".
-doc(#{since => <<"OTP R14B">>}).
-spec match(Subject, Pattern, Options) -> Found | nomatch when
Expand Down Expand Up @@ -531,7 +536,7 @@ the following example:
The result shows that <<"bcde">> is selected instead of the shorter match
<<"bc">> (which would have given raise to one more match, <<"de">>). This
corresponds to the behavior of POSIX regular expressions (and programs like
awk), but is not consistent with alternative matches in `re` (and Perl), where
`awk`), but is not consistent with alternative matches in `re` (and Perl), where
instead lexical ordering in the search pattern selects which string matches.

If none of the strings in a pattern is found, an empty list is returned.
Expand All @@ -542,6 +547,13 @@ available options, see `match/3`.
If `{scope, {Start,Length}}` is specified in the options such that `Start` >
size of `Subject`, `Start + Length` < 0 or `Start + Length` is > size of
`Subject`, a `badarg` exception is raised.

## Examples

```erlang
> binary:matches(~"the rain in spain", ~"ai", []).
[{5,2},{14,2}]
```
""".
-doc(#{since => <<"OTP R14B">>}).
-spec matches(Subject, Pattern, Options) -> Found when
Expand Down

0 comments on commit 1482d40

Please sign in to comment.