summaryrefslogtreecommitdiff
path: root/libappstream-glib/as-utils.c
diff options
context:
space:
mode:
authorKalev Lember <klember@redhat.com>2016-12-29 23:56:53 +0100
committerKalev Lember <klember@redhat.com>2016-12-31 17:23:11 +0200
commitee450bd49c6c6d4a89d14d88e93334805524aecc (patch)
tree361ef52e4392a054be0c67cafbd55a5c527dcacc /libappstream-glib/as-utils.c
parent2163c7c20f224abbd693f8128e98384ffac082eb (diff)
downloadappstream-glib-ee450bd49c6c6d4a89d14d88e93334805524aecc.tar.gz
Add support for "+" operator at the end of SPDX license identifiers
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.c18
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;