aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/misc
diff options
context:
space:
mode:
authorChristopher James Lahey <clahey@ximian.com>2001-02-07 06:57:01 +0800
committerChris Lahey <clahey@src.gnome.org>2001-02-07 06:57:01 +0800
commit4a01c7558799e57732fe620670d6a73f1859c1b5 (patch)
treef798c00be2dab14a25f4ee1d250a91f3832afbfc /widgets/misc
parent2a8a66ab471738acc605c29169cfbe418146ceab (diff)
downloadgsoc2013-evolution-4a01c7558799e57732fe620670d6a73f1859c1b5.tar
gsoc2013-evolution-4a01c7558799e57732fe620670d6a73f1859c1b5.tar.gz
gsoc2013-evolution-4a01c7558799e57732fe620670d6a73f1859c1b5.tar.bz2
gsoc2013-evolution-4a01c7558799e57732fe620670d6a73f1859c1b5.tar.lz
gsoc2013-evolution-4a01c7558799e57732fe620670d6a73f1859c1b5.tar.xz
gsoc2013-evolution-4a01c7558799e57732fe620670d6a73f1859c1b5.tar.zst
gsoc2013-evolution-4a01c7558799e57732fe620670d6a73f1859c1b5.zip
Check for nl_langinfo (CODESET). Code taken from glib 1.3 branch.
2001-02-06 Christopher James Lahey <clahey@ximian.com> * configure.in: Check for nl_langinfo (CODESET). Code taken from glib 1.3 branch. * gal/widgets/e-font.c, gal/widgets/e-font.h (e_locale_encoding): Added e_locale_encoding, e_iconv_from_locale, and e_iconv_to_locale. * gal/widgets/e-unicode.c, gal/widgets/e-unicode.h: Added e_utf8_from_locale_string, e_utf8_from_locale_string_sized, e_utf8_to_locale_string, e_utf8_to_locale_string_sized. svn path=/trunk/; revision=8032
Diffstat (limited to 'widgets/misc')
-rw-r--r--widgets/misc/e-unicode.c123
-rw-r--r--widgets/misc/e-unicode.h9
2 files changed, 130 insertions, 2 deletions
diff --git a/widgets/misc/e-unicode.c b/widgets/misc/e-unicode.c
index 8de74fa842..0cb889e323 100644
--- a/widgets/misc/e-unicode.c
+++ b/widgets/misc/e-unicode.c
@@ -355,6 +355,129 @@ e_utf8_to_gtk_string (GtkWidget *widget, const gchar *string)
}
gchar *
+e_utf8_from_locale_string_sized (const gchar *string, gint bytes)
+{
+ iconv_t ic;
+ char *new, *ob;
+ gchar * ib;
+ size_t ibl, obl;
+
+ if (!string) return NULL;
+
+ ic = e_iconv_from_locale ();
+ if (ic == (iconv_t) -1) {
+ gint i;
+ /* iso-8859-1 */
+ ib = (char *) string;
+ new = ob = g_new (unsigned char, bytes * 2 + 1);
+ for (i = 0; i < (bytes); i ++) {
+ ob += g_unichar_to_utf8 (ib[i], ob);
+ }
+ *ob = '\0';
+ return new;
+ }
+
+ ib = (char *) string;
+ ibl = bytes;
+ new = ob = g_new (gchar, ibl * 6 + 1);
+ obl = ibl * 6 + 1;
+
+ while (ibl > 0) {
+ iconv (ic, &ib, &ibl, &ob, &obl);
+ if (ibl > 0) {
+ gint len;
+ if ((*ib & 0x80) == 0x00) len = 1;
+ else if ((*ib &0xe0) == 0xc0) len = 2;
+ else if ((*ib &0xf0) == 0xe0) len = 3;
+ else if ((*ib &0xf8) == 0xf0) len = 4;
+ else {
+ g_warning ("Invalid UTF-8 sequence");
+ break;
+ }
+ ib += len;
+ ibl = bytes - (ib - string);
+ if (ibl > bytes) ibl = 0;
+ *ob++ = '_';
+ obl--;
+ }
+ }
+
+ *ob = '\0';
+
+ return new;
+}
+
+gchar *
+e_utf8_from_locale_string (const gchar *string)
+{
+ return e_utf8_from_locale_string_sized (string, strlen (string));
+}
+
+gchar *
+e_utf8_to_locale_string_sized (const gchar *string, gint bytes)
+{
+ iconv_t ic;
+ char *new, *ob;
+ gchar * ib;
+ size_t ibl, obl;
+
+ if (!string) return NULL;
+
+ ic = e_iconv_to_locale ();
+ if (ic == (iconv_t) -1) {
+ gint len;
+ const gchar *u;
+ unicode_char_t uc;
+
+ new = g_new (unsigned char, bytes * 4 + 1);
+ u = string;
+ len = 0;
+
+ while ((u) && (u - string < bytes)) {
+ u = unicode_get_utf8 (u, &uc);
+ new[len++] = uc & 0xff;
+ }
+ new[len] = '\0';
+ return new;
+ }
+
+ ib = (char *) string;
+ ibl = bytes;
+ new = ob = g_new (gchar, ibl * 4 + 1);
+ obl = ibl * 4 + 1;
+
+ while (ibl > 0) {
+ iconv (ic, &ib, &ibl, &ob, &obl);
+ if (ibl > 0) {
+ gint len;
+ if ((*ib & 0x80) == 0x00) len = 1;
+ else if ((*ib &0xe0) == 0xc0) len = 2;
+ else if ((*ib &0xf0) == 0xe0) len = 3;
+ else if ((*ib &0xf8) == 0xf0) len = 4;
+ else {
+ g_warning ("Invalid UTF-8 sequence");
+ break;
+ }
+ ib += len;
+ ibl = bytes - (ib - string);
+ if (ibl > bytes) ibl = 0;
+ *ob++ = '_';
+ obl--;
+ }
+ }
+
+ *ob = '\0';
+
+ return new;
+}
+
+gchar *
+e_utf8_to_locale_string (const gchar *string)
+{
+ return e_utf8_to_locale_string_sized (string, strlen (string));
+}
+
+gchar *
e_utf8_gtk_entry_get_text (GtkEntry *entry)
{
gchar *s, *u;
diff --git a/widgets/misc/e-unicode.h b/widgets/misc/e-unicode.h
index 1b51595f6c..8f0c8b646d 100644
--- a/widgets/misc/e-unicode.h
+++ b/widgets/misc/e-unicode.h
@@ -46,9 +46,14 @@ gchar *e_utf8_from_gtk_event_key (GtkWidget *widget, guint keyval, const gchar *
gchar *e_utf8_from_gtk_string (GtkWidget *widget, const gchar *string);
gchar *e_utf8_from_gtk_string_sized (GtkWidget *widget, const gchar *string, gint bytes);
-gchar * e_utf8_to_gtk_string (GtkWidget *widget, const gchar *string);
-gchar * e_utf8_to_gtk_string_sized (GtkWidget *widget, const gchar *string, gint bytes);
+gchar *e_utf8_to_gtk_string (GtkWidget *widget, const gchar *string);
+gchar *e_utf8_to_gtk_string_sized (GtkWidget *widget, const gchar *string, gint bytes);
+gchar *e_utf8_from_locale_string (const gchar *string);
+gchar *e_utf8_from_locale_string_sized (const gchar *string, gint bytes);
+
+gchar *e_utf8_to_locale_string (const gchar *string);
+gchar *e_utf8_to_locale_string_sized (const gchar *string, gint bytes);
/*
* These are simple wrappers that save us some typing
*/