charsets: new utf8_to_hex() method
This commit is contained in:
@@ -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 */
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user