coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: numfmt (=print 'human' sizes) updates


From: Assaf Gordon
Subject: Re: numfmt (=print 'human' sizes) updates
Date: Wed, 26 Dec 2012 10:28:33 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.4) Gecko/20120510 Icedove/10.0.4

Hello, 

Pádraig Brady wrote, On 12/21/2012 12:42 PM:
> 
> I'm starting to think the original idea of having a --format option
> would be more a more concise, well known and extendible interface
> rather than having --padding, --grouping, --base, ...
> It wouldn't have to be passed directly to printf, and could
> be parsed and preprocessed something like we do in seq(1).
> 

Regarding 'format' option, there are some intricacies that are worth discussing:

1. Depending on the requested conversion, the output can be a string (e.g. 
"1.4Ki") or a long double (e.g. 1400000).

2. Internally, the program uses long doubles - so the real format is "%Lf" - 
regardless of what the user will give (e.g. "%f").

3. printf accepts all sorts of options, some of which aren't relevant to 
numfmt, or only relevant when printing non-humanized values.
e.g.:
    $ LC_ALL=en_US.utf8 seq -f "%0'14.5f" 1000 1001
    0001,000.00000
    0001,001.00000

4. The assumption was that humanized numbers are always maximum 4 characters in 
SI/IEC (e.g. "1024" or "4.5M") or 5 characters with "iec-i" (e.g. "999Ti").
With the new 'format', if given "%'2.9f" - should the output be still 4 
characters (e.g. "4.5T"), or respect the ".9" format (e.g. "4.500000000T") ? 
and does the suffix character counts in the "2.9" format ?


My preference is to keep things simple, and accept just a limited subset of the 
"format" syntax:
1. grouping (the ' character)
2. padding (the number after '%' and before the 'f'
3. alignment (optional '-' after '%')
4. Any prefix/suffix before/after the '%' option.
5. Accept just "%f", but internally treat it as '%s' or '%Lf', depending on the 
output.

All other options will be silently ignored, or trigger errors.

Example:
    $ numfmt --format "xx%20fxx" --to=si 5000
    [[ internally, treats as "--padding 20" ]]
    xx                5.0Kxx

    $ numfmt --format "xx%'-10fxx" 5000
    [[ internally, treats as "--padding -10 --grouping" ]]
    xx5,000     xx

    $ numfmt --format "xx%0#'+010llfxx" 5000
    [[ reject as 'too complicated' / unsupported printf options ]]


WDYT?

-gordon





reply via email to

[Prev in Thread] Current Thread [Next in Thread]