Skip to content

Commit 68983eb

Browse files
authored
Merge pull request #13 from JuliaString/spj/v16fixes
Fix str_next and findfirst issues
2 parents 077b721 + 17a3df5 commit 68983eb

File tree

9 files changed

+76
-74
lines changed

9 files changed

+76
-74
lines changed

.drone.yml

+3-16
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,17 @@ steps:
1111
image: julia:1.5
1212
commands:
1313
- "julia --project=. --check-bounds=yes --color=yes -e 'using InteractiveUtils; versioninfo(verbose=true); using Pkg; Pkg.build(); Pkg.test(coverage=true)'"
14-
---
15-
kind: pipeline
16-
name: linux - arm64 - Julia 1.0
17-
18-
platform:
19-
os: linux
20-
arch: arm64
21-
22-
steps:
23-
- name: build
24-
image: julia:1.0
25-
commands:
26-
- "julia --project=. --check-bounds=yes --color=yes -e 'using InteractiveUtils; versioninfo(verbose=true); using Pkg; Pkg.build(); Pkg.test(coverage=true)'"
2714

2815
---
2916
kind: pipeline
30-
name: linux - arm - Julia 1.0
17+
name: linux - arm64 - Julia 1.6
3118

3219
platform:
3320
os: linux
34-
arch: arm
21+
arch: arm64
3522

3623
steps:
3724
- name: build
38-
image: julia:1.0
25+
image: julia:1.6
3926
commands:
4027
- "julia --project=. --check-bounds=yes --color=yes -e 'using InteractiveUtils; versioninfo(verbose=true); using Pkg; Pkg.build(); Pkg.test(coverage=true)'"

.github/workflows/ci.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: CI
2+
on:
3+
- push
4+
- pull_request
5+
jobs:
6+
test:
7+
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
8+
runs-on: ${{ matrix.os }}
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
version:
13+
- '1.5'
14+
- '1.6'
15+
- 'nightly'
16+
os:
17+
- ubuntu-latest
18+
- macOS-latest
19+
- windows-latest
20+
arch:
21+
- x64
22+
- x86
23+
exclude:
24+
- os: macOS-latest
25+
arch: x86
26+
steps:
27+
- uses: actions/checkout@v2
28+
- uses: julia-actions/setup-julia@v1
29+
with:
30+
version: ${{ matrix.version }}
31+
arch: ${{ matrix.arch }}
32+
- uses: actions/cache@v1
33+
env:
34+
cache-name: cache-artifacts
35+
with:
36+
path: ~/.julia/artifacts
37+
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
38+
restore-keys: |
39+
${{ runner.os }}-test-${{ env.cache-name }}-
40+
${{ runner.os }}-test-
41+
${{ runner.os }}-
42+
- uses: julia-actions/julia-buildpkg@v1
43+
- uses: julia-actions/julia-runtest@v1

.travis.yml

-34
This file was deleted.

Project.toml

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ authors = ["ScottPJones <[email protected]>"]
44
keywords = ["Strings"]
55
license = "MIT"
66
uuid = "e79e7a6a-7bb1-5a4d-9d64-da657b06f53a"
7-
version = "1.0.4"
7+
version = "1.0.5"
88

99
[deps]
1010
Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
@@ -24,9 +24,9 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
2424
test = ["Test", "Random"]
2525

2626
[compat]
27-
julia = "^1.0.0"
28-
ModuleInterfaceTools = "^1.0.0"
29-
MurmurHash3 = "^1.0.3"
30-
StrAPI = "^1.0.0"
31-
ChrBase = "^1.0.1"
32-
CharSetEncodings = "^1.0.0"
27+
julia = "1"
28+
ModuleInterfaceTools = "1"
29+
MurmurHash3 = "^1.2"
30+
StrAPI = "^1.1"
31+
ChrBase = "^1.0.3"
32+
CharSetEncodings = "1"

src/compare.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ end
5454
while pnt < fin
5555
str_done(b, pos) && return 1
5656
c1, pnt = _nextcp(C, pnt)
57-
ch, pos = str_next(b, pos)
57+
ch, pos = iterate(b, pos)
5858
c2 = ch%UInt32
5959
c1 == c2 || return ifelse(c1 < c2, -1, 1)
6060
end
@@ -93,7 +93,7 @@ function _cpeq(a::MaybeSub{T}, b) where {C<:CSE, T<:Str{C}}
9393
while pnt < fin
9494
str_done(b, pos) && return false
9595
c1, pnt = _nextcp(C, pnt)
96-
ch, pos = str_next(b, pos)
96+
ch, pos = iterate(b, pos)
9797
c1 == codepoint(ch) || return false
9898
end
9999
true

src/search.jl

+10-4
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ Base.findlast(a::Str, b::AbstractString) = nothing_sentinel(find(Last, a, b))
130130
Base.findnext(a::Str, b::AbstractString, i) = nothing_sentinel(find(Fwd, a, b, i))
131131
Base.findprev(a::Str, b::AbstractString, i) = nothing_sentinel(find(Rev, a, b, i))
132132

