@@ -677,18 +677,23 @@ defmodule Regex do
677677 << _ :: binary - size ( ^ offset ) , part :: binary - size ( ^ keep ) , match :: binary - size ( ^ length ) , _ :: binary >> =
678678 string
679679
680- if keep == 0 and trim do
681- [ match | do_split ( [ h | t ] , string , new_offset , counter - 1 , trim , true ) ]
682- else
683- [ part , match | do_split ( [ h | t ] , string , new_offset , counter - 1 , trim , true ) ]
680+ cond do
681+ keep == 0 and ( offset != 0 and length == 0 ) ->
682+ do_split ( [ h | t ] , string , new_offset , counter - 1 , trim , true )
683+
684+ keep == 0 and trim ->
685+ [ match | do_split ( [ h | t ] , string , new_offset , counter - 1 , trim , true ) ]
686+
687+ true ->
688+ [ part , match | do_split ( [ h | t ] , string , new_offset , counter - 1 , trim , true ) ]
684689 end
685690 end
686691
687692 defp do_split ( [ [ { pos , length } | h ] | t ] , string , offset , counter , trim , false ) do
688693 new_offset = pos + length
689694 keep = pos - offset
690695
691- if keep == 0 and trim do
696+ if keep == 0 and ( trim or ( offset != 0 and length == 0 ) ) do
692697 do_split ( [ h | t ] , string , new_offset , counter , trim , false )
693698 else
694699 << _ :: binary - size ( ^ offset ) , part :: binary - size ( ^ keep ) , _ :: binary >> = string
0 commit comments