-
-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add find(first|last|next|prev) methods that return nothing #513
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1498,6 +1498,7 @@ else | |
export occursin | ||
|
||
zero2nothing(x::Integer) = x == 0 ? nothing : x | ||
zero2nothing(x::AbstractUnitRange{<:Integer}) = x == 0:-1 ? nothing : x | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO that would be harder to read for no real advantage. Also I think the compiler is smart enough to avoid branches were it's faster even if you use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fine, no big deal either way. |
||
zero2nothing(x) = x | ||
|
||
findnext(xs...) = zero2nothing(Base.findnext(xs...)) | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1378,18 +1378,19 @@ for (f1, f2, i) in ((Compat.findfirst, Compat.findnext, 1), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@test f2(occursin(chars), "bx", i) == f1(occursin(chars), "bx") == nothing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
for (f1, f2, i) in ((findfirst, findnext, 1), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should keep testing the unprefix methods as Compat provides a few ones (which do not return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But they return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, OK. Should probably have a version-specific test then, as long as we provide these methods via There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the point in providing Compat methods which do not behave like 0.7 though? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess none of Lines 1508 to 1540 in fd3b92a
should extend the Base functions. I think we should deprecate those and require Compat.find* such that people have the 0.7 behaviour w.r.t nothing ?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't get it, now we basically just provide another 0.6 interface to those functions. So the options here are 1. deprecate those to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't 2. already work? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea you are right, it does, but I still think it is confusing. The Base extended methods are only useful on 0.6, at which point you might use the 0.6 syntax (e.g. with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I'm not saying they are really useful, but that deprecating them is more trouble than it's worth. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(findlast, findprev, 2), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(Compat.findfirst, Compat.findnext, 1), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(Compat.findlast, Compat.findprev, 2)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@test f2("a", "ba", i) == f1("a", "ba") == 2:2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@test f2("z", "ba", i) == f1("z", "ba") == 0:-1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
for (f1, f2, i) in ((findfirst, findnext, 1), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(Compat.findfirst, Compat.findnext, 1)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@test f2(r"a", "ba", 1) == f1(r"a", "ba") == 2:2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@test f2(r"z", "ba", 1) == f1(r"z", "ba") == 0:-1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@test findnext("a", "ba", 1) == findfirst("a", "ba") == 2:2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@test findnext("z", "ba", 1) == findfirst("z", "ba") == (VERSION < v"0.7.0-DEV.4480" ? (0:-1) : nothing) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@test findprev("a", "ba", 2) == findlast("a", "ba") == 2:2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@test findprev("z", "ba", 2) == findlast("z", "ba") == (VERSION < v"0.7.0-DEV.4480" ? (0:-1) : nothing) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@test Compat.findnext("a", "ba", 1) == Compat.findfirst("a", "ba") == 2:2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@test Compat.findnext("z", "ba", 1) == Compat.findfirst("z", "ba") == nothing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@test Compat.findprev("a", "ba", 2) == Compat.findlast("a", "ba") == 2:2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@test Compat.findprev("z", "ba", 2) == Compat.findlast("z", "ba") == nothing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@test findnext(r"a", "ba", 1) == findfirst(r"a", "ba") == 2:2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@test findnext(r"z", "ba", 1) == findfirst(r"z", "ba") == (VERSION < v"0.7.0-DEV.4480" ? (0:-1) : nothing) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@test Compat.findnext(r"a", "ba", 1) == Compat.findfirst(r"a", "ba") == 2:2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@test Compat.findnext(r"z", "ba", 1) == Compat.findfirst(r"z", "ba") == nothing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@test Compat.findfirst(equalto(UInt8(0)), IOBuffer(UInt8[1, 0])) == 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@test Compat.findfirst(equalto(UInt8(9)), IOBuffer(UInt8[1, 0])) == nothing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use
isempty
just in case?