133+
# Fix ambiguities caused by addition of new findfirst definition to base
134+
Base.findfirst(a::AbstractChar, b::Str) = nothing_sentinel(find(First, a, b))
135+
Base.findlast(a::AbstractChar, b::Str) = nothing_sentinel(find(Last, a, b))
136+
Base.findnext(a::AbstractChar, b::Str, i) = nothing_sentinel(find(Fwd, a, b, i))
137+
Base.findprev(a::AbstractChar, b::Str, i) = nothing_sentinel(find(Rev, a, b, i))
138+
133139
function find(::Type{D}, fun::Function, str::AbstractString, pos::Integer) where {D<:Direction}
134140
pos < Int(D===Fwd) && (@boundscheck boundserr(str, pos); return 0)
135141
if pos > (len = ncodeunits(str))
@@ -189,7 +195,7 @@ function find(::Type{D}, needle::AbstractString, str::AbstractString,
189195
@inbounds is_valid(str, pos) || index_error(str, pos)
190196
(tlen = ncodeunits(needle)) == 0 && return pos:pos-1
191197
(cmp = CanContain(str, needle)) === NoCompare() && return _not_found
192-
@inbounds ch, nxt = str_next(needle, 1)
198+
@inbounds ch, nxt = iterate(needle, 1)
193199
is_valid(eltype(str), ch) || return _not_found
194200
# Check if single character
195201
if nxt > tlen
@@ -205,7 +211,7 @@ function find(::Type{T}, needle::AbstractString, str::AbstractString) where {T<:
205211
pos = T === First ? 1 : thisind(str, slen)
206212
(tlen = ncodeunits(needle)) == 0 && return pos:(pos-1)
207213
(cmp = CanContain(str, needle)) === NoCompare() && return _not_found
208-
@inbounds ch, nxt = str_next(needle, 1)
214+
@inbounds ch, nxt = iterate(needle, 1)
209215
is_valid(eltype(str), ch) || return _not_found
210216
# Check if single character
211217
if nxt > tlen
@@ -298,8 +304,8 @@ end
298304
"""Compare two strings, starting at nxtstr and nxtsub"""
299305
@inline function _cmp_str(str, strpos, endpos, sub, subpos, endsub)
300306
while strpos <= endpos
301-
c, strnxt = str_next(str, strpos)
302-
d, subpos = str_next(sub, subpos)
307+
c, strnxt = iterate(str, strpos)
308+
d, subpos = iterate(sub, subpos)
303309
c == d || break
304310
subpos > endsub && return strpos
305311
strpos = strnxt

src/support.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ function unsafe_check_string(str::T;
264264
totalchar = latin1byte = num2byte = num3byte = num4byte = invalids = 0
265265
pos = 1
266266
@inbounds while !str_done(str, pos)
267-
chr, nxt = str_next(str, pos)
267+
chr, nxt = iterate(str, pos)
268268
ch = chr%UInt32
269269
totalchar += 1
270270
if ch > 0x7f
@@ -288,7 +288,7 @@ function unsafe_check_string(str::T;
288288
break
289289
end
290290
# next character *must* be a trailing surrogate character
291-
chr, nxt = str_next(str, nxt)
291+
chr, nxt = iterate(str, nxt)
292292
if !is_surrogate_trail(chr)
293293
accept_invalids || strerror(StrErrors.NOT_TRAIL, pos, chr)
294294
invalids += 1

src/utf8.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,9 @@ _iterate(::MultiCU, ::Type{T}, str::SubString{<:Str{RawUTF8CSE}}, pos::Int) wher
387387
end
388388

389389
_next(::MultiCU, ::Type{T}, str::Str{RawUTF8CSE}, pos::Int) where {T} =
390-
str_next(str.data, pos)
390+
iterate(str.data, pos)
391391
_next(::MultiCU, ::Type{T}, str::SubString{<:Str{RawUTF8CSE}}, pos::Int) where {T} =
392-
str_next(SubString(str.string.data, str.offset + pos, str.offset + ncodeunits(str)), 1)
392+
iterate(SubString(str.string.data, str.offset + pos, str.offset + ncodeunits(str)), 1)
393393

394394
## overload methods for efficiency ##
395395

test/basic.jl

+7-7
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,8 @@ let
305305

306306
@test lastindex(srep) == 7
307307

308-
@test str_next(srep, 3) == ('β',5)
309-
@test str_next(srep, 7) == ('β',9)
308+
@test iterate(srep, 3) == ('β',5)
309+
@test iterate(srep, 7) == ('β',9)
310310

311311
@test srep[7] == 'β'
312312
@test_throws StringIndexError srep[8]
@@ -340,8 +340,8 @@ end
340340
@test_throws MethodError codeunit(tstr, true)
341341
@test_throws MethodError isvalid(tstr, 1)
342342
@test_throws MethodError isvalid(tstr, true)
343-
@test_throws MethodError str_next(tstr, 1)
344-
@test_throws MethodError str_next(tstr, true)
343+
@test_throws MethodError iterate(tstr, 1)
344+
@test_throws MethodError iterate(tstr, true)
345345
@test_throws MethodError lastindex(tstr)
346346

347347
gstr = GenericString("12")
@@ -611,7 +611,7 @@ end
611611
for st in ("Hello", "Σ", "こんにちは", "😊😁")
612612
local s
613613
s = ST(st)
614-
@test str_next(s, lastindex(s))[2] > sizeof(s)
614+
@test iterate(s, lastindex(s))[2] > sizeof(s)
615615
@test nextind(s, lastindex(s)) > sizeof(s)
616616
end
617617
end
@@ -915,7 +915,7 @@ function testbin(::Type{ST}) where {ST}
915915
b"\xf8\x9f\x98\x84", b"\xf8\x9f\x98\x84z")),
916916
s in lst
917917
st = ST(s)
918-
@test str_next(st, 1)[2] == 2
918+
@test iterate(st, 1)[2] == 2
919919
@test nextind(st, 1) == 2
920920
end
921921

@@ -930,7 +930,7 @@ function testbin(::Type{ST}) where {ST}
930930
(s, r) in lst
931931
st = ST(s)
932932
(ST === BinaryStr || ST === Text1Str) && (r = 2)
933-
@test str_next(st, 1)[2] == r
933+
@test iterate(st, 1)[2] == r
934934
@test nextind(st, 1) == r
935935
end
936936
end

0 commit comments

Comments
 (0)