mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-04-17 15:00:43 +02:00
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).
This commit is contained in:
parent
280d095fdf
commit
f7805ab602
2 changed files with 38 additions and 5 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue