Julia packages for strings with fixed maximum number of bytes.
StrF{S} <: AbstractString
can be used for strings up to S
bytes in UTF-8 encoding. When the string has less than that many bytes, it is terminated with a 0x00
.
This mirrors the way Stata DTA files encode fixed length strings (str#
), but other applications may also find this useful. StrF{S}
strings are implemented by wrapping an SVector{S,UInt8}
, with the potential efficiency gains that entails.
julia> using StrFs
julia> gender = [strf"male", strf"female"]
2-element Array{StrF{6},1}:
"male"
"female"
julia> gender[1] == "male"
true
julia> issorted(gender, rev = true)
true
julia> motto = StrF{6}("ηβπ") # uses all bytes
"ηβπ"
julia> sizeof(motto)
6
julia> length(motto)
3
julia> motto == StrF{10}("ηβπ") # 0x00 at byte 7
true
See StataDTAFiles.jl.