aboutsummaryrefslogtreecommitdiffstats
path: root/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'widgets')
-rw-r--r--widgets/misc/e-unicode.c204
-rw-r--r--widgets/misc/e-unicode.h16
2 files changed, 154 insertions, 66 deletions
diff --git a/widgets/misc/e-unicode.c b/widgets/misc/e-unicode.c
index b967d0358f..edb7d3ee17 100644
--- a/widgets/misc/e-unicode.c
+++ b/widgets/misc/e-unicode.c
@@ -222,48 +222,24 @@ e_utf8_from_gtk_event_key (GtkWidget *widget, guint keyval, const gchar *string)
}
gchar *
-e_utf8_from_gtk_string_sized (GtkWidget *widget, const gchar *string, gint bytes)
+e_utf8_from_iconv_string_sized (iconv_t ic, const gchar *string, gint bytes)
{
- iconv_t ic;
char *new, *ob;
gchar * ib;
size_t ibl, obl;
- g_return_val_if_fail (widget != NULL, NULL);
- g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
-
if (!string) return NULL;
- g_return_val_if_fail (widget, NULL);
-
- ic = e_iconv_from_gdk_font (widget->style->font);
if (ic == (iconv_t) -1) {
- XFontStruct *xfs;
- /* If iconv is missing we assume either iso-10646 or iso-8859-1 */
- xfs = GDK_FONT_XFONT (widget->style->font);
- if (widget->style->font->type == GDK_FONT_FONTSET || ((xfs->min_byte1 != 0) || (xfs->max_byte1 != 0))) {
- gint i;
- const guchar *ib;
- guchar * ob, * new;
- /* iso-10646 */
- ib = string;
- new = ob = g_new (unsigned char, bytes * 6 + 1);
- for (i = 0; i < (bytes - 1); i += 2) {
- ob += e_unichar_to_utf8 (ib[i] * 256 + ib[i + 1], ob);
- }
- *ob = '\0';
- return new;
- } else {
- gint i;
- /* iso-8859-1 */
- ib = (char *) string;
- new = ob = g_new (unsigned char, bytes * 2 + 1);
- for (i = 0; i < (bytes); i ++) {
- ob += e_unichar_to_utf8 (ib[i], ob);
- }
- *ob = '\0';
- return new;
+ gint i;
+ /* iso-8859-1 */
+ ib = (char *) string;
+ new = ob = g_new (unsigned char, bytes * 2 + 1);
+ for (i = 0; i < (bytes); i ++) {
+ ob += e_unichar_to_utf8 (ib[i], ob);
}
+ *ob = '\0';
+ return new;
}
ib = (char *) string;
@@ -297,35 +273,25 @@ e_utf8_from_gtk_string_sized (GtkWidget *widget, const gchar *string, gint bytes
}
gchar *
-e_utf8_from_gtk_string (GtkWidget *widget, const gchar *string)
+e_utf8_from_iconv_string (iconv_t ic, const gchar *string)
{
if (!string) return NULL;
- return e_utf8_from_gtk_string_sized (widget, string, strlen (string));
+ return e_utf8_from_iconv_string_sized (ic, string, strlen (string));
}
gchar *
-e_utf8_to_gtk_string_sized (GtkWidget *widget, const gchar *string, gint bytes)
+e_utf8_to_iconv_string_sized (iconv_t ic, const gchar *string, gint bytes)
{
- iconv_t ic;
char *new, *ob;
gchar * ib;
size_t ibl, obl;
if (!string) return NULL;
- g_return_val_if_fail (widget, NULL);
-
- gtk_widget_ensure_style (widget);
- ic = e_iconv_to_gdk_font (widget->style->font);
if (ic == (iconv_t) -1) {
- XFontStruct *xfs;
- gboolean twobyte;
gint len;
const gchar *u;
gunichar uc;
- /* If iconv is missing we assume either iso-10646 or iso-8859-1 */
- xfs = GDK_FONT_XFONT (widget->style->font);
- twobyte = (widget->style->font->type == GDK_FONT_FONTSET || ((xfs->min_byte1 != 0) || (xfs->max_byte1 != 0)));
new = g_new (unsigned char, bytes * 4 + 1);
u = string;
@@ -333,13 +299,9 @@ e_utf8_to_gtk_string_sized (GtkWidget *widget, const gchar *string, gint bytes)
while ((u) && (u - string < bytes)) {
u = e_unicode_get_utf8 (u, &uc);
- if (twobyte) {
- new[len++] = (uc & 0xff00) >> 8;
- }
new[len++] = uc & 0xff;
}
new[len] = '\0';
- d(printf("utf8_to_gtk: %s => %s\n", string, new));
return new;
}
@@ -374,33 +336,93 @@ e_utf8_to_gtk_string_sized (GtkWidget *widget, const gchar *string, gint bytes)
}
gchar *
-e_utf8_to_gtk_string (GtkWidget *widget, const gchar *string)
+e_utf8_to_iconv_string (iconv_t ic, const gchar *string)
{
if (!string) return NULL;
- return e_utf8_to_gtk_string_sized (widget, string, strlen (string));
+ return e_utf8_to_iconv_string_sized (ic, string, strlen (string));
}
gchar *
-e_utf8_from_locale_string_sized (const gchar *string, gint bytes)
+e_utf8_from_charset_string_sized (const gchar *charset, const gchar *string, gint bytes)
+{
+ iconv_t ic;
+
+ if (!string) return NULL;
+
+ ic = e_iconv_from_charset (charset);
+
+ return e_utf8_from_iconv_string_sized (ic, string, bytes);
+}
+
+gchar *
+e_utf8_from_charset_string (const gchar *charset, const gchar *string)
+{
+ if (!string) return NULL;
+ return e_utf8_from_charset_string_sized (charset, string, strlen (string));
+}
+
+gchar *
+e_utf8_to_charset_string_sized (const gchar *charset, const gchar *string, gint bytes)
+{
+ iconv_t ic;
+
+ if (!string) return NULL;
+
+ ic = e_iconv_to_charset (charset);
+
+ return e_utf8_to_iconv_string_sized (ic, string, bytes);
+}
+
+gchar *
+e_utf8_to_charset_string (const gchar *charset, const gchar *string)
+{
+ if (!string) return NULL;
+ return e_utf8_to_charset_string_sized (charset, string, strlen (string));
+}
+
+gchar *
+e_utf8_from_gtk_string_sized (GtkWidget *widget, const gchar *string, gint bytes)
{
iconv_t ic;
char *new, *ob;
gchar * ib;
size_t ibl, obl;
+ g_return_val_if_fail (widget != NULL, NULL);
+ g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
+
if (!string) return NULL;
- ic = e_iconv_from_locale ();
+ g_return_val_if_fail (widget, NULL);
+
+ ic = e_iconv_from_gdk_font (widget->style->font);
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 += e_unichar_to_utf8 (ib[i], ob);
+ XFontStruct *xfs;
+ /* If iconv is missing we assume either iso-10646 or iso-8859-1 */
+ xfs = GDK_FONT_XFONT (widget->style->font);
+ if (widget->style->font->type == GDK_FONT_FONTSET || ((xfs->min_byte1 != 0) || (xfs->max_byte1 != 0))) {
+ gint i;
+ const guchar *ib;
+ guchar * ob, * new;
+ /* iso-10646 */
+ ib = string;
+ new = ob = g_new (unsigned char, bytes * 6 + 1);
+ for (i = 0; i < (bytes - 1); i += 2) {
+ ob += e_unichar_to_utf8 (ib[i] * 256 + ib[i + 1], ob);
+ }
+ *ob = '\0';
+ return new;
+ } else {
+ gint i;
+ /* iso-8859-1 */
+ ib = (char *) string;
+ new = ob = g_new (unsigned char, bytes * 2 + 1);
+ for (i = 0; i < (bytes); i ++) {
+ ob += e_unichar_to_utf8 (ib[i], ob);
+ }
+ *ob = '\0';
+ return new;
}
- *ob = '\0';
- return new;
}
ib = (char *) string;
@@ -434,14 +456,14 @@ e_utf8_from_locale_string_sized (const gchar *string, gint bytes)
}
gchar *
-e_utf8_from_locale_string (const gchar *string)
+e_utf8_from_gtk_string (GtkWidget *widget, const gchar *string)
{
if (!string) return NULL;
- return e_utf8_from_locale_string_sized (string, strlen (string));
+ return e_utf8_from_gtk_string_sized (widget, string, strlen (string));
}
gchar *
-e_utf8_to_locale_string_sized (const gchar *string, gint bytes)
+e_utf8_to_gtk_string_sized (GtkWidget *widget, const gchar *string, gint bytes)
{
iconv_t ic;
char *new, *ob;
@@ -450,11 +472,19 @@ e_utf8_to_locale_string_sized (const gchar *string, gint bytes)
if (!string) return NULL;
- ic = e_iconv_to_locale ();
+ g_return_val_if_fail (widget, NULL);
+
+ gtk_widget_ensure_style (widget);
+ ic = e_iconv_to_gdk_font (widget->style->font);
if (ic == (iconv_t) -1) {
+ XFontStruct *xfs;
+ gboolean twobyte;
gint len;
const gchar *u;
gunichar uc;
+ /* If iconv is missing we assume either iso-10646 or iso-8859-1 */
+ xfs = GDK_FONT_XFONT (widget->style->font);
+ twobyte = (widget->style->font->type == GDK_FONT_FONTSET || ((xfs->min_byte1 != 0) || (xfs->max_byte1 != 0)));
new = g_new (unsigned char, bytes * 4 + 1);
u = string;
@@ -462,9 +492,13 @@ e_utf8_to_locale_string_sized (const gchar *string, gint bytes)
while ((u) && (u - string < bytes)) {
u = e_unicode_get_utf8 (u, &uc);
+ if (twobyte) {
+ new[len++] = (uc & 0xff00) >> 8;
+ }
new[len++] = uc & 0xff;
}
new[len] = '\0';
+ d(printf("utf8_to_gtk: %s => %s\n", string, new));
return new;
}
@@ -499,6 +533,44 @@ e_utf8_to_locale_string_sized (const gchar *string, gint bytes)
}
gchar *
+e_utf8_to_gtk_string (GtkWidget *widget, const gchar *string)
+{
+ if (!string) return NULL;
+ return e_utf8_to_gtk_string_sized (widget, string, strlen (string));
+}
+
+gchar *
+e_utf8_from_locale_string_sized (const gchar *string, gint bytes)
+{
+ iconv_t ic;
+
+ if (!string) return NULL;
+
+ ic = e_iconv_to_locale ();
+
+ return e_utf8_from_iconv_string_sized (ic, string, bytes);
+}
+
+gchar *
+e_utf8_from_locale_string (const gchar *string)
+{
+ if (!string) return NULL;
+ 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;
+
+ if (!string) return NULL;
+
+ ic = e_iconv_to_locale ();
+
+ return e_utf8_to_iconv_string_sized (ic, string, bytes);
+}
+
+gchar *
e_utf8_to_locale_string (const gchar *string)
{
if (!string) return NULL;
diff --git a/widgets/misc/e-unicode.h b/widgets/misc/e-unicode.h
index 019505948f..0b137dc200 100644
--- a/widgets/misc/e-unicode.h
+++ b/widgets/misc/e-unicode.h
@@ -20,6 +20,7 @@
#include <libgnome/gnome-defs.h>
#include <gnome-xml/tree.h>
#include <gal/unicode/gunicode.h>
+#include <iconv.h>
BEGIN_GNOME_DECLS
@@ -39,12 +40,27 @@ const gchar *e_utf8_strstrcasedecomp (const gchar *haystack, const gchar *needle
gchar *e_utf8_from_gtk_event_key (GtkWidget *widget, guint keyval, const gchar *string);
+gchar *e_utf8_from_iconv_string (iconv_t ic, const gchar *string);
+gchar *e_utf8_from_iconv_string_sized (iconv_t ic, const gchar *string, gint bytes);
+
+gchar *e_utf8_to_iconv_string (iconv_t ic, const gchar *string);
+gchar *e_utf8_to_iconv_string_sized (iconv_t ic, const gchar *string, gint bytes);
+
+
+gchar *e_utf8_from_charset_string (const gchar *charset, const gchar *string);
+gchar *e_utf8_from_charset_string_sized (const gchar *charset, const gchar *string, gint bytes);
+
+gchar *e_utf8_to_charset_string (const gchar *charset, const gchar *string);
+gchar *e_utf8_to_charset_string_sized (const gchar *charset, const gchar *string, gint bytes);
+
+
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_from_locale_string (const gchar *string);
gchar *e_utf8_from_locale_string_sized (const gchar *string, gint bytes);