From 53c63f0169b3c5441172a2d6bedd3735e1b9e04a Mon Sep 17 00:00:00 2001 From: mattBrzezinski Date: Thu, 24 Sep 2020 15:07:00 -0500 Subject: [PATCH] Use PropertyDicts.jl (#23) * Use PropertyDicts.jl * Only using PropertyDict * v0.2.2 --- Project.toml | 4 ++- src/LazyJSON.jl | 3 +- src/PropertyDicts.jl | 65 -------------------------------------------- 3 files changed, 5 insertions(+), 67 deletions(-) delete mode 100644 src/PropertyDicts.jl diff --git a/Project.toml b/Project.toml index 8facc68..7007633 100644 --- a/Project.toml +++ b/Project.toml @@ -1,16 +1,18 @@ name = "LazyJSON" uuid = "fc18253b-5e1b-504c-a4a2-9ece4944c004" license = "MIT" -version = "0.2.1" +version = "0.2.2" [deps] JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" +PropertyDicts = "f8a19df8-e894-5f55-a973-672c1158cbca" [compat] JSON = "0.18, 0.19, 0.20, 0.21" JSON2 = "0.1, 0.2, 0.3" OrderedCollections = "1" +PropertyDicts = "0.1" julia = "1" [extras] diff --git a/src/LazyJSON.jl b/src/LazyJSON.jl index 9e8f60b..bb4eae5 100644 --- a/src/LazyJSON.jl +++ b/src/LazyJSON.jl @@ -1,5 +1,7 @@ module LazyJSON +using PropertyDicts: PropertyDict + module JSONjl using JSON end @@ -16,7 +18,6 @@ macro lazywarn(a...) end include("SplicedStrings.jl") ; using .SplicedStrings: SplicedString -include("PropertyDicts.jl") ; using .PropertyDicts: PropertyDict include("IOStrings.jl") ; using .IOStrings: IOString, pump diff --git a/src/PropertyDicts.jl b/src/PropertyDicts.jl deleted file mode 100644 index 2c690d6..0000000 --- a/src/PropertyDicts.jl +++ /dev/null @@ -1,65 +0,0 @@ -module PropertyDicts - -""" - PropertyDict(::AbstactDict) - -Wraps an `AbstractDict` to add `getproperty` support for `Symbol` and -`AbstractString` keys. - -e.g. -``` -> julia d = PropertyDict(Dict("foo" => 1, :bar => 2)) -PropertyDict with 2 entries: - :bar => 2 - "foo" => 1 - -julia> d.foo, d.bar, d."foo" -(1, 2, 1) - -julia> d."bar" -ERROR: KeyError: key "bar" not found -``` -""" -struct PropertyDict{K, V, T <: AbstractDict{K, V}} <: AbstractDict{K, V} - d::T - PropertyDict(d::T) where {T <: AbstractDict} = - new{keytype(d), valtype(d), T}(d) -end - - -unwrap(d::PropertyDict) = getfield(d, :d) - - -Base.getproperty(d::PropertyDict{AbstractString}, n::Symbol) = - getindex(d, String(n)) - -function Base.getproperty(d::PropertyDict, n::Symbol) - v = get(d, n, Base.secret_table_token) - if v != Base.secret_table_token - return v - end - return getindex(d, String(n)) -end - -Base.getproperty(d::PropertyDict, n) = getindex(d, n) - - -Base.IteratorSize(::Type{PropertyDict{K,V,T}}) where {K,V,T} = Base.IteratorSize(T) -Base.IteratorEltype(::Type{PropertyDict{K,V,T}}) where {K,V,T} = Base.IteratorEltype(T) -Base.getindex(d::PropertyDict, i) = getindex(unwrap(d), i) -Base.get(d::PropertyDict, k, default) = get(unwrap(d), k, default) -Base.length(d::PropertyDict) = length(unwrap(d)) -Base.iterate(d::PropertyDict) = iterate(unwrap(d)) -Base.iterate(d::PropertyDict, i) = iterate(unwrap(d), i) - -Base.string(d::PropertyDict) = string(unwrap(d)) - -Base.convert(::Type{Any}, d::PropertyDict) = d -Base.convert(::Type{PropertyDict{K,V,T}}, d::PropertyDict{K,V,T}) where {K,V,T<:AbstractDict{K,V}} = d -Base.convert(::Type{T}, d::PropertyDict) where T <: AbstractDict = - T === AbstractDict ? d : convert(T, PropertyDicts.unwrap(d)) -Base.convert(::Type{T}, d::PropertyDict) where T = convert(T, PropertyDicts.unwrap(d)) - - - -end # module PropertyDicts