2017-08-01 18:03:48 +02:00
|
|
|
"""
|
2017-08-01 22:51:03 +02:00
|
|
|
Citation{S}(data::Dict{String,String})
|
2017-08-01 18:03:48 +02:00
|
|
|
|
|
|
|
A bibliography item in a bibTeX database, based on a dictionary of
|
|
|
|
strings to values. It is parameterized by a symbol `S` giving the
|
2017-08-01 22:51:03 +02:00
|
|
|
type of the item (`:article` etcetera). A `b::Citation` supports
|
2017-08-01 18:03:48 +02:00
|
|
|
`b[key]` access to retrieve the data and in general acts like
|
|
|
|
a dictionary from `String` to `String`.
|
|
|
|
"""
|
2017-08-01 22:51:03 +02:00
|
|
|
struct Citation{S} <: Associative{String,String}
|
2017-08-01 18:03:48 +02:00
|
|
|
data::Dict{String,String}
|
|
|
|
end
|
2017-08-01 22:51:03 +02:00
|
|
|
Citation{S}() where {S} = Citation{S}(Dict{String,String}())
|
2017-08-01 18:03:48 +02:00
|
|
|
|
2017-08-01 22:51:03 +02:00
|
|
|
function Citation!(data::Dict{String,String})
|
2017-08-01 18:03:48 +02:00
|
|
|
S = Symbol(pop!(data, "__type__"))
|
2017-08-01 22:51:03 +02:00
|
|
|
return Citation{S}(data)
|
2017-08-01 18:03:48 +02:00
|
|
|
end
|
|
|
|
|
2017-08-01 22:51:03 +02:00
|
|
|
Base.similar(b::Citation{S}) where {S} = Citation{S}(Dict{String,String}())
|
2017-08-01 23:04:18 +02:00
|
|
|
Base.rehash!(b::Citation, n=length(b.data)) = begin Base.rehash!(b.data, n); b; end
|
2017-08-01 22:51:03 +02:00
|
|
|
Base.sizehint!(b::Citation, n) = begin sizehint!(b.data, n); b; end
|
|
|
|
Base.empty!(b::Citation) = begin empty!(b.data); b; end
|
|
|
|
Base.copy(b::Citation{S}) where {S} = Citation{S}(copy(b.data))
|
2017-08-01 18:03:48 +02:00
|
|
|
|
2017-08-01 22:51:03 +02:00
|
|
|
Base.get(b::Citation, k::AbstractString, default) = get(b.data, String(k), default)
|
|
|
|
Base.getindex(b::Citation, k::AbstractString) = getindex(b.data, String(k))
|
|
|
|
function Base.setindex!(b::Citation, v::AbstractString, k::AbstractString)
|
2017-08-01 18:03:48 +02:00
|
|
|
b.data[String(k)] = String(v)
|
|
|
|
return b
|
|
|
|
end
|
|
|
|
|
2017-08-01 22:51:03 +02:00
|
|
|
Base.start(b::Citation) = start(b.data)
|
|
|
|
Base.done(b::Citation, i) = done(b.data, i)
|
|
|
|
Base.next(b::Citation, i) = next(b.data, i)
|
|
|
|
Base.length(b::Citation) = length(b.data)
|
2017-08-01 18:03:48 +02:00
|
|
|
|
2017-08-01 22:51:03 +02:00
|
|
|
function Base.show{S}(io::IO, b::Citation{S})
|
|
|
|
print(io, "Citation{:$S}(", length(b), " entries)")
|
2017-08-01 18:03:48 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
# TODO: add Base.show text/plain and text/markdown for formatted citation
|