On Thursday, October 11, 2018 at 10:50:50 PM UTC+2, Francois Vogel wrote:
> Regarding the expected result of '.t search -all "" 1.0', I proposed to
> return the same result as '.t search "" 1.0'. This seemed more logical
> to me than returning an error (ugly!) or the empty string (wrong!).
Empty string is definitely wrong, it is an empty list if this was chosen for -all.
> Indeed search results with the -all switch should contain search results
> without this switch.
+1
> Now, when
> the -all switch is added, I choose to return that same start index
> rather than nothing or throwing and error out.
regexp, that is mentioned as reference in the documentation of search -all, returns *all* matches for the empty pattern. However, string first returns -1.
My guts feeling says, that there is no exact match for the empty string, but many matches for the empty regexp pattern. On the other hand, fixing this bug should not modify the behavior of search without -all.
Conclusion imho: return all indices (with and without -regexp).
> Now, in the special case when the text widget is empty there is no
> difference: '.t search -all "" 1.0' returns the same result as '.t
> search "" 1.0' (and this result is "1.0").
side note: when I init text as in your minimal example, it is not empty but contains a newline character {1 == [.t count -chars 1.0 end]}.
<nitpicking>
regexp matches the empty string at the start of the empty string, but not the empty string at the end of a non-empty string. This might also be debatable.
expect:~$ regexp -all -inline "" ""
{}
expect:~$ regexp -all -inline "" "a"
{}
expect:~$ regexp -all -inline "" "ab"
{} {}