diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2018-08-07 00:23:41 +0200 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2018-08-21 16:50:15 +0000 |
commit | eda46d05cf9ed1a8f9aac460a55509b510b02c0b (patch) | |
tree | 6817619ecc3c1da22d3657c28f171981a4435649 /src/mm-charsets.c | |
parent | e90ced5e0f5691113abb20fb5a22e312a2bc9b68 (diff) |
charsets: new helper to convert binary input data to UTF-8
Most of all the other APIs we have are expecting binary data (e.g.
UCS-2 encoded strings) in ASCII hex format, because they were going
to be used in text AT commands. For binary protocols allowing binary
data, we need use a more generic API that provides an explicit data
size.
Diffstat (limited to 'src/mm-charsets.c')
-rw-r--r-- | src/mm-charsets.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/mm-charsets.c b/src/mm-charsets.c index 55604182..73dd4da6 100644 --- a/src/mm-charsets.c +++ b/src/mm-charsets.c @@ -148,6 +148,31 @@ mm_modem_charset_byte_array_append (GByteArray *array, return TRUE; } +gchar * +mm_modem_charset_byte_array_to_utf8 (GByteArray *array, + MMModemCharset charset) +{ + char *converted; + const char *iconv_from; + GError *error = NULL; + + g_return_val_if_fail (array != NULL, NULL); + g_return_val_if_fail (charset != MM_MODEM_CHARSET_UNKNOWN, NULL); + + iconv_from = charset_iconv_from (charset); + g_return_val_if_fail (iconv_from != NULL, FALSE); + + converted = g_convert ((const gchar *)array->data, array->len, + "UTF-8//TRANSLIT", iconv_from, + NULL, NULL, &error); + if (!converted || error) { + g_clear_error (&error); + converted = NULL; + } + + return converted; +} + char * mm_modem_charset_hex_to_utf8 (const char *src, MMModemCharset charset) { |