1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3
* e-unicode.c - utf-8 support functions for gal
4
* Copyright 2000, 2001, Ximian, Inc.
7
* Lauris Kaplinski <lauris@ximian.com>
9
* This library is free software; you can redistribute it and/or
10
* modify it under the terms of the GNU Library General Public
11
* License, version 2, as published by the Free Software Foundation.
13
* This library is distributed in the hope that it will be useful, but
14
* WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* Library General Public License for more details.
18
* You should have received a copy of the GNU Library General Public
19
* License along with this library; if not, write to the Free Software
20
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26
#include "e-unicode.h"
34
e_utf8_to_iconv_string_sized (iconv_t ic, const gchar *string, gint bytes)
40
if (!string) return NULL;
42
if (ic == (iconv_t) -1) {
47
new = g_new (unsigned char, bytes * 4 + 1);
51
while ((u) && (u - string < bytes)) {
52
u = e_unicode_get_utf8 (u, &uc);
53
new[len++] = uc & 0xff;
61
new = ob = g_new (gchar, ibl * 4 + 1);
65
e_iconv (ic, &ib, &ibl, &ob, &obl);
68
if ((*ib & 0x80) == 0x00) len = 1;
69
else if ((*ib &0xe0) == 0xc0) len = 2;
70
else if ((*ib &0xf0) == 0xe0) len = 3;
71
else if ((*ib &0xf8) == 0xf0) len = 4;
73
g_warning ("Invalid UTF-8 sequence");
77
ibl = bytes - (ib - string);
78
if (ibl > bytes) ibl = 0;
90
e_utf8_to_locale_string_sized (const gchar *string, gint bytes)
95
if (!string) return NULL;
97
ic = e_iconv_open(e_iconv_locale_charset(), "utf-8");
98
ret = e_utf8_to_iconv_string_sized (ic, string, bytes);
105
e_utf8_to_locale_string (const gchar *string)
107
if (!string) return NULL;
108
return e_utf8_to_locale_string_sized (string, strlen (string));
112
e_unicode_get_utf8 (const gchar *text, gunichar *out)
114
*out = g_utf8_get_char (text);
115
return (*out == (gunichar)-1) ? NULL : g_utf8_next_char (text);