summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2016-03-03 12:56:33 +0000
committerRichard Hughes <richard@hughsie.com>2016-03-03 13:06:05 +0000
commitecb45f77ca3e553c00c861d3d659838dc298c507 (patch)
tree3ceb74d350a971359b8ba35b39818338821cce21
parent4efe58524c84bc34fc9680485feba7275eaf757d (diff)
downloadappstream-glib-ecb45f77ca3e553c00c861d3d659838dc298c507.tar.gz
Add a AsMarkupConvertFormat to as_markup_import()
This API is not in any released version and is not part of the API yet.
-rw-r--r--libappstream-builder/plugins/asb-plugin-shell-extension.c9
-rw-r--r--libappstream-glib/as-self-test.c6
-rw-r--r--libappstream-glib/as-utils.c37
-rw-r--r--libappstream-glib/as-utils.h6
4 files changed, 42 insertions, 16 deletions
diff --git a/libappstream-builder/plugins/asb-plugin-shell-extension.c b/libappstream-builder/plugins/asb-plugin-shell-extension.c
index 8842b1f..e86ba30 100644
--- a/libappstream-builder/plugins/asb-plugin-shell-extension.c
+++ b/libappstream-builder/plugins/asb-plugin-shell-extension.c
@@ -129,9 +129,12 @@ as_app_parse_shell_extension_data (AsApp *app,
tmp = json_object_get_string_member (json_obj, "description");
if (tmp != NULL) {
g_autofree gchar *desc = NULL;
- desc = as_markup_import (tmp);
- if (desc != NULL)
- as_app_set_description (app, NULL, desc);
+ desc = as_markup_import (tmp,
+ AS_MARKUP_CONVERT_FORMAT_SIMPLE,
+ error);
+ if (desc == NULL)
+ return FALSE;
+ as_app_set_description (app, NULL, desc);
}
}
if (json_object_has_member (json_obj, "url")) {
diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c
index 7d528c5..dbc300c 100644
--- a/libappstream-glib/as-self-test.c
+++ b/libappstream-glib/as-self-test.c
@@ -3742,7 +3742,11 @@ as_test_utils_markup_import_func (void)
};
for (i = 0; table[i].old != NULL; i++) {
g_autofree gchar *new = NULL;
- new = as_markup_import (table[i].old);
+ g_autoptr(GError) error = NULL;
+ new = as_markup_import (table[i].old,
+ AS_MARKUP_CONVERT_FORMAT_SIMPLE,
+ &error);
+ g_assert_no_error (error);
g_assert_cmpstr (new, ==, table[i].new);
}
}
diff --git a/libappstream-glib/as-utils.c b/libappstream-glib/as-utils.c
index 3cf2a24..d5d4a79 100644
--- a/libappstream-glib/as-utils.c
+++ b/libappstream-glib/as-utils.c
@@ -58,17 +58,10 @@
G_DEFINE_QUARK (as-utils-error-quark, as_utils_error)
/**
- * as_markup_import:
- * @text: the text to import.
- *
- * Imports unformatted text and converts to AppStream markup.
- *
- * Returns: (transfer full): appstream markup, or %NULL in event of an error
- *
- * Since: 0.5.11
+ * as_markup_import_simple:
*/
-gchar *
-as_markup_import (const gchar *text)
+static gchar *
+as_markup_import_simple (const gchar *text, GError **error)
{
GString *str;
guint i;
@@ -100,6 +93,30 @@ as_markup_import (const gchar *text)
}
/**
+ * as_markup_import:
+ * @text: the text to import.
+ * @format: the #AsMarkupConvertFormat, e.g. %AS_MARKUP_CONVERT_FORMAT_SIMPLE
+ * @error: A #GError or %NULL
+ *
+ * Imports text and converts to AppStream markup.
+ *
+ * Returns: (transfer full): appstream markup, or %NULL in event of an error
+ *
+ * Since: 0.5.11
+ */
+gchar *
+as_markup_import (const gchar *text, AsMarkupConvertFormat format, GError **error)
+{
+ if (format == AS_MARKUP_CONVERT_FORMAT_SIMPLE)
+ return as_markup_import_simple (text, error);
+ g_set_error_literal (error,
+ AS_UTILS_ERROR,
+ AS_UTILS_ERROR_INVALID_TYPE,
+ "unknown comnversion kind");
+ return NULL;
+}
+
+/**
* as_markup_strsplit_words:
* @text: the text to split.
* @line_len: the maximum length of the output line
diff --git a/libappstream-glib/as-utils.h b/libappstream-glib/as-utils.h
index b6dae41..7c5ffda 100644
--- a/libappstream-glib/as-utils.h
+++ b/libappstream-glib/as-utils.h
@@ -83,7 +83,7 @@ typedef enum {
* @AS_MARKUP_CONVERT_FORMAT_NULL: No output
* @AS_MARKUP_CONVERT_FORMAT_APPSTREAM: AppStream (passthrough)
*
- * The output format used when converting AppStream descriptions.
+ * The format used when converting to or from AppStream descriptions.
**/
typedef enum {
AS_MARKUP_CONVERT_FORMAT_SIMPLE,
@@ -135,7 +135,9 @@ gboolean as_markup_validate (const gchar *markup,
GError **error);
gchar **as_markup_strsplit_words (const gchar *text,
guint line_len);
-gchar *as_markup_import (const gchar *text);
+gchar *as_markup_import (const gchar *text,
+ AsMarkupConvertFormat format,
+ GError **error);
GQuark as_utils_error_quark (void);
gboolean as_utils_is_stock_icon_name (const gchar *name);