From 207ee5b008883c4972e49675a4602d0c84032a1a Mon Sep 17 00:00:00 2001 From: getsnoopy Date: Mon, 28 Aug 2023 14:33:07 -0500 Subject: [PATCH 1/2] gutils: Use international symbol for bits Currently, the project uses IEC symbols and/or SI symbols everywhere else (e.g., KiB and kB). However, when it comes to bits, it uses JEDEC symbols (e.g., b). This mixing of standards does not make sense, especially when JEDEC symbols seem to be deprecated (at least in this project). Moreover, it is a huge point of confusion for everyday people who don't know the difference between bits and bytes to read stuff like "Mbps" (the old ad hoc abbreviation) and "Mb/s" as "megabytes per second" and the like. That's the whole reason the IEC has come up with its symbols in the first place so that they leave no room for confusion, with a clear distinction between B (for bytes) and bit (for bits). As such, this commit updates all bit symbols to use those from the IEC standard. --- glib/gutils.c | 48 +++++++++++++++++++++--------------------- glib/tests/fileutils.c | 38 ++++++++++++++++----------------- 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/glib/gutils.c b/glib/gutils.c index 362c55aff9..59e32eb893 100644 --- a/glib/gutils.c +++ b/glib/gutils.c @@ -2990,32 +2990,32 @@ g_format_size_full (guint64 size, { EXBIBYTE_FACTOR, N_("EiB") } }, { - /* Translators: A unit symbol for size formatting, showing for example: "13.0 kb" */ - { KILOBYTE_FACTOR, N_("kb") }, - /* Translators: A unit symbol for size formatting, showing for example: "13.0 Mb" */ - { MEGABYTE_FACTOR, N_("Mb") }, - /* Translators: A unit symbol for size formatting, showing for example: "13.0 Gb" */ - { GIGABYTE_FACTOR, N_("Gb") }, - /* Translators: A unit symbol for size formatting, showing for example: "13.0 Tb" */ - { TERABYTE_FACTOR, N_("Tb") }, - /* Translators: A unit symbol for size formatting, showing for example: "13.0 Pb" */ - { PETABYTE_FACTOR, N_("Pb") }, - /* Translators: A unit symbol for size formatting, showing for example: "13.0 Eb" */ - { EXABYTE_FACTOR, N_("Eb") } + /* Translators: A unit symbol for size formatting, showing for example: "13.0 kbit" */ + { KILOBYTE_FACTOR, N_("kbit") }, + /* Translators: A unit symbol for size formatting, showing for example: "13.0 Mbit" */ + { MEGABYTE_FACTOR, N_("Mbit") }, + /* Translators: A unit symbol for size formatting, showing for example: "13.0 Gbit" */ + { GIGABYTE_FACTOR, N_("Gbit") }, + /* Translators: A unit symbol for size formatting, showing for example: "13.0 Tbit" */ + { TERABYTE_FACTOR, N_("Tbit") }, + /* Translators: A unit symbol for size formatting, showing for example: "13.0 Pbit" */ + { PETABYTE_FACTOR, N_("Pbit") }, + /* Translators: A unit symbol for size formatting, showing for example: "13.0 Ebit" */ + { EXABYTE_FACTOR, N_("Ebit") } }, { - /* Translators: A unit symbol for size formatting, showing for example: "13.0 Kib" */ - { KIBIBYTE_FACTOR, N_("Kib") }, - /* Translators: A unit symbol for size formatting, showing for example: "13.0 Mib" */ - { MEBIBYTE_FACTOR, N_("Mib") }, - /* Translators: A unit symbol for size formatting, showing for example: "13.0 Gib" */ - { GIBIBYTE_FACTOR, N_("Gib") }, - /* Translators: A unit symbol for size formatting, showing for example: "13.0 Tib" */ - { TEBIBYTE_FACTOR, N_("Tib") }, - /* Translators: A unit symbol for size formatting, showing for example: "13.0 Pib" */ - { PEBIBYTE_FACTOR, N_("Pib") }, - /* Translators: A unit symbol for size formatting, showing for example: "13.0 Eib" */ - { EXBIBYTE_FACTOR, N_("Eib") } + /* Translators: A unit symbol for size formatting, showing for example: "13.0 Kibit" */ + { KIBIBYTE_FACTOR, N_("Kibit") }, + /* Translators: A unit symbol for size formatting, showing for example: "13.0 Mibit" */ + { MEBIBYTE_FACTOR, N_("Mibit") }, + /* Translators: A unit symbol for size formatting, showing for example: "13.0 Gibit" */ + { GIBIBYTE_FACTOR, N_("Gibit") }, + /* Translators: A unit symbol for size formatting, showing for example: "13.0 Tibit" */ + { TEBIBYTE_FACTOR, N_("Tibit") }, + /* Translators: A unit symbol for size formatting, showing for example: "13.0 Pibit" */ + { PEBIBYTE_FACTOR, N_("Pibit") }, + /* Translators: A unit symbol for size formatting, showing for example: "13.0 Eibit" */ + { EXBIBYTE_FACTOR, N_("Eibit") } } }; diff --git a/glib/tests/fileutils.c b/glib/tests/fileutils.c index ab5b574cc5..f4426bcdb0 100644 --- a/glib/tests/fileutils.c +++ b/glib/tests/fileutils.c @@ -979,17 +979,17 @@ test_format_size_for_display (void) check_string (g_format_size_full (2, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_ONLY_VALUE), "2"); check_string (g_format_size_full (2, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_ONLY_UNIT), "bits"); - check_string (g_format_size_full (2000ULL, G_FORMAT_SIZE_BITS), "2.0\302\240kb"); - check_string (g_format_size_full (2000ULL * 1000, G_FORMAT_SIZE_BITS), "2.0\302\240Mb"); - check_string (g_format_size_full (2000ULL * 1000 * 1000, G_FORMAT_SIZE_BITS), "2.0\302\240Gb"); - check_string (g_format_size_full (2000ULL * 1000 * 1000 * 1000, G_FORMAT_SIZE_BITS), "2.0\302\240Tb"); - check_string (g_format_size_full (2000ULL * 1000 * 1000 * 1000 * 1000, G_FORMAT_SIZE_BITS), "2.0\302\240Pb"); - check_string (g_format_size_full (2000ULL * 1000 * 1000 * 1000 * 1000 * 1000, G_FORMAT_SIZE_BITS), "2.0\302\240Eb"); - - check_string (g_format_size_full (238472938, G_FORMAT_SIZE_BITS), "238.5\302\240Mb"); - check_string (g_format_size_full (238472938, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_LONG_FORMAT), "238.5\302\240Mb (238472938 bits)"); + check_string (g_format_size_full (2000ULL, G_FORMAT_SIZE_BITS), "2.0\302\240kbit"); + check_string (g_format_size_full (2000ULL * 1000, G_FORMAT_SIZE_BITS), "2.0\302\240Mbit"); + check_string (g_format_size_full (2000ULL * 1000 * 1000, G_FORMAT_SIZE_BITS), "2.0\302\240Gbit"); + check_string (g_format_size_full (2000ULL * 1000 * 1000 * 1000, G_FORMAT_SIZE_BITS), "2.0\302\240Tbit"); + check_string (g_format_size_full (2000ULL * 1000 * 1000 * 1000 * 1000, G_FORMAT_SIZE_BITS), "2.0\302\240Pbit"); + check_string (g_format_size_full (2000ULL * 1000 * 1000 * 1000 * 1000 * 1000, G_FORMAT_SIZE_BITS), "2.0\302\240Ebit"); + + check_string (g_format_size_full (238472938, G_FORMAT_SIZE_BITS), "238.5\302\240Mbit"); + check_string (g_format_size_full (238472938, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_LONG_FORMAT), "238.5\302\240Mbit (238472938 bits)"); check_string (g_format_size_full (238472938, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_ONLY_VALUE), "238.5"); - check_string (g_format_size_full (238472938, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_ONLY_UNIT), "Mb"); + check_string (g_format_size_full (238472938, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_ONLY_UNIT), "Mbit"); check_string (g_format_size_full (0, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_IEC_UNITS), "0 bits"); @@ -1002,17 +1002,17 @@ test_format_size_for_display (void) check_string (g_format_size_full (2, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_IEC_UNITS | G_FORMAT_SIZE_ONLY_VALUE), "2"); check_string (g_format_size_full (2, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_IEC_UNITS | G_FORMAT_SIZE_ONLY_UNIT), "bits"); - check_string (g_format_size_full (2048ULL, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_IEC_UNITS), "2.0\302\240Kib"); - check_string (g_format_size_full (2048ULL * 1024, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_IEC_UNITS), "2.0\302\240Mib"); - check_string (g_format_size_full (2048ULL * 1024 * 1024, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_IEC_UNITS), "2.0\302\240Gib"); - check_string (g_format_size_full (2048ULL * 1024 * 1024 * 1024, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_IEC_UNITS), "2.0\302\240Tib"); - check_string (g_format_size_full (2048ULL * 1024 * 1024 * 1024 * 1024, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_IEC_UNITS), "2.0\302\240Pib"); - check_string (g_format_size_full (2048ULL * 1024 * 1024 * 1024 * 1024 * 1024, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_IEC_UNITS), "2.0\302\240Eib"); + check_string (g_format_size_full (2048ULL, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_IEC_UNITS), "2.0\302\240Kibit"); + check_string (g_format_size_full (2048ULL * 1024, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_IEC_UNITS), "2.0\302\240Mibit"); + check_string (g_format_size_full (2048ULL * 1024 * 1024, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_IEC_UNITS), "2.0\302\240Gibit"); + check_string (g_format_size_full (2048ULL * 1024 * 1024 * 1024, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_IEC_UNITS), "2.0\302\240Tibit"); + check_string (g_format_size_full (2048ULL * 1024 * 1024 * 1024 * 1024, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_IEC_UNITS), "2.0\302\240Pibit"); + check_string (g_format_size_full (2048ULL * 1024 * 1024 * 1024 * 1024 * 1024, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_IEC_UNITS), "2.0\302\240Eibit"); - check_string (g_format_size_full (238472938, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_IEC_UNITS), "227.4\302\240Mib"); - check_string (g_format_size_full (238472938, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_IEC_UNITS | G_FORMAT_SIZE_LONG_FORMAT), "227.4\302\240Mib (238472938 bits)"); + check_string (g_format_size_full (238472938, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_IEC_UNITS), "227.4\302\240Mibit"); + check_string (g_format_size_full (238472938, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_IEC_UNITS | G_FORMAT_SIZE_LONG_FORMAT), "227.4\302\240Mibit (238472938 bits)"); check_string (g_format_size_full (238472938, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_IEC_UNITS | G_FORMAT_SIZE_ONLY_VALUE), "227.4"); - check_string (g_format_size_full (238472938, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_IEC_UNITS | G_FORMAT_SIZE_ONLY_UNIT), "Mib"); + check_string (g_format_size_full (238472938, G_FORMAT_SIZE_BITS | G_FORMAT_SIZE_IEC_UNITS | G_FORMAT_SIZE_ONLY_UNIT), "Mibit"); } static void -- GitLab From f42ff08d8e003e401779f944391ad83d40a29156 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Mon, 16 Oct 2023 02:26:49 +0000 Subject: [PATCH 2/2] Apply 1 suggestion(s) to 1 file(s) --- glib/gutils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glib/gutils.c b/glib/gutils.c index 59e32eb893..dd051a06fe 100644 --- a/glib/gutils.c +++ b/glib/gutils.c @@ -2913,7 +2913,7 @@ g_format_size (guint64 size) * a strong "power of 2" basis, like RAM sizes or RAID stripe sizes. * Network and storage sizes should be reported in the normal SI units. * @G_FORMAT_SIZE_BITS: set the size as a quantity in bits, rather than - * bytes, and return units in bits. For example, ‘Mb’ rather than ‘MB’. + * bytes, and return units in bits. For example, ‘Mbit’ rather than ‘MB’. * @G_FORMAT_SIZE_ONLY_VALUE: return only value, without unit; this should * not be used together with @G_FORMAT_SIZE_LONG_FORMAT * nor @G_FORMAT_SIZE_ONLY_UNIT. Since: 2.74 -- GitLab