From b3867a6e154420833d6a1117f556b9ab2d64c6ab Mon Sep 17 00:00:00 2001 From: Michael Osipov <1983-01-06@gmx.net> Date: Wed, 27 Jul 2016 17:25:10 +0200 Subject: [PATCH] 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 --- lib/util.c | 12 ++++++------ src/filemanager/panel.c | 10 +++------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/lib/util.c b/lib/util.c index f22c88561..304351ddd 100644 --- a/lib/util.c +++ b/lib/util.c @@ -346,26 +346,26 @@ 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"); } } } - g_snprintf (x, sizeof (x), "%.0f%s", 1.0 * size / divisor, xtra); + g_snprintf (x, sizeof (x), "%.0f %s", 1.0 * size / divisor, xtra); return x; } @@ -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++) { diff --git a/src/filemanager/panel.c b/src/filemanager/panel.c index e7c210bfe..5dd939503 100644 --- a/src/filemanager/panel.c +++ b/src/filemanager/panel.c @@ -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), -- 2.11.4.GIT