Skip to content

Commit b7eff14

Browse files
divbyzerofordummiesbest4inniovisr
authored
Fixes problem with DBF file where field name is not padded with \0 (#29)
* Fixes problem with DBF file where rest of field name is not filled with \0 * go directly from bytes until 0 to Symbol * Omit repetition of hard-coded constant, make variable names more telling --------- Co-authored-by: Daniel Muschick <[email protected]> Co-authored-by: Martijn Visser <[email protected]>
1 parent 573ce48 commit b7eff14

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/DBFTables.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,12 @@ end
192192

193193
"Read a field descriptor from the stream, and create a FieldDescriptor struct"
194194
function read_dbf_field(io::IO)
195-
field_name_raw = String(read!(io, Vector{UInt8}(undef, 11)))
196-
field_name = Symbol(strip(replace(field_name_raw, '\0' => ' ')))
195+
n_bytes_field_name = 11 # field name can be up to 11 bytes long, delimited by '\0' (end of string, EOS)
196+
field_name_bytes = read(io, n_bytes_field_name)
197+
pos_eos = findfirst(iszero, field_name_bytes)
198+
n = pos_eos === nothing ? n_bytes_field_name : pos_eos - 1
199+
field_name = Symbol(field_name_bytes[1:n])
200+
197201
field_type = read(io, Char)
198202
skip(io, 4) # skip
199203
field_len = read(io, UInt8)

0 commit comments

Comments
 (0)