diff options
author | Kalev Lember <klember@redhat.com> | 2016-12-29 23:56:53 +0100 |
---|---|---|
committer | Kalev Lember <klember@redhat.com> | 2016-12-30 00:00:36 +0100 |
commit | 80cd5c18dd44003d81c35ce6ea197a8879f7daa0 (patch) | |
tree | 47818e9a5a356bfd82e29f710885a684f2134a4c /libappstream-glib/as-utils.c | |
parent | 959972c57e1b73a8ffd60e5719f8e10301a2ab3c (diff) | |
download | appstream-glib-80cd5c18dd44003d81c35ce6ea197a8879f7daa0.tar.gz |
Add support for "+" operator at the end of SPDX license identifierswip/kalev/spdx-+-tokenize
SPDX v2.0 and later support an unary "+" operator suffix at the end of
license identifiers, e.g. "CC-BY-SA-3.0+". This commit adds support for
tokenizing and detokenizing this and adds new tests.
Diffstat (limited to 'libappstream-glib/as-utils.c')
-rw-r--r-- | libappstream-glib/as-utils.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/libappstream-glib/as-utils.c b/libappstream-glib/as-utils.c index ba5e11a..84ced4b 100644 --- a/libappstream-glib/as-utils.c +++ b/libappstream-glib/as-utils.c @@ -342,6 +342,18 @@ as_utils_spdx_license_tokenize_drop (AsUtilsSpdxHelper *helper) return; } + /* is license enum with "+" */ + if (g_str_has_suffix (tmp, "+")) { + g_autofree gchar *license_id = g_strndup (tmp, strlen (tmp) - 1); + if (as_utils_is_spdx_license_id (license_id)) { + g_ptr_array_add (helper->array, g_strdup_printf ("@%s", license_id)); + g_ptr_array_add (helper->array, g_strdup ("+")); + helper->last_token_literal = FALSE; + g_string_truncate (helper->collect, 0); + return; + } + } + /* is old license enum */ for (i = 0; licenses[i].old != NULL; i++) { if (g_strcmp0 (tmp, licenses[i].old) != 0) @@ -466,6 +478,10 @@ as_utils_spdx_license_detokenize (gchar **license_tokens) g_string_append (tmp, " OR "); continue; } + if (g_strcmp0 (license_tokens[i], "+") == 0) { + g_string_append (tmp, "+"); + continue; + } if (license_tokens[i][0] != '@') { g_string_append (tmp, license_tokens[i]); continue; @@ -518,6 +534,8 @@ as_utils_is_spdx_license (const gchar *license) continue; if (g_strcmp0 (tokens[i], "|") == 0) continue; + if (g_strcmp0 (tokens[i], "+") == 0) + continue; return FALSE; } return TRUE; |