Skip to content

Commit

Permalink
fix regex serialization
Browse files Browse the repository at this point in the history
also add regex comparison method and serialization test
  • Loading branch information
tanmaykm committed Jun 24, 2015
1 parent 756517b commit d20cd4b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
6 changes: 6 additions & 0 deletions base/regex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,9 @@ function eachmatch(re::Regex, str::AbstractString, ovr::Bool=false)
end

eachmatch(re::Regex, str::AbstractString) = RegexMatchIterator(re,str)

## comparison ##

function ==(a::Regex, b::Regex)
a.pattern == b.pattern && a.compile_options == b.compile_options && a.match_options == b.match_options
end
8 changes: 5 additions & 3 deletions base/serialize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ end
function serialize(s::SerializationState, r::Regex)
serialize_type(s, typeof(r))
serialize(s, r.pattern)
serialize(s, r.options)
serialize(s, r.compile_options)
serialize(s, r.match_options)
end

function serialize(s::SerializationState, n::BigInt)
Expand Down Expand Up @@ -706,8 +707,9 @@ deserialize(s::SerializationState, ::Type{BigInt}) = get(GMP.tryparse_internal(B

function deserialize(s::SerializationState, t::Type{Regex})
pattern = deserialize(s)
options = deserialize(s)
Regex(pattern, options)
compile_options = deserialize(s)
match_options = deserialize(s)
Regex(pattern, compile_options, match_options)
end

end
9 changes: 9 additions & 0 deletions test/serialize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,12 @@ create_serialization_stream() do s
@test length(b) == 5
@test isa(b,Vector{Any})
end

# Regex
create_serialization_stream() do s
r1 = r"a?b.*"
serialize(s, r1)
seekstart(s)
r2 = deserialize(s)
@test r1 == r2
end

0 comments on commit d20cd4b

Please sign in to comment.