summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Miranda <andreldm@xfce.org>2021-05-10 19:56:41 -0300
committerAndre Miranda <andreldm@xfce.org>2021-06-25 18:40:16 +0000
commit05af8d22462b9fc783bf5fa0eb1a72add7a455f5 (patch)
tree6393dfc26787d52dc5bdf56d24bb532fdee2e472
parentc881265b1e421bbf1cbf3f6afe5649f96cd8decc (diff)
downloadlibxfce4util-05af8d22462b9fc783bf5fa0eb1a72add7a455f5.tar.gz
Add xfce_unescape_desktop_entry_value
Relates to appfinder#8
-rw-r--r--docs/reference/libxfce4util-sections.txt1
-rw-r--r--libxfce4util/libxfce4util.symbols1
-rw-r--r--libxfce4util/xfce-miscutils.c46
-rw-r--r--libxfce4util/xfce-miscutils.h2
4 files changed, 50 insertions, 0 deletions
diff --git a/docs/reference/libxfce4util-sections.txt b/docs/reference/libxfce4util-sections.txt
index 3832504..14daab1 100644
--- a/docs/reference/libxfce4util-sections.txt
+++ b/docs/reference/libxfce4util-sections.txt
@@ -148,6 +148,7 @@ xfce_gethostname
xfce_expand_variables
xfce_append_quoted
xfce_expand_desktop_entry_field_codes
+xfce_unescape_desktop_entry_value
</SECTION>
diff --git a/libxfce4util/libxfce4util.symbols b/libxfce4util/libxfce4util.symbols
index 17da2c1..81bbebc 100644
--- a/libxfce4util/libxfce4util.symbols
+++ b/libxfce4util/libxfce4util.symbols
@@ -104,6 +104,7 @@ xfce_gethostname G_GNUC_MALLOC
xfce_expand_variables G_GNUC_MALLOC
xfce_append_quoted
xfce_expand_desktop_entry_field_codes G_GNUC_MALLOC
+xfce_unescape_desktop_entry_value G_GNUC_MALLOC
#endif
#endif
diff --git a/libxfce4util/xfce-miscutils.c b/libxfce4util/xfce-miscutils.c
index 27a7182..f5c0bc4 100644
--- a/libxfce4util/xfce-miscutils.c
+++ b/libxfce4util/xfce-miscutils.c
@@ -588,5 +588,51 @@ xfce_expand_desktop_entry_field_codes (const gchar *command,
+/**
+ * xfce_unescape_desktop_entry_value:
+ * @value : Value string to replace escape sequences.
+ *
+ * Unescapes sequences in @value according to Freedesktop.org Desktop Entry Specification.
+ *
+ * Return value: %NULL on error, else the string, which should be freed using g_free() when
+ * no longer needed.
+ *
+ * Since: 4.18
+ **/
+gchar*
+xfce_unescape_desktop_entry_value (const gchar *value)
+{
+ const gchar *p;
+ GString *string;
+
+ if (G_UNLIKELY (value == NULL))
+ return NULL;
+
+ string = g_string_sized_new (strlen (value));
+
+ for (p = value; *p != '\0'; ++p)
+ {
+ if (G_UNLIKELY (p[0] == '\\' && p[1] != '\0'))
+ {
+ switch (*++p)
+ {
+ case 's':
+ g_string_append_c (string, ' ');
+ break;
+
+ case '\\':
+ g_string_append_c (string, '\\');
+ break;
+ }
+ }
+ else
+ {
+ g_string_append_c (string, *p);
+ }
+ }
+
+ return g_string_free (string, FALSE);
+}
+
#define __XFCE_MISCUTILS_C__
#include <libxfce4util/libxfce4util-aliasdef.c>
diff --git a/libxfce4util/xfce-miscutils.h b/libxfce4util/xfce-miscutils.h
index 608eaf8..13ad1f0 100644
--- a/libxfce4util/xfce-miscutils.h
+++ b/libxfce4util/xfce-miscutils.h
@@ -100,6 +100,8 @@ gchar* xfce_expand_desktop_entry_field_codes (const gchar *command,
const gchar *uri,
gboolean requires_terminal) G_GNUC_MALLOC;
+gchar* xfce_unescape_desktop_entry_value (const gchar *value) G_GNUC_MALLOC;
+
G_END_DECLS
#endif /* __XFCE_MISCUTILS_H__ */