aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/misc
diff options
context:
space:
mode:
authorChristopher James Lahey <clahey@ximian.com>2001-09-01 16:16:49 +0800
committerChris Lahey <clahey@src.gnome.org>2001-09-01 16:16:49 +0800
commita3d7a62572a7f34094a6f416ffac9320b308fffa (patch)
tree4133e2d08327370347a8c39961ef0028e0ae17e1 /widgets/misc
parent06eb6e23fb44335ffd747d1257dce6deb9a1d756 (diff)
downloadgsoc2013-evolution-a3d7a62572a7f34094a6f416ffac9320b308fffa.tar
gsoc2013-evolution-a3d7a62572a7f34094a6f416ffac9320b308fffa.tar.gz
gsoc2013-evolution-a3d7a62572a7f34094a6f416ffac9320b308fffa.tar.bz2
gsoc2013-evolution-a3d7a62572a7f34094a6f416ffac9320b308fffa.tar.lz
gsoc2013-evolution-a3d7a62572a7f34094a6f416ffac9320b308fffa.tar.xz
gsoc2013-evolution-a3d7a62572a7f34094a6f416ffac9320b308fffa.tar.zst
gsoc2013-evolution-a3d7a62572a7f34094a6f416ffac9320b308fffa.zip
Bumped the version number to 0.111.99.1 for new e_utf8 functions.
2001-09-01 Christopher James Lahey <clahey@ximian.com> * configure.in: Bumped the version number to 0.111.99.1 for new e_utf8 functions. * gal/unicode/gunicollate.c (g_utf8_collate, g_utf8_collate_key): Changed this from e_utf8_from_locale_string to e_utf8_to_locale_string. * gal/widgets/e-font.c, gal/widgets/e-font.h (e_iconv_from_charset, e_iconv_to_charset): Added these functions to the exported interface (renamed them as well from e_iconv_from_encoding and e_iconv_to_encoding.) * gal/widgets/e-unicode.c, gal/widgets/e-unicode.h (e_utf8_from_iconv_string, e_utf8_from_iconv_string_sized, e_utf8_to_iconv_string, e_utf8_to_iconv_string_sized, e_utf8_from_charset_string, e_utf8_from_charset_string_sized, e_utf8_to_charset_string, e_utf8_to_charset_string_sized): Added these functions. (e_utf8_from_locale_string, e_utf8_to_locale_string): Changed these to use the new e_utf8_from_iconv_string and e_utf8_to_iconv_string. svn path=/trunk/; revision=12554
Diffstat (limited to 'widgets/misc')
-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);