summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: de5c385)
raw | patch | inline | side by side (parent: de5c385)
author | Max Kellermann <max@duempel.org> | |
Thu, 2 Oct 2008 17:01:11 +0000 (19:01 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Thu, 2 Oct 2008 17:01:11 +0000 (19:01 +0200) |
Use g_convert_with_fallback() for charset conversion, and don't print
a status bar message on error.
a status bar message on error.
src/charset.c | patch | blob | history |
diff --git a/src/charset.c b/src/charset.c
index 701fd2105bd6eb1afaf5a4e8a67cb64170c8abc3..42c0e60347432c2f909d97a207c4599cf741797c 100644 (file)
--- a/src/charset.c
+++ b/src/charset.c
*/
#include "charset.h"
-#include "i18n.h"
#include <assert.h>
#include <string.h>
#include <glib.h>
-extern void screen_status_printf(const char *format, ...);
-
static bool noconvert = true;
static const char *charset;
utf8_to_locale(const char *utf8str)
{
gchar *str;
- gsize rb, wb;
GError *error;
assert(utf8str != NULL);
if (noconvert)
return g_strdup(utf8str);
- rb = 0; /* bytes read */
- wb = 0; /* bytes written */
- error = NULL;
- str = g_locale_from_utf8(utf8str,
- strlen(utf8str),
- &wb, &rb,
- &error);
- if (error) {
- screen_status_printf(_("Error: Unable to convert characters to %s"),
- charset);
+ str = g_convert_with_fallback(utf8str, strlen(utf8str),
+ charset, "utf-8",
+ NULL, NULL, NULL,
+ &error);
+ if (str == NULL) {
g_error_free(error);
return g_strdup(utf8str);
}
locale_to_utf8(const char *localestr)
{
gchar *str;
- gsize rb, wb;
GError *error;
assert(localestr != NULL);
if (noconvert)
return g_strdup(localestr);
- rb = 0; /* bytes read */
- wb = 0; /* bytes written */
- error = NULL;
- str = g_locale_to_utf8(localestr,
- strlen(localestr),
- &wb, &rb,
- &error);
- if (error) {
- screen_status_printf(_("Error: Unable to convert characters to UTF-8"));
+ str = g_convert_with_fallback(localestr, strlen(localestr),
+ "utf-8", charset,
+ NULL, NULL, NULL,
+ &error);
+ if (str == NULL) {
g_error_free(error);
return g_strdup(localestr);
}