Skip to content

Commit 8485123

Browse files
authored
Add M datatype (#24)
1 parent 7ea8090 commit 8485123

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/DBFTables.jl

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ julia_type(::Val{'O'}, ndec::UInt8) = Float64
121121
julia_type(::Val{'I'}, ndec::UInt8) = Int32
122122
julia_type(::Val{'+'}, ndec::UInt8) = Int64
123123
julia_type(::Val{'L'}, ndec::UInt8) = Bool
124+
julia_type(::Val{'M'}, ndec::UInt8) = String
124125
function julia_type(::Val{T}, ndec::UInt8) where {T}
125126
@warn "Unknown DBF type code '$T'. Data will be loaded as `String"
126127
String
@@ -129,10 +130,13 @@ end
129130

130131
julia_value(o::FieldDescriptor, s::AbstractString) = julia_value(o.type, Val(o.dbf_type), s::AbstractString)
131132

132-
function julia_value(::Type{String}, ::Val{'C'}, s::AbstractString)
133+
function julia_value_string(s::AbstractString)
133134
s2 = strip(s)
134135
isempty(s2) ? missing : String(s2)
135136
end
137+
138+
julia_value(::Type{String}, ::Val{'C'}, s::AbstractString) = julia_value_string(s)
139+
julia_value(::Type{String}, ::Val{'M'}, s::AbstractString) = julia_value_string(s)
136140
function julia_value(::Type{Date}, ::Val{'D'}, s::AbstractString)
137141
all(isspace, s) ? missing : Date(s, dateformat"yyyymmdd")
138142
end
@@ -163,10 +167,13 @@ function julia_value(::Type{Int64}, ::Val{'+'}, s::AbstractString)
163167
end
164168
function julia_value(::Type{Bool}, ::Val{'L'}, s::AbstractString)
165169
char = only(s)
166-
char === '?' ? missing :
167-
char in "YyTt" ? true :
168-
char in "NnFf" ? false :
169-
error("Unknown logical entry for dbf type code 'L': '$char'.")
170+
if char in "YyTt"
171+
return true
172+
elseif char in "NnFf"
173+
return false
174+
else
175+
return missing
176+
end
170177
end
171178

172179
"Read a field descriptor from the stream, and create a FieldDescriptor struct"

0 commit comments

Comments
 (0)