-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Make getindex for String check if indices are valid #22572
Changes from 3 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 |
---|---|---|
|
@@ -11,7 +11,11 @@ function completes_global(x, name) | |
end | ||
|
||
function appendmacro!(syms, macros, needle, endchar) | ||
append!(syms, s[2:end-sizeof(needle)]*endchar for s in filter(x -> endswith(x, needle), macros)) | ||
r = Regex("^.(.*)$needle\$") | ||
for s in macros | ||
m = match(r, s) | ||
m === nothing || push!(syms, m[1]*endchar) | ||
end | ||
end | ||
|
||
function filtered_mod_names(ffunc::Function, mod::Module, name::AbstractString, all::Bool=false, imported::Bool=false) | ||
|
@@ -482,9 +486,11 @@ function completions(string, pos) | |
paths, r, success = complete_path(replace(string[r], r"\\ ", " "), pos) | ||
|
||
if inc_tag == :string && | ||
length(paths) == 1 && # Only close if there's a single choice, | ||
!isdir(expanduser(replace(string[startpos:start(r)-1] * paths[1], r"\\ ", " "))) && # except if it's a directory | ||
(length(string) <= pos || string[pos+1] != '"') # or there's already a " at the cursor. | ||
length(paths) == 1 && # Only close if there's a single choice, | ||
!isdir(expanduser(replace(string[startpos:prevind(string, start(r))] * paths[1], | ||
r"\\ ", " "))) && # except if it's a directory | ||
(length(string) <= pos || | ||
string[nextind(string,pos)] != '"') # or there's already a " at the cursor. | ||
paths[1] *= "\"" | ||
end | ||
|
||
|
@@ -534,10 +540,11 @@ function completions(string, pos) | |
# <Mod>/src/<Mod>.jl | ||
# <Mod>.jl/src/<Mod>.jl | ||
if isfile(joinpath(dir, pname)) | ||
endswith(pname, ".jl") && push!(suggestions, pname[1:end-3]) | ||
endswith(pname, ".jl") && push!(suggestions, | ||
pname[1:prevind(pname, end-2)]) | ||
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. This should have been OK, since we know the three last characters are ASCII. 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. Unfortunately not:
I can 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. OK, carry on, I need to learn how to count up to three. :-) |
||
else | ||
mod_name = if endswith(pname, ".jl") | ||
pname[1:end - 3] | ||
pname[1:prevind(pname, end-2)] | ||
else | ||
pname | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -235,20 +235,25 @@ isvalid(s::String, i::Integer) = | |
|
||
function getindex(s::String, r::UnitRange{Int}) | ||
isempty(r) && return "" | ||
i, j = first(r), last(r) | ||
l = sizeof(s) | ||
i = first(r) | ||
if i < 1 || i > l | ||
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. Just a styling issue, but I don't see the point of changing these from |
||
throw(BoundsError(s, i)) | ||
end | ||
@inbounds si = codeunit(s, i) | ||
if is_valid_continuation(si) | ||
throw(UnicodeError(UTF_ERR_INVALID_INDEX, i, si)) | ||
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. Better continue throwing a |
||
end | ||
j = last(r) | ||
if j > l | ||
throw(BoundsError()) | ||
throw(BoundsError(s, j)) | ||
end | ||
j = nextind(s,j)-1 | ||
unsafe_string(pointer(s,i), j-i+1) | ||
@inbounds sj = codeunit(s, j) | ||
if is_valid_continuation(sj) | ||
throw(UnicodeError(UTF_ERR_INVALID_INDEX, j, sj)) | ||
end | ||
j = nextind(s,j) | ||
unsafe_string(pointer(s,i), j-i) | ||
end | ||
|
||
function search(s::String, c::Char, i::Integer = 1) | ||
|
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.
Perhaps
Regex("^.(.*)\\Q$needle\\E\$")
since you don't want special characters to have special interpretation?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.
Sure :). I will fix after I am sure that CI goes through correcty (as it seems now will go through without errors).
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.
The CI looks fine now, failures are unrelated.