[gnome-software] Correctly extract the correct language for preformatted AppStream descriptions
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Correctly extract the correct language for preformatted AppStream descriptions
- Date: Thu, 14 Nov 2013 19:42:33 +0000 (UTC)
commit 5369795ce142e6add54a6c0e04da570f8491f1a8
Author: Richard Hughes <richard hughsie com>
Date: Thu Nov 14 19:41:32 2013 +0000
Correctly extract the correct language for preformatted AppStream descriptions
src/plugins/appstream-cache.c | 1 +
src/plugins/appstream-markup.c | 20 +++++++++++++++++---
src/plugins/appstream-markup.h | 1 +
src/plugins/gs-self-test.c | 7 +++++++
4 files changed, 26 insertions(+), 3 deletions(-)
---
diff --git a/src/plugins/appstream-cache.c b/src/plugins/appstream-cache.c
index 67b550f..d51eb7f 100644
--- a/src/plugins/appstream-cache.c
+++ b/src/plugins/appstream-cache.c
@@ -325,6 +325,7 @@ appstream_cache_start_element_cb (GMarkupParseContext *context,
appstream_tag_to_string (helper->tag));
return;
}
+ appstream_markup_reset (helper->markup);
helper->item_temp = appstream_app_new ();
appstream_app_set_priority (helper->item_temp, helper->priority);
appstream_app_set_userdata (helper->item_temp,
diff --git a/src/plugins/appstream-markup.c b/src/plugins/appstream-markup.c
index 7032cdf..9e1e294 100644
--- a/src/plugins/appstream-markup.c
+++ b/src/plugins/appstream-markup.c
@@ -31,6 +31,7 @@ struct AppstreamMarkup
gboolean enabled;
gchar *lang;
guint locale_value;
+ gboolean preformatted;
};
/**
@@ -45,6 +46,17 @@ appstream_markup_free (AppstreamMarkup *markup)
}
/**
+ * appstream_markup_reset:
+ */
+void
+appstream_markup_reset (AppstreamMarkup *markup)
+{
+ markup->preformatted = FALSE;
+ markup->locale_value = G_MAXUINT;
+ g_string_truncate (markup->string, 0);
+}
+
+/**
* appstream_markup_new:
*/
AppstreamMarkup *
@@ -103,8 +115,8 @@ appstream_markup_set_mode (AppstreamMarkup *markup, AppstreamMarkupMode mode)
markup->mode = APPSTREAM_MARKUP_MODE_LI_CONTENT;
break;
case APPSTREAM_MARKUP_MODE_START:
- markup->locale_value = G_MAXUINT;
- g_string_truncate (markup->string, 0);
+ if (!markup->preformatted)
+ appstream_markup_reset (markup);
markup->mode = mode;
break;
case APPSTREAM_MARKUP_MODE_END:
@@ -161,8 +173,10 @@ appstream_markup_add_content (AppstreamMarkup *markup,
tmp = appstream_xml_unmunge_safe (text, length);
if (tmp == NULL)
break;
- if (!appstream_text_is_whitespace (tmp))
+ if (!appstream_text_is_whitespace (tmp)) {
g_string_append (markup->string, tmp);
+ markup->preformatted = TRUE;
+ }
break;
case APPSTREAM_MARKUP_MODE_P_CONTENT:
tmp = appstream_xml_unmunge (text, length);
diff --git a/src/plugins/appstream-markup.h b/src/plugins/appstream-markup.h
index d3d5089..e8deb02 100644
--- a/src/plugins/appstream-markup.h
+++ b/src/plugins/appstream-markup.h
@@ -45,6 +45,7 @@ typedef struct AppstreamMarkup AppstreamMarkup;
AppstreamMarkup *appstream_markup_new (void);
void appstream_markup_free (AppstreamMarkup *markup);
+void appstream_markup_reset (AppstreamMarkup *markup);
void appstream_markup_set_enabled (AppstreamMarkup *markup,
gboolean enabled);
void appstream_markup_set_mode (AppstreamMarkup *markup,
diff --git a/src/plugins/gs-self-test.c b/src/plugins/gs-self-test.c
index b25f9ab..c86fa3c 100644
--- a/src/plugins/gs-self-test.c
+++ b/src/plugins/gs-self-test.c
@@ -59,9 +59,16 @@ appstream_markup_plain_func (void)
markup = appstream_markup_new ();
appstream_markup_set_enabled (markup, TRUE);
appstream_markup_set_lang (markup, NULL);
+
appstream_markup_set_mode (markup, APPSTREAM_MARKUP_MODE_START);
appstream_markup_add_content (markup, "This is preformatted\n\nOne", -1);
appstream_markup_set_mode (markup, APPSTREAM_MARKUP_MODE_END);
+
+ appstream_markup_set_mode (markup, APPSTREAM_MARKUP_MODE_START);
+ appstream_markup_set_lang (markup, "xx_XX");
+ appstream_markup_add_content (markup, "This is dave\n\nOne", -1);
+ appstream_markup_set_mode (markup, APPSTREAM_MARKUP_MODE_END);
+
tmp = appstream_markup_get_text (markup);
g_assert_cmpstr (tmp, ==, "This is preformatted\n\nOne");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]