11module DBFTables
22
3- using Printf, Tables, WeakRefStrings
3+ import Printf, Tables, WeakRefStrings
44
55" Field/column descriptor, part of the Header"
66struct FieldDescriptor
2929struct Table
3030 header:: Header
3131 data:: Vector{UInt8} # WeakRefString references this
32- strings:: StringArray{String,2}
32+ strings:: WeakRefStrings. StringArray{String,2}
3333end
3434
3535" Struct representing a single row or record of the DBF Table"
@@ -50,7 +50,6 @@ function typemap(fld::Char, ndec::UInt8)
5050 if ndec > 0
5151 rt = Float64
5252 else
53- # TODO do we want this?
5453 rt = Int
5554 end
5655 elseif fld == ' F' || fld == ' O'
@@ -84,7 +83,7 @@ function Header(io::IO)
8483 date1 = read (io, UInt8)
8584 date2 = read (io, UInt8)
8685 date3 = read (io, UInt8)
87- last_update = @sprintf (" %4d%02d%02d" , date1 + 1900 , date2, date3)
86+ last_update = Printf . @sprintf (" %4d%02d%02d" , date1 + 1900 , date2, date3)
8887 records = read (io, UInt32)
8988 hsize = read (io, UInt16)
9089 rsize = read (io, UInt16)
134133miss (x) = ifelse (x === nothing , missing , x)
135134
136135" Concert a DBF entry string to a Julia value"
137- function dbf_value (T :: Type{Bool} , str:: AbstractString )
136+ function dbf_value (:: Type{Bool} , str:: AbstractString )
138137 char = first (str)
139138 if char in " YyTt"
140139 true
150149dbf_value (T:: Union{Type{Int},Type{Float64}} , str:: AbstractString ) =
151150 miss (tryparse (T, str))
152151# String to avoid returning SubString{String}
153- function dbf_value (T :: Type{String} , str:: AbstractString )
152+ function dbf_value (:: Type{String} , str:: AbstractString )
154153 stripped = rstrip (str)
155154 if isempty (stripped)
156155 # return missing rather than ""
@@ -159,7 +158,7 @@ function dbf_value(T::Type{String}, str::AbstractString)
159158 return String (stripped)
160159 end
161160end
162- dbf_value (T :: Type{Nothing} , str :: AbstractString ) = missing
161+ dbf_value (:: Type{Nothing} , :: AbstractString ) = missing
163162
164163# define get functions using getfield since we overload getproperty
165164" Access the header of a DBF Table"
@@ -176,7 +175,7 @@ Base.size(row::Row) = (length(row),)
176175Base. size (row:: Row , i) = i == 1 ? length (row) : throw (BoundsError (row, i))
177176
178177"""
179- DBFTables.Table(source) => DBFTables.Table
178+ DBFTables.Table(source) => DBFTables.Table
180179
181180Read a source, a path to a file or an opened stream, to a DBFTables.Table.
182181This type conforms to the Tables interface, so it can be easily converted
@@ -211,7 +210,7 @@ function _create_stringarray(header::Header, data::AbstractVector)
211210 offsets = repeat (offsets_record, 1 , header. records)
212211 offsets .+ = reshape (row_offsets, 1 , :)
213212
214- StringArray {String,2} (data, offsets, lengths)
213+ WeakRefStrings . StringArray {String,2} (data, offsets, lengths)
215214end
216215
217216" Create a NamedTuple representing a single row"
0 commit comments