summaryrefslogtreecommitdiff
path: root/libnm/nm-libnm-utils.c
diff options
context:
space:
mode:
authorLubomir Rintel <lkundrak@v3.sk>2018-02-23 14:52:05 +0100
committerLubomir Rintel <lkundrak@v3.sk>2018-02-23 19:47:19 +0100
commitf7805ab602df78b5828ef361988d1c4559dd5de2 (patch)
treea6f0869ffbc405f87ef3b46c5d879319e67fed0a /libnm/nm-libnm-utils.c
parent280d095fdffd569c64bc7516cce1a2ea8751f5f9 (diff)
downloadNetworkManager-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/nm-libnm-utils.c')
-rw-r--r--libnm/nm-libnm-utils.c38
1 files changed, 33 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;
}