diff options
author | Lubomir Rintel <lkundrak@v3.sk> | 2018-02-23 14:52:05 +0100 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2018-02-23 19:47:19 +0100 |
commit | f7805ab602df78b5828ef361988d1c4559dd5de2 (patch) | |
tree | a6f0869ffbc405f87ef3b46c5d879319e67fed0a /libnm | |
parent | 280d095fdffd569c64bc7516cce1a2ea8751f5f9 (diff) | |
download | NetworkManager-f7805ab602df78b5828ef361988d1c4559dd5de2.tar.gz |
libnm/utils: deal with the square brackets on producr/vendor fixup
If there's a [<string>] that survived the substitution, then the string
is supposed to be a short form that is generally preferrable.
That's great in theory, but actually it's rather often pure garbage for
product names. Let's prefer it just for vendors and provide an option to
drop it (will be useful for fixing up product names).
Diffstat (limited to 'libnm')
-rw-r--r-- | libnm/nm-libnm-utils.c | 38 | ||||
-rw-r--r-- | libnm/tests/test-general.c | 5 |
2 files changed, 38 insertions, 5 deletions
diff --git a/libnm/nm-libnm-utils.c b/libnm/nm-libnm-utils.c index 9aea2d47d5..7ecf63b4ae 100644 --- a/libnm/nm-libnm-utils.c +++ b/libnm/nm-libnm-utils.c @@ -28,7 +28,8 @@ static char * _fixup_string (const char *desc, const char *const *ignored_phrases, - const char *const *ignored_words) + const char *const *ignored_words, + gboolean square_brackets_sensible) { char *desc_full; gboolean in_paren = FALSE; @@ -116,6 +117,31 @@ next: *q++ = '\0'; + p = strchr (desc_full, '['); + if (p == desc_full) { + /* All we're left with is in square brackets. + * Always prefer that to a blank string.*/ + square_brackets_sensible = TRUE; + } + if (square_brackets_sensible) { + /* If there's a [<string>] that survived the substitution, then the string + * is a short form that is generally preferrable. */ + q = strchr (desc_full, ']'); + if (p && q > p) { + p++; + memmove (desc_full, p, q - p); + desc_full[q - p] = '\0'; + } + } else { + /* [<string>] sometimes contains the preferred human-readable name, but + * mostly it's utterly useless. Sigh. Drop it. */ + if (p) { + if (p > desc_full && p[-1] == ' ') + p--; + *p = '\0'; + } + } + if (!desc_full[0]) { g_free (desc_full); return NULL; @@ -208,7 +234,7 @@ nm_utils_fixup_vendor_string (const char *desc) }; char *desc_full; - desc_full = _fixup_string (desc, IGNORED_PHRASES, IGNORED_WORDS); + desc_full = _fixup_string (desc, IGNORED_PHRASES, IGNORED_WORDS, TRUE); if (desc_full) nm_assert (g_utf8_validate (desc_full, -1, NULL)); @@ -247,9 +273,11 @@ nm_utils_fixup_desc_string (const char *desc) }; char *desc_full; - desc_full = _fixup_string (desc, IGNORED_PHRASES, IGNORED_WORDS); - if (desc_full) - nm_assert (g_utf8_validate (desc_full, -1, NULL)); + desc_full = _fixup_string (desc, IGNORED_PHRASES, IGNORED_WORDS, FALSE); + if (!desc_full) + return NULL; + + nm_assert (g_utf8_validate (desc_full, -1, NULL)); return desc_full; } diff --git a/libnm/tests/test-general.c b/libnm/tests/test-general.c index 7a82845ad3..2483579bed 100644 --- a/libnm/tests/test-general.c +++ b/libnm/tests/test-general.c @@ -69,6 +69,7 @@ test_fixup_vendor_string (void) T (nm_utils_fixup_vendor_string, "ADMtek", "ADMtek"); T (nm_utils_fixup_vendor_string, "ADMtek, Inc.", "ADMtek"); T (nm_utils_fixup_vendor_string, "ADS Technologies, Inc.", "ADS"); + T (nm_utils_fixup_vendor_string, "Advanced Micro Devices, Inc. [AMD]", "AMD"); T (nm_utils_fixup_vendor_string, "Advance Multimedia Internet Technology Inc. (AMIT)", "Advance"); T (nm_utils_fixup_vendor_string, "AEI", "AEI"); T (nm_utils_fixup_vendor_string, "Airprime, Incorporated", "Airprime"); @@ -198,6 +199,7 @@ test_fixup_vendor_string (void) T (nm_utils_fixup_vendor_string, "Logitec Corp.", "Logitec"); T (nm_utils_fixup_vendor_string, "Logitech, Inc.", "Logitech"); T (nm_utils_fixup_vendor_string, "LSI Corporation", "LSI"); + T (nm_utils_fixup_vendor_string, "Macronix, Inc. [MXIC]", "MXIC"); T (nm_utils_fixup_vendor_string, "Marvell Semiconductor, Inc.", "Marvell"); T (nm_utils_fixup_vendor_string, "Marvell Technology Group Ltd.", "Marvell"); T (nm_utils_fixup_vendor_string, "MediaTek Inc.", "MediaTek"); @@ -208,6 +210,7 @@ test_fixup_vendor_string (void) T (nm_utils_fixup_vendor_string, "Microcomputer Systems (M) Son", "Microcomputer"); T (nm_utils_fixup_vendor_string, "Microsoft Corp.", "Microsoft"); T (nm_utils_fixup_vendor_string, "Microsoft Corporation", "Microsoft"); + T (nm_utils_fixup_vendor_string, "Micro-Star International Co., Ltd. [MSI]", "MSI"); T (nm_utils_fixup_vendor_string, "Micro Star International", "Micro Star"); T (nm_utils_fixup_vendor_string, "Mobility", "Mobility"); T (nm_utils_fixup_vendor_string, "MosChip Semiconductor", "MosChip"); @@ -282,6 +285,7 @@ test_fixup_vendor_string (void) T (nm_utils_fixup_vendor_string, "Sierra Wireless, Inc.", "Sierra Wireless"); T (nm_utils_fixup_vendor_string, "Silicom", "Silicom"); T (nm_utils_fixup_vendor_string, "Silicon Graphics Intl. Corp.", "Silicon Graphics"); + T (nm_utils_fixup_vendor_string, "Silicon Integrated Systems [SiS]", "SiS"); T (nm_utils_fixup_vendor_string, "Sitecom Europe B.V.", "Sitecom"); T (nm_utils_fixup_vendor_string, "Sitecom", "Sitecom"); T (nm_utils_fixup_vendor_string, "smartBridges, Inc.", "smartBridges"); @@ -290,6 +294,7 @@ test_fixup_vendor_string (void) T (nm_utils_fixup_vendor_string, "Sony Corp.", "Sony"); T (nm_utils_fixup_vendor_string, "SpeedStream", "SpeedStream"); T (nm_utils_fixup_vendor_string, "Sphairon Access Systems GmbH", "Sphairon"); + T (nm_utils_fixup_vendor_string, "Standard Microsystems Corp [SMC]", "SMC"); T (nm_utils_fixup_vendor_string, "Standard Microsystems Corp.", "Standard"); T (nm_utils_fixup_vendor_string, "STMicroelectronics", "STMicroelectronics"); T (nm_utils_fixup_vendor_string, "Surecom Technology Corp.", "Surecom"); |