summaryrefslogtreecommitdiff
path: root/pango/querymodules.c
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2002-07-31 16:46:55 +0000
committerOwen Taylor <otaylor@src.gnome.org>2002-07-31 16:46:55 +0000
commit682109791d6b704d169aca87c1c0f4dc0dace9df (patch)
tree123c48edd4eb6fbd0b434e380d3618df244c0715 /pango/querymodules.c
parentd4d6d7317dce6981a8491fb52f9211694830bf2b (diff)
downloadpango-682109791d6b704d169aca87c1c0f4dc0dace9df.tar.gz
Avoid using g_strescape(), since it mangles UTF-8. (#89479, Yao Zhang)
Wed Jul 31 12:38:36 2002 Owen Taylor <otaylor@redhat.com> * pango/querymodules.c (string_needs_escape): Avoid using g_strescape(), since it mangles UTF-8. (#89479, Yao Zhang)
Diffstat (limited to 'pango/querymodules.c')
-rw-r--r--pango/querymodules.c46
1 files changed, 44 insertions, 2 deletions
diff --git a/pango/querymodules.c b/pango/querymodules.c
index 5ae7789a..95c67d89 100644
--- a/pango/querymodules.c
+++ b/pango/querymodules.c
@@ -42,6 +42,48 @@
#endif
#define SOEXT_LEN (strlen (SOEXT))
+static gboolean
+string_needs_escape (const char *str)
+{
+ while (TRUE)
+ {
+ char c = *str++;
+
+ if (!c)
+ return FALSE;
+ else if (c == '\"' || g_ascii_isspace (c))
+ return TRUE;
+ }
+}
+
+static char *
+escape_string (const char *str)
+{
+ GString *result = g_string_new ("");
+
+ while (TRUE)
+ {
+ char c = *str++;
+
+ switch (c)
+ {
+ case '\0':
+ goto done;
+ case '\n':
+ g_string_append (result, "\\n");
+ break;
+ case '\"':
+ g_string_append (result, "\\\"");
+ break;
+ default:
+ g_string_append_c (result, c);
+ }
+ }
+
+ done:
+ return g_string_free (result, FALSE);
+}
+
void
query_module (const char *dir, const char *name)
{
@@ -78,10 +120,10 @@ query_module (const char *dir, const char *name)
const gchar *quote;
gchar *quoted_path;
- if (strchr (path, ' ') != NULL)
+ if (string_needs_escape (path))
{
quote = "\"";
- quoted_path = g_strescape (path, NULL);
+ quoted_path = escape_string (path);
}
else
{