Skip to content

Commit 91b8bf5

Browse files
committed
fix RegexAndMatchData searching (fixes #5)
1 parent 1ddca05 commit 91b8bf5

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/regex.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ function Base.match(re::Regex, str::DenseStringViewAndSub, idx::Integer, add_opt
3838
return result
3939
end
4040

41-
Base.findnext(re::Regex, str::DenseStringViewAndSub, idx::Integer) = _findnext_re(re, str, idx, C_NULL)
41+
Base.findnext(re::Regex, str::DenseStringViewAndSub, idx::Integer) = Base._findnext_re(re, str, idx, C_NULL)
4242

43-
function _findnext_re(re::Regex, str::DenseStringViewAndSub, idx::Integer, match_data::Ptr{Cvoid})
43+
function Base._findnext_re(re::Regex, str::DenseStringViewAndSub, idx::Integer, match_data::Ptr{Cvoid})
4444
if idx > nextind(str,lastindex(str))
4545
throw(BoundsError())
4646
end

src/util.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ Base.replace(str::DenseStringViewAndSub, pat_repl::Pair{<:Union{Tuple{Vararg{<:A
4444
count::Integer=typemax(Int)) =
4545
replace(str, in(first(pat_repl)) => last(pat_repl), count=count)
4646

47-
_pat_replacer(x) = x
48-
_free_pat_replacer(x) = nothing
47+
import Base: _pat_replacer, _free_pat_replacer
4948

5049
function Base.replace(str::DenseStringViewAndSub, pat_repl::Pair; count::Integer=typemax(Int))
5150
pattern, repl = pat_repl

test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ end
102102
@test findprev(==("ba"), str, n) === findprev(==("ba"), sS, n)
103103
end
104104
@test chomp(StringView("foo\n")) == "foo"
105+
106+
# issue #5
107+
let v = [0x32, 0x30, 0x32, 0x31, 0x2d, 0x31, 0x31, 0x2d, 0x31, 0x30, 0x20, 0x32, 0x31, 0x3a, 0x34, 0x32, 0x3a, 0x30, 0x35, 0x2e, 0x31, 0x31, 0x35, 0x38, 0x30, 0x37],
108+
pat = r"(\.[\d]{3})\d+" => s"\g<1>"
109+
@test replace(String(copy(v)), pat) == replace(StringView(v), pat)
110+
end
105111
end
106112

107113
@testset "miscellaneous" begin

0 commit comments

Comments
 (0)