charsets: new utf8_to_hex() method

This commit is contained in:
Aleksander Morgado
2011-06-06 17:20:16 +02:00
parent 1e507824c6
commit 668726dbd7
2 changed files with 36 additions and 0 deletions
+31
View File
@@ -177,6 +177,37 @@ mm_modem_charset_hex_to_utf8 (const char *src, MMModemCharset charset)
return converted;
}
char *
mm_modem_charset_utf8_to_hex (const char *src, MMModemCharset charset)
{
gsize converted_len = 0;
char *converted;
const char *iconv_to;
GError *error = NULL;
g_return_val_if_fail (src != NULL, NULL);
g_return_val_if_fail (charset != MM_MODEM_CHARSET_UNKNOWN, NULL);
iconv_to = charset_iconv_from (charset);
g_return_val_if_fail (iconv_to != NULL, FALSE);
if (charset == MM_MODEM_CHARSET_UTF8 || charset == MM_MODEM_CHARSET_IRA)
return g_strdup (src);
converted = g_convert (src, strlen (src),
iconv_to, "UTF-8//TRANSLIT",
NULL, &converted_len, &error);
if (!converted || error) {
g_clear_error (&error);
g_free (converted);
converted = NULL;
} else {
/* Get hex representation of the string */
converted = utils_bin2hexstr ((guint8 *)converted, converted_len);
}
return converted;
}
/* GSM 03.38 encoding conversion stuff */
+5
View File
@@ -48,6 +48,11 @@ gboolean mm_modem_charset_byte_array_append (GByteArray *array,
*/
char *mm_modem_charset_hex_to_utf8 (const char *src, MMModemCharset charset);
/* Take a string in UTF-8 and convert it to the given charset in hex
* representation.
*/
char *mm_modem_charset_utf8_to_hex (const char *src, MMModemCharset charset);
guint8 *mm_charset_utf8_to_unpacked_gsm (const char *utf8, guint32 *out_len);
guint8 *mm_charset_gsm_unpacked_to_utf8 (const guint8 *gsm, guint32 len);