pidgin/gtkimhtml.c

changeset 22596
0854ae660ef4
parent 22595
5ce90eecd894
child 22656
c4c7c4852390
child 22703
2cc5d0981559
equal deleted inserted replaced
22595:5ce90eecd894 22596:0854ae660ef4
850 850
851 be = G_BYTE_ORDER == G_BIG_ENDIAN; 851 be = G_BYTE_ORDER == G_BIG_ENDIAN;
852 be = swap ? be : !be; 852 be = swap ? be : !be;
853 853
854 if (be) 854 if (be)
855 return "UCS-2BE"; 855 return "UTF-16BE";
856 else 856 else
857 return "UCS-2LE"; 857 return "UTF-16LE";
858 858
859 } 859 }
860 860
861 /* Convert from UCS-2 to UTF-8, stripping the BOM if one is present.*/ 861 /* Convert from UTF-16LE to UTF-8, stripping the BOM if one is present.*/
862 static gchar * 862 static gchar *
863 ucs2_to_utf8_with_bom_check(gchar *data, guint len) { 863 utf16_to_utf8_with_bom_check(gchar *data, guint len) {
864 char *fromcode = NULL; 864 char *fromcode = NULL;
865 GError *error = NULL; 865 GError *error = NULL;
866 guint16 c; 866 guint16 c;
867 gchar *utf8_ret; 867 gchar *utf8_ret;
868 868
881 fromcode = ucs2_order(c == 0xfeff); 881 fromcode = ucs2_order(c == 0xfeff);
882 data += 2; 882 data += 2;
883 len -= 2; 883 len -= 2;
884 break; 884 break;
885 default: 885 default:
886 fromcode = "UCS-2"; 886 fromcode = "UTF-16";
887 break; 887 break;
888 } 888 }
889 889
890 utf8_ret = g_convert(data, len, "UTF-8", fromcode, NULL, NULL, &error); 890 utf8_ret = g_convert(data, len, "UTF-8", fromcode, NULL, NULL, &error);
891 891
925 925
926 /* Mozilla asks that we start our text/html with the Unicode byte order mark */ 926 /* Mozilla asks that we start our text/html with the Unicode byte order mark */
927 str = g_string_append_unichar(str, 0xfeff); 927 str = g_string_append_unichar(str, 0xfeff);
928 str = g_string_append(str, text); 928 str = g_string_append(str, text);
929 str = g_string_append_unichar(str, 0x0000); 929 str = g_string_append_unichar(str, 0x0000);
930 selection = g_convert(str->str, str->len, "UCS-2", "UTF-8", NULL, &len, NULL); 930 selection = g_convert(str->str, str->len, "UTF-16", "UTF-8", NULL, &len, NULL);
931 gtk_selection_data_set(selection_data, gdk_atom_intern("text/html", FALSE), 16, (const guchar *)selection, len); 931 gtk_selection_data_set(selection_data, gdk_atom_intern("text/html", FALSE), 16, (const guchar *)selection, len);
932 g_string_free(str, TRUE); 932 g_string_free(str, TRUE);
933 #else 933 #else
934 selection = clipboard_html_to_win32(html_clipboard); 934 selection = clipboard_html_to_win32(html_clipboard);
935 gtk_selection_data_set(selection_data, gdk_atom_intern("HTML Format", FALSE), 8, (const guchar *)selection, strlen(selection)); 935 gtk_selection_data_set(selection_data, gdk_atom_intern("HTML Format", FALSE), 8, (const guchar *)selection, strlen(selection));
1080 memcpy(text, selection_data->data, selection_data->length); 1080 memcpy(text, selection_data->data, selection_data->length);
1081 } 1081 }
1082 1082
1083 if (selection_data->length >= 2 && 1083 if (selection_data->length >= 2 &&
1084 (*(guint16 *)text == 0xfeff || *(guint16 *)text == 0xfffe)) { 1084 (*(guint16 *)text == 0xfeff || *(guint16 *)text == 0xfffe)) {
1085 /* This is UCS-2 */ 1085 /* This is UTF-16 */
1086 char *utf8 = ucs2_to_utf8_with_bom_check(text, selection_data->length); 1086 char *utf8 = utf16_to_utf8_with_bom_check(text, selection_data->length);
1087 g_free(text); 1087 g_free(text);
1088 text = utf8; 1088 text = utf8;
1089 if (!text) { 1089 if (!text) {
1090 purple_debug_warning("gtkimhtml", "g_convert from UCS-2 failed in paste_received_cb\n"); 1090 purple_debug_warning("gtkimhtml", "g_convert from UTF-16 failed in paste_received_cb\n");
1091 return; 1091 return;
1092 } 1092 }
1093 } 1093 }
1094 1094
1095 if (!(*text) || !g_utf8_validate(text, -1, NULL)) { 1095 if (!(*text) || !g_utf8_validate(text, -1, NULL)) {
1782 * 1782 *
1783 * See also the comment on text/html here: 1783 * See also the comment on text/html here:
1784 * http://mail.gnome.org/archives/gtk-devel-list/2001-September/msg00114.html 1784 * http://mail.gnome.org/archives/gtk-devel-list/2001-September/msg00114.html
1785 */ 1785 */
1786 if (sd->length >= 2 && !g_utf8_validate(text, sd->length - 1, NULL)) { 1786 if (sd->length >= 2 && !g_utf8_validate(text, sd->length - 1, NULL)) {
1787 utf8 = ucs2_to_utf8_with_bom_check(text, sd->length); 1787 utf8 = utf16_to_utf8_with_bom_check(text, sd->length);
1788 1788
1789 if (!utf8) { 1789 if (!utf8) {
1790 purple_debug_warning("gtkimhtml", "g_convert from UCS-2 failed in drag_rcv_cb\n"); 1790 purple_debug_warning("gtkimhtml", "g_convert from UTF-16 failed in drag_rcv_cb\n");
1791 return; 1791 return;
1792 } 1792 }
1793 } else if (!(*text) || !g_utf8_validate(text, -1, NULL)) { 1793 } else if (!(*text) || !g_utf8_validate(text, -1, NULL)) {
1794 purple_debug_warning("gtkimhtml", "empty string or invalid UTF-8 in drag_rcv_cb\n"); 1794 purple_debug_warning("gtkimhtml", "empty string or invalid UTF-8 in drag_rcv_cb\n");
1795 return; 1795 return;

mercurial