From 228968bae8a74cfc7442448330c9fcc3091490d7 Mon Sep 17 00:00:00 2001 From: ScottPJones Date: Thu, 13 May 2021 11:54:24 -0400 Subject: [PATCH 1/2] Fix str_next and findfirst issues --- src/compare.jl | 4 ++-- src/search.jl | 14 ++++++++++---- src/support.jl | 4 ++-- src/utf8.jl | 4 ++-- test/basic.jl | 14 +++++++------- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/compare.jl b/src/compare.jl index 7b60f06..a7ab04a 100644 --- a/src/compare.jl +++ b/src/compare.jl @@ -54,7 +54,7 @@ end while pnt < fin str_done(b, pos) && return 1 c1, pnt = _nextcp(C, pnt) - ch, pos = str_next(b, pos) + ch, pos = iterate(b, pos) c2 = ch%UInt32 c1 == c2 || return ifelse(c1 < c2, -1, 1) end @@ -93,7 +93,7 @@ function _cpeq(a::MaybeSub{T}, b) where {C<:CSE, T<:Str{C}} while pnt < fin str_done(b, pos) && return false c1, pnt = _nextcp(C, pnt) - ch, pos = str_next(b, pos) + ch, pos = iterate(b, pos) c1 == codepoint(ch) || return false end true diff --git a/src/search.jl b/src/search.jl index a5ac2e8..2d9d0b5 100644 --- a/src/search.jl +++ b/src/search.jl @@ -130,6 +130,12 @@ Base.findlast(a::Str, b::AbstractString) = nothing_sentinel(find(Last, a, b)) Base.findnext(a::Str, b::AbstractString, i) = nothing_sentinel(find(Fwd, a, b, i)) Base.findprev(a::Str, b::AbstractString, i) = nothing_sentinel(find(Rev, a, b, i)) +# Fix ambiguities caused by addition of new findfirst definition to base +Base.findfirst(a::AbstractChar, b::Str) = nothing_sentinel(find(First, a, b)) +Base.findlast(a::AbstractChar, b::Str) = nothing_sentinel(find(Last, a, b)) +Base.findnext(a::AbstractChar, b::Str, i) = nothing_sentinel(find(Fwd, a, b, i)) +Base.findprev(a::AbstractChar, b::Str, i) = nothing_sentinel(find(Rev, a, b, i)) + function find(::Type{D}, fun::Function, str::AbstractString, pos::Integer) where {D<:Direction} pos < Int(D===Fwd) && (@boundscheck boundserr(str, pos); return 0) if pos > (len = ncodeunits(str)) @@ -189,7 +195,7 @@ function find(::Type{D}, needle::AbstractString, str::AbstractString, @inbounds is_valid(str, pos) || index_error(str, pos) (tlen = ncodeunits(needle)) == 0 && return pos:pos-1 (cmp = CanContain(str, needle)) === NoCompare() && return _not_found - @inbounds ch, nxt = str_next(needle, 1) + @inbounds ch, nxt = iterate(needle, 1) is_valid(eltype(str), ch) || return _not_found # Check if single character if nxt > tlen @@ -205,7 +211,7 @@ function find(::Type{T}, needle::AbstractString, str::AbstractString) where {T<: pos = T === First ? 1 : thisind(str, slen) (tlen = ncodeunits(needle)) == 0 && return pos:(pos-1) (cmp = CanContain(str, needle)) === NoCompare() && return _not_found - @inbounds ch, nxt = str_next(needle, 1) + @inbounds ch, nxt = iterate(needle, 1) is_valid(eltype(str), ch) || return _not_found # Check if single character if nxt > tlen @@ -298,8 +304,8 @@ end """Compare two strings, starting at nxtstr and nxtsub""" @inline function _cmp_str(str, strpos, endpos, sub, subpos, endsub) while strpos <= endpos - c, strnxt = str_next(str, strpos) - d, subpos = str_next(sub, subpos) + c, strnxt = iterate(str, strpos) + d, subpos = iterate(sub, subpos) c == d || break subpos > endsub && return strpos strpos = strnxt diff --git a/src/support.jl b/src/support.jl index 73d4d1a..48c5ddd 100644 --- a/src/support.jl +++ b/src/support.jl @@ -264,7 +264,7 @@ function unsafe_check_string(str::T; totalchar = latin1byte = num2byte = num3byte = num4byte = invalids = 0 pos = 1 @inbounds while !str_done(str, pos) - chr, nxt = str_next(str, pos) + chr, nxt = iterate(str, pos) ch = chr%UInt32 totalchar += 1 if ch > 0x7f @@ -288,7 +288,7 @@ function unsafe_check_string(str::T; break end # next character *must* be a trailing surrogate character - chr, nxt = str_next(str, nxt) + chr, nxt = iterate(str, nxt) if !is_surrogate_trail(chr) accept_invalids || strerror(StrErrors.NOT_TRAIL, pos, chr) invalids += 1 diff --git a/src/utf8.jl b/src/utf8.jl index 8b453ee..b30581c 100644 --- a/src/utf8.jl +++ b/src/utf8.jl @@ -387,9 +387,9 @@ _iterate(::MultiCU, ::Type{T}, str::SubString{<:Str{RawUTF8CSE}}, pos::Int) wher end _next(::MultiCU, ::Type{T}, str::Str{RawUTF8CSE}, pos::Int) where {T} = - str_next(str.data, pos) + iterate(str.data, pos) _next(::MultiCU, ::Type{T}, str::SubString{<:Str{RawUTF8CSE}}, pos::Int) where {T} = - str_next(SubString(str.string.data, str.offset + pos, str.offset + ncodeunits(str)), 1) + iterate(SubString(str.string.data, str.offset + pos, str.offset + ncodeunits(str)), 1) ## overload methods for efficiency ## diff --git a/test/basic.jl b/test/basic.jl index a925cde..7c0af3b 100644 --- a/test/basic.jl +++ b/test/basic.jl @@ -305,8 +305,8 @@ let @test lastindex(srep) == 7 - @test str_next(srep, 3) == ('β',5) - @test str_next(srep, 7) == ('β',9) + @test iterate(srep, 3) == ('β',5) + @test iterate(srep, 7) == ('β',9) @test srep[7] == 'β' @test_throws StringIndexError srep[8] @@ -340,8 +340,8 @@ end @test_throws MethodError codeunit(tstr, true) @test_throws MethodError isvalid(tstr, 1) @test_throws MethodError isvalid(tstr, true) - @test_throws MethodError str_next(tstr, 1) - @test_throws MethodError str_next(tstr, true) + @test_throws MethodError iterate(tstr, 1) + @test_throws MethodError iterate(tstr, true) @test_throws MethodError lastindex(tstr) gstr = GenericString("12") @@ -611,7 +611,7 @@ end for st in ("Hello", "Σ", "こんにちは", "😊😁") local s s = ST(st) - @test str_next(s, lastindex(s))[2] > sizeof(s) + @test iterate(s, lastindex(s))[2] > sizeof(s) @test nextind(s, lastindex(s)) > sizeof(s) end end @@ -915,7 +915,7 @@ function testbin(::Type{ST}) where {ST} b"\xf8\x9f\x98\x84", b"\xf8\x9f\x98\x84z")), s in lst st = ST(s) - @test str_next(st, 1)[2] == 2 + @test iterate(st, 1)[2] == 2 @test nextind(st, 1) == 2 end @@ -930,7 +930,7 @@ function testbin(::Type{ST}) where {ST} (s, r) in lst st = ST(s) (ST === BinaryStr || ST === Text1Str) && (r = 2) - @test str_next(st, 1)[2] == r + @test iterate(st, 1)[2] == r @test nextind(st, 1) == r end end From 17a3df5be86abec31e3da973e813713e19c52cc5 Mon Sep 17 00:00:00 2001 From: ScottPJones Date: Thu, 13 May 2021 12:22:22 -0400 Subject: [PATCH 2/2] Update CI --- .drone.yml | 19 +++--------------- .github/workflows/ci.yml | 43 ++++++++++++++++++++++++++++++++++++++++ .travis.yml | 34 ------------------------------- Project.toml | 14 ++++++------- 4 files changed, 53 insertions(+), 57 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml diff --git a/.drone.yml b/.drone.yml index 6ac7118..d5da3da 100644 --- a/.drone.yml +++ b/.drone.yml @@ -11,30 +11,17 @@ steps: image: julia:1.5 commands: - "julia --project=. --check-bounds=yes --color=yes -e 'using InteractiveUtils; versioninfo(verbose=true); using Pkg; Pkg.build(); Pkg.test(coverage=true)'" ---- -kind: pipeline -name: linux - arm64 - Julia 1.0 - -platform: - os: linux - arch: arm64 - -steps: -- name: build - image: julia:1.0 - commands: - - "julia --project=. --check-bounds=yes --color=yes -e 'using InteractiveUtils; versioninfo(verbose=true); using Pkg; Pkg.build(); Pkg.test(coverage=true)'" --- kind: pipeline -name: linux - arm - Julia 1.0 +name: linux - arm64 - Julia 1.6 platform: os: linux - arch: arm + arch: arm64 steps: - name: build - image: julia:1.0 + image: julia:1.6 commands: - "julia --project=. --check-bounds=yes --color=yes -e 'using InteractiveUtils; versioninfo(verbose=true); using Pkg; Pkg.build(); Pkg.test(coverage=true)'" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..36c5c31 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,43 @@ +name: CI +on: + - push + - pull_request +jobs: + test: + name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + version: + - '1.5' + - '1.6' + - 'nightly' + os: + - ubuntu-latest + - macOS-latest + - windows-latest + arch: + - x64 + - x86 + exclude: + - os: macOS-latest + arch: x86 + steps: + - uses: actions/checkout@v2 + - uses: julia-actions/setup-julia@v1 + with: + version: ${{ matrix.version }} + arch: ${{ matrix.arch }} + - uses: actions/cache@v1 + env: + cache-name: cache-artifacts + with: + path: ~/.julia/artifacts + key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }} + restore-keys: | + ${{ runner.os }}-test-${{ env.cache-name }}- + ${{ runner.os }}-test- + ${{ runner.os }}- + - uses: julia-actions/julia-buildpkg@v1 + - uses: julia-actions/julia-runtest@v1 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 423d9fa..0000000 --- a/.travis.yml +++ /dev/null @@ -1,34 +0,0 @@ -## Documentation: http://docs.travis-ci.com/user/languages/julia/ -language: julia -os: - - linux - - osx - - windows -julia: - - 1.0 - - 1 - - nightly -notifications: - email: false -git: - depth: 99999999 - -## uncomment the following lines to allow failures on nightly julia -## (tests will run but not make your overall status red) -matrix: - allow_failures: - - julia: nightly - -## uncomment and modify the following lines to manually install system packages -#addons: -# apt: # apt-get for linux -# packages: -# - gfortran -#before_script: # homebrew for mac -# - if [ $TRAVIS_OS_NAME = osx ]; then brew install gcc; fi - -## uncomment the following lines to override the default test script - -after_success: - # push coverage results to Codecov - - julia -e 'using Pkg; cd(Pkg.dir("StrBase")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())' diff --git a/Project.toml b/Project.toml index d17deff..32ae2cf 100644 --- a/Project.toml +++ b/Project.toml @@ -4,7 +4,7 @@ authors = ["ScottPJones "] keywords = ["Strings"] license = "MIT" uuid = "e79e7a6a-7bb1-5a4d-9d64-da657b06f53a" -version = "1.0.4" +version = "1.0.5" [deps] Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" @@ -24,9 +24,9 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" test = ["Test", "Random"] [compat] -julia = "^1.0.0" -ModuleInterfaceTools = "^1.0.0" -MurmurHash3 = "^1.0.3" -StrAPI = "^1.0.0" -ChrBase = "^1.0.1" -CharSetEncodings = "^1.0.0" +julia = "1" +ModuleInterfaceTools = "1" +MurmurHash3 = "^1.2" +StrAPI = "^1.1" +ChrBase = "^1.0.3" +CharSetEncodings = "1"