JuliaString / Format.jl

A Julia package to provide C and Python-like formatting support
Other
40 stars 6 forks source link

format() should accept SubString as well as String #84

Open bluesmoon opened 6 months ago

bluesmoon commented 6 months ago

In format:

function format( x::T;
                 width::Int=-1,
                 precision::Int= -1,
                 leftjustified::Bool=false,
                 zeropadding::Bool=false, # when right-justified, use 0 instead of space to fill
                 commas::Bool=false,
                 signed::Bool=false, # +/- prefix
                 positivespace::Bool=false,
                 stripzeros::Bool=(precision== -1),
                 parens::Bool=false, # use (1.00) instead of -1.00. Used in finance
                 alternative::Bool=false, # usually for hex
                 mixedfraction::Bool=false,
                 mixedfractionsep::UTF8Str="_",
                 fractionsep::UTF8Str="/", # num / den
                 fractionwidth::Int = 0,
                 tryden::Int = 0, # if 2 or higher,
                                  # try to use this denominator, without losing precision
                 suffix::UTF8Str="", # useful for units/%
                 autoscale::Symbol=:none, # :metric, :binary or :finance
                 conversion::ASCIIStr=""
                 ) where {T<:Real}

several of the parameters are either UTF8Str or ASCIIStr, but this fails when the parameter passed in is a SubString{T}. This seemed to work with Formatting.jl

ScottPJones commented 3 months ago

Thanks for finding this! Sorry I've been out of touch the last couple of months! Will look at fixing it now at JuliaCon