diff options
author | Richard Hughes <richard@hughsie.com> | 2015-09-23 17:13:37 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2015-09-23 19:46:28 +0100 |
commit | c14ea9def41aa41c2b6fd5f2eaf943dc3b5d459d (patch) | |
tree | a415e75fd4e3498052881c53fb23939862194e67 | |
parent | c469ad4fa0b12532a031d7ac66cd1fc29b25bd4c (diff) | |
download | appstream-glib-c14ea9def41aa41c2b6fd5f2eaf943dc3b5d459d.tar.gz |
Accept a '0x' hexidecimal prefix when parsing a component
-rw-r--r-- | libappstream-glib/as-release.c | 19 | ||||
-rw-r--r-- | libappstream-glib/as-self-test.c | 4 |
2 files changed, 17 insertions, 6 deletions
diff --git a/libappstream-glib/as-release.c b/libappstream-glib/as-release.c index ccf78fb..7946deb 100644 --- a/libappstream-glib/as-release.c +++ b/libappstream-glib/as-release.c @@ -320,6 +320,16 @@ as_release_set_version (AsRelease *release, const gchar *version) { AsReleasePrivate *priv = GET_PRIVATE (release); g_free (priv->version); + + /* convert 0x prefixed strings to base 10 */ + if (g_str_has_prefix (version, "0x")) { + guint64 tmp; + tmp = g_ascii_strtoull (version + 2, NULL, 16); + priv->version = g_strdup_printf ("%" G_GUINT64_FORMAT, tmp); + return; + } + + /* no special rule */ priv->version = g_strdup (version); } @@ -496,7 +506,6 @@ as_release_node_parse (AsRelease *release, GNode *node, AsReleasePrivate *priv = GET_PRIVATE (release); GNode *n; const gchar *tmp; - gchar *taken; tmp = as_node_get_attribute (node, "timestamp"); if (tmp != NULL) @@ -504,11 +513,9 @@ as_release_node_parse (AsRelease *release, GNode *node, tmp = as_node_get_attribute (node, "urgency"); if (tmp != NULL) as_release_set_urgency (release, as_urgency_kind_from_string (tmp)); - taken = as_node_take_attribute (node, "version"); - if (taken != NULL) { - g_free (priv->version); - priv->version = taken; - } + tmp = as_node_get_attribute (node, "version"); + if (tmp != NULL) + as_release_set_version (release, tmp); /* get optional locations */ g_ptr_array_set_size (priv->locations, 0); diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c index e9e8b41..0d8e695 100644 --- a/libappstream-glib/as-self-test.c +++ b/libappstream-glib/as-self-test.c @@ -375,6 +375,10 @@ as_test_release_func (void) g_assert (ret); g_string_free (xml, TRUE); as_node_unref (root); + + /* verify converting hex prefix */ + as_release_set_version (release, "0x600100"); + g_assert_cmpstr (as_release_get_version (release), ==, "6291712"); } static void |