Ticket #3666: Improper use of IEC and SI prefixes for size in size_trunc().

size_trunc() has been aligned to properly use either IEC or SI prefixes with
the unit B (byte). Additionally always put a space between number and unit
which is required by the norms.

Obsolete gettext message ids have been removed and some cleaned up for
duplicate words or leading spaces.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Michael Osipov 2016-07-27 17:25:10 +02:00 committed by Andrew Borodin
parent c2e1ec81f6
commit b3867a6e15
2 changed files with 9 additions and 13 deletions

View File

@ -346,22 +346,22 @@ size_trunc (uintmax_t size, gboolean use_si)
{
static char x[BUF_TINY];
uintmax_t divisor = 1;
const char *xtra = "";
const char *xtra = _("B");
if (size > 999999999UL)
{
divisor = use_si ? 1000 : 1024;
xtra = use_si ? "k" : "K";
xtra = use_si ? _("kB") : _("KiB");
if (size / divisor > 999999999UL)
{
divisor = use_si ? (1000 * 1000) : (1024 * 1024);
xtra = use_si ? "m" : "M";
xtra = use_si ? _("MB") : _("MiB");
if (size / divisor > 999999999UL)
{
divisor = use_si ? (1000 * 1000 * 1000) : (1024 * 1024 * 1024);
xtra = use_si ? "g" : "G";
xtra = use_si ? _("GB") : _("GiB");
}
}
}
@ -383,7 +383,7 @@ size_trunc_sep (uintmax_t size, gboolean use_si)
p += strlen (p) - 1;
d = x + sizeof (x) - 1;
*d-- = '\0';
while (p >= y && isalpha ((unsigned char) *p))
while (p >= y && (isalpha ((unsigned char) *p) || (unsigned char) *p == ' '))
*d-- = *p--;
for (count = 0; p >= y; count++)
{

View File

@ -1079,13 +1079,9 @@ display_total_marked_size (const WPanel * panel, int y, int x, gboolean size_onl
buf = size_only ? b_bytes : buffer;
cols = w->cols - 2;
/*
* This is a trick to use two ngettext() calls in one sentence.
* First make "N bytes", then insert it into "X in M files".
*/
g_snprintf (b_bytes, sizeof (b_bytes),
ngettext ("%s byte", "%s bytes", panel->total),
size_trunc_sep (panel->total, panels_options.kilobyte_si));
g_strlcpy (b_bytes, size_trunc_sep (panel->total, panels_options.kilobyte_si),
sizeof (b_bytes));
if (!size_only)
g_snprintf (buffer, sizeof (buffer),
ngettext ("%s in %d file", "%s in %d files", panel->marked),