Make utils_get_utf8_from_locale(), utils_get_locale_from_utf8()

NULL-safe.


git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@2121 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Nick Treleaven 2007-12-21 16:34:07 +00:00
parent 559ca62705
commit 4e262328bd
2 changed files with 19 additions and 4 deletions

View File

@ -6,6 +6,9 @@
the GtkEntry, use a callback for input text, and have a 'persistent'
option to hide the dialog instead of deleting it, using a combo box
for input text history.
* src/utils.c:
Make utils_get_utf8_from_locale(), utils_get_locale_from_utf8()
NULL-safe.
2007-12-19 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>

View File

@ -1384,6 +1384,7 @@ gboolean utils_wrap_string(gchar *string, gint wrapstart)
}
/* Null-safe with fallback encoding conversion. */
gchar *utils_get_locale_from_utf8(const gchar *utf8_text)
{
#ifdef G_OS_WIN32
@ -1391,13 +1392,19 @@ gchar *utils_get_locale_from_utf8(const gchar *utf8_text)
// which would result in wrongly converted strings
return g_strdup(utf8_text);
#else
gchar *locale_text = g_locale_from_utf8(utf8_text, -1, NULL, NULL, NULL);
if (locale_text == NULL) locale_text = g_strdup(utf8_text);
gchar *locale_text;
if (! utf8_text)
return NULL;
locale_text = g_locale_from_utf8(utf8_text, -1, NULL, NULL, NULL);
if (locale_text == NULL)
locale_text = g_strdup(utf8_text);
return locale_text;
#endif
}
/* Null-safe with fallback encoding conversion. */
gchar *utils_get_utf8_from_locale(const gchar *locale_text)
{
#ifdef G_OS_WIN32
@ -1405,8 +1412,13 @@ gchar *utils_get_utf8_from_locale(const gchar *locale_text)
// which would result in wrongly converted strings
return g_strdup(locale_text);
#else
gchar *utf8_text = g_locale_to_utf8(locale_text, -1, NULL, NULL, NULL);
if (utf8_text == NULL) utf8_text = g_strdup(locale_text);
gchar *utf8_text;
if (! locale_text)
return NULL;
utf8_text = g_locale_to_utf8(locale_text, -1, NULL, NULL, NULL);
if (utf8_text == NULL)
utf8_text = g_strdup(locale_text);
return utf8_text;
#endif
}