Packages

Efficiently slice prefixes from strings. Good for parsers!

Current section

Files

Jump to
splitter src splitter_ffi.erl
Raw

src/splitter_ffi.erl

-module(splitter_ffi).
-export([new/1, split/2]).
new([]) ->
empty_splitter;
new(Patterns) ->
binary:compile_pattern(Patterns).
split(empty_splitter, String) ->
{<<>>, <<>>, String};
split(Splitter, String) ->
case binary:match(String, Splitter) of
nomatch -> {String, <<"">>, <<"">>}; % No delimiter found
{Index, Length} ->
{binary:part(String, 0, Index),
binary:part(String, Index, Length),
binary:part(String, Index + Length, byte_size(String) - Index - Length)}
end.