diff options
author | Benjamin Otte <otte@redhat.com> | 2020-02-22 18:33:20 +0100 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2020-02-23 01:59:00 +0100 |
commit | 6442ec2f8d3460d67cc567c2c76f374c9f6f70f6 (patch) | |
tree | 0cfe3b06ed7fb96a92296fec782d8e9bb178dada /gdk/x11 | |
parent | a62d78bf708024da3e6dec92578c511172e4ee7f (diff) | |
download | gtk+-6442ec2f8d3460d67cc567c2c76f374c9f6f70f6.tar.gz |
gdk: Remove gdk_utf8_to_string_target()
Only keep the X11 version around in the backend.
Diffstat (limited to 'gdk/x11')
-rw-r--r-- | gdk/x11/gdkdisplay-x11.c | 1 | ||||
-rw-r--r-- | gdk/x11/gdkprivate-x11.h | 4 | ||||
-rw-r--r-- | gdk/x11/gdkselection-x11.c | 66 | ||||
-rw-r--r-- | gdk/x11/gdksurface-x11.c | 2 | ||||
-rw-r--r-- | gdk/x11/gdktextlistconverter-x11.c | 59 |
5 files changed, 62 insertions, 70 deletions
diff --git a/gdk/x11/gdkdisplay-x11.c b/gdk/x11/gdkdisplay-x11.c index 5a863f9000..7147ad6a23 100644 --- a/gdk/x11/gdkdisplay-x11.c +++ b/gdk/x11/gdkdisplay-x11.c @@ -3053,7 +3053,6 @@ gdk_x11_display_class_init (GdkX11DisplayClass * class) display_class->create_surface = _gdk_x11_display_create_surface; display_class->get_keymap = gdk_x11_display_get_keymap; display_class->text_property_to_utf8_list = _gdk_x11_display_text_property_to_utf8_list; - display_class->utf8_to_string_target = _gdk_x11_display_utf8_to_string_target; display_class->make_gl_context_current = gdk_x11_display_make_gl_context_current; diff --git a/gdk/x11/gdkprivate-x11.h b/gdk/x11/gdkprivate-x11.h index 69a1248b8a..5bd6bb3e75 100644 --- a/gdk/x11/gdkprivate-x11.h +++ b/gdk/x11/gdkprivate-x11.h @@ -125,8 +125,8 @@ gint _gdk_x11_display_text_property_to_utf8_list (GdkDisplay *display const guchar *text, gint length, gchar ***list); -gchar * _gdk_x11_display_utf8_to_string_target (GdkDisplay *displayt, - const gchar *str); +char * gdk_x11_utf8_to_string_target (const char *utf8_str, + gboolean return_latin1); void _gdk_x11_device_check_extension_events (GdkDevice *device); diff --git a/gdk/x11/gdkselection-x11.c b/gdk/x11/gdkselection-x11.c index 7f34dfce84..169ba661fa 100644 --- a/gdk/x11/gdkselection-x11.c +++ b/gdk/x11/gdkselection-x11.c @@ -325,70 +325,6 @@ gdk_x11_display_string_to_compound_text (GdkDisplay *display, return res; } -/* The specifications for COMPOUND_TEXT and STRING specify that C0 and - * C1 are not allowed except for \n and \t, however the X conversions - * routines for COMPOUND_TEXT only enforce this in one direction, - * causing cut-and-paste of \r and \r\n separated text to fail. - * This routine strips out all non-allowed C0 and C1 characters - * from the input string and also canonicalizes \r, and \r\n to \n - */ -static gchar * -sanitize_utf8 (const gchar *src, - gboolean return_latin1) -{ - gint len = strlen (src); - GString *result = g_string_sized_new (len); - const gchar *p = src; - - while (*p) - { - if (*p == '\r') - { - p++; - if (*p == '\n') - p++; - - g_string_append_c (result, '\n'); - } - else - { - gunichar ch = g_utf8_get_char (p); - - if (!((ch < 0x20 && ch != '\t' && ch != '\n') || (ch >= 0x7f && ch < 0xa0))) - { - if (return_latin1) - { - if (ch <= 0xff) - g_string_append_c (result, ch); - else - g_string_append_printf (result, - ch < 0x10000 ? "\\u%04x" : "\\U%08x", - ch); - } - else - { - char buf[7]; - gint buflen; - - buflen = g_unichar_to_utf8 (ch, buf); - g_string_append_len (result, buf, buflen); - } - } - - p = g_utf8_next_char (p); - } - } - - return g_string_free (result, FALSE); -} - -gchar * -_gdk_x11_display_utf8_to_string_target (GdkDisplay *display, - const gchar *str) -{ - return sanitize_utf8 (str, TRUE); -} - /** * gdk_x11_display_utf8_to_compound_text: * @display: (type GdkX11Display): a #GdkDisplay @@ -423,7 +359,7 @@ gdk_x11_display_utf8_to_compound_text (GdkDisplay *display, need_conversion = !g_get_charset (&charset); - tmp_str = sanitize_utf8 (str, FALSE); + tmp_str = gdk_x11_utf8_to_string_target (str, FALSE); if (need_conversion) { diff --git a/gdk/x11/gdksurface-x11.c b/gdk/x11/gdksurface-x11.c index 699bcf2864..f023e09473 100644 --- a/gdk/x11/gdksurface-x11.c +++ b/gdk/x11/gdksurface-x11.c @@ -2235,7 +2235,7 @@ set_text_property (GdkDisplay *display, if (utf8_is_latin1 (utf8_str)) { prop_type = XA_STRING; - prop_text = _gdk_x11_display_utf8_to_string_target (display, utf8_str); + prop_text = gdk_x11_utf8_to_string_target (utf8_str, TRUE); prop_length = prop_text ? strlen (prop_text) : 0; prop_format = 8; is_compound_text = FALSE; diff --git a/gdk/x11/gdktextlistconverter-x11.c b/gdk/x11/gdktextlistconverter-x11.c index 38c7df9a71..88c4a5310f 100644 --- a/gdk/x11/gdktextlistconverter-x11.c +++ b/gdk/x11/gdktextlistconverter-x11.c @@ -121,6 +121,63 @@ gdk_x11_text_list_converter_decode (GdkX11TextListConverter *conv, } } +/* The specifications for COMPOUND_TEXT and STRING specify that C0 and + * C1 are not allowed except for \n and \t, however the X conversions + * routines for COMPOUND_TEXT only enforce this in one direction, + * causing cut-and-paste of \r and \r\n separated text to fail. + * This routine strips out all non-allowed C0 and C1 characters + * from the input string and also canonicalizes \r, and \r\n to \n + */ +char * +gdk_x11_utf8_to_string_target (const char *utf8_str, + gboolean return_latin1) +{ + gint len = strlen (utf8_str); + GString *result = g_string_sized_new (len); + const gchar *p = utf8_str; + + while (*p) + { + if (*p == '\r') + { + p++; + if (*p == '\n') + p++; + + g_string_append_c (result, '\n'); + } + else + { + gunichar ch = g_utf8_get_char (p); + + if (!((ch < 0x20 && ch != '\t' && ch != '\n') || (ch >= 0x7f && ch < 0xa0))) + { + if (return_latin1) + { + if (ch <= 0xff) + g_string_append_c (result, ch); + else + g_string_append_printf (result, + ch < 0x10000 ? "\\u%04x" : "\\U%08x", + ch); + } + else + { + char buf[7]; + gint buflen; + + buflen = g_unichar_to_utf8 (ch, buf); + g_string_append_len (result, buf, buflen); + } + } + + p = g_utf8_next_char (p); + } + } + + return g_string_free (result, FALSE); +} + static GConverterResult gdk_x11_text_list_converter_encode (GdkX11TextListConverter *conv, const void *inbuf, @@ -146,7 +203,7 @@ gdk_x11_text_list_converter_encode (GdkX11TextListConverter *conv, gchar *tmp, *latin1; tmp = g_strndup (inbuf, inbuf_size); - latin1 = gdk_utf8_to_string_target (tmp); + latin1 = gdk_x11_utf8_to_string_target (tmp, TRUE); g_free (tmp); if (latin1) { |