Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/lazy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,12 @@ function Base.convert(::Type{T}, x::PtrString) where {T <: Enum}
end

Base.:(==)(x::PtrString, y::AbstractString) = x.len == sizeof(y) && ccall(:memcmp, Cint, (Ptr{UInt8}, Ptr{UInt8}, Csize_t), x.ptr, pointer(y), x.len) == 0
Base.:(==)(x::AbstractString, y::PtrString) = y == x
Base.:(==)(x::PtrString, y::PtrString) = x.len == y.len && ccall(:memcmp, Cint, (Ptr{UInt8}, Ptr{UInt8}, Csize_t), x.ptr, y.ptr, x.len) == 0
Base.isequal(x::PtrString, y::AbstractString) = x == y
Base.isequal(x::AbstractString, y::PtrString) = y == x
Base.isequal(x::PtrString, y::PtrString) = x == y
Base.hash(x::PtrString, h::UInt) = hash(unsafe_string(x.ptr, x.len), h)
StructUtils.keyeq(x::PtrString, y::AbstractString) = x == y
StructUtils.keyeq(x::PtrString, y::String) = x == y
StructUtils.keyeq(x::PtrString, y::Symbol) = convert(Symbol, x) == y
Expand Down Expand Up @@ -746,4 +749,4 @@ function Base.show(io::IO, x::LazyValue)
else # bool/number
Base.print(io, "JSON.LazyValue(", parse(x), ")")
end
end
end
10 changes: 10 additions & 0 deletions test/lazy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ end
x = JSON.lazy("{}"; allownan=true)
@test_throws ArgumentError JSON.parsenumber(x)

str = JSON.lazy("\"alpha\"")
key, _ = JSON.parsestring(str)
@test key == "alpha"
@test "alpha" == key
@test isequal(key, "alpha")
@test isequal("alpha", key)
@test hash(key) == hash("alpha")
@test haskey(Dict{Any,Int}(key => 1), "alpha")
@test "alpha" in Set{Any}([key])

# lazy indexing selection support
# examples from https://support.smartbear.com/alertsite/docs/monitors/api/endpoint/jsonpath.html
json = """
Expand Down
Loading