Skip to content

Commit

Permalink
add regex functions (fixes #55)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj committed Nov 3, 2021
1 parent be1873b commit 466088d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/LaTeXStrings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,8 @@ Base.isvalid(s::LaTeXString, i::Integer) = isvalid(s.s, i)
Base.pointer(s::LaTeXString) = pointer(s.s)
Base.IOBuffer(s::LaTeXString) = IOBuffer(s.s)
Base.unsafe_convert(T::Union{Type{Ptr{UInt8}},Type{Ptr{Int8}},Cstring}, s::LaTeXString) = Base.unsafe_convert(T, s.s)
Base.match(re::Regex, s::LaTeXString, idx::Integer, add_opts::UInt32=UInt32(0)) = match(re, s.s, idx, add_opts)
Base.findnext(re::Regex, s::LaTeXString, idx::Integer) = findnext(re, s.s, idx)
Base.eachmatch(re::Regex, s::LaTeXString; overlap = false) = eachmatch(re, s.s; overlap=overlap)

end # module
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ end
@test L"foo"[1] == '$'
@test tst1[1:2] == tst1[0x01:0x02] == tst1[[1,2]] == "an"

@test match(r"[a-z]+", tst1, 3).match == match(r"[a-z]+", tst1.s, 3).match
@test findnext(r"[a-z]+", tst1, 3) == findnext(r"[a-z]+", tst1.s, 3)
@test [m.match for m in eachmatch(r"[a-z]+", tst1)] == [m.match for m in eachmatch(r"[a-z]+", tst1.s)]

# issue #23 — will change if #17 is addressed
@test L"x" * L"y" == "\$x\$\$y\$"

Expand Down

0 comments on commit 466088d

Please sign in to comment.