-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bounds check thisind, nextind and prevind as well
- Loading branch information
1 parent
feb1f68
commit 8de25f5
Showing
8 changed files
with
168 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,14 +92,12 @@ function ==(a::String, b::String) | |
al == sizeof(b) && 0 == ccall(:memcmp, Int32, (Ptr{UInt8}, Ptr{UInt8}, UInt), a, b, al) | ||
end | ||
|
||
## thisind, nextind, prevind ## | ||
|
||
thisind(s::String, i::Integer) = oftype(i, thisind(s, Int(i))) | ||
nextind(s::String, i::Integer) = oftype(i, nextind(s, Int(i))) | ||
## thisind, prevind, nextind ## | ||
|
||
function thisind(s::String, i::Int) | ||
n = ncodeunits(s) | ||
between(i, 2, n) || return i | ||
i == n + 1 && return i | ||
@boundscheck between(i, 0, n) || throw(BoundsError(s, i)) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
samoconnor
Contributor
|
||
@inbounds b = codeunit(s, i) | ||
b & 0xc0 == 0x80 || return i | ||
@inbounds b = codeunit(s, i-1) | ||
|
@@ -114,8 +112,9 @@ function thisind(s::String, i::Int) | |
end | ||
|
||
function nextind(s::String, i::Int) | ||
i == 0 && return 1 | ||
n = ncodeunits(s) | ||
between(i, 1, n-1) || return i+1 | ||
@boundscheck between(i, 1, n) || throw(BoundsError(s, i)) | ||
@inbounds l = codeunit(s, i) | ||
(l < 0x80) | (0xf8 ≤ l) && return i+1 | ||
if l < 0xc0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
@StefanKarpinski does this boundscheck make the one in
isvalid
redundant?