charsets: use new bytearray_to_utf8() instead of byte_array_to_utf8()
This commit is contained in:
@@ -4820,11 +4820,9 @@ ussd_decode (guint32 scheme,
|
||||
if (!decoded)
|
||||
g_prefix_error (error, "Error decoding USSD command in 0x%04x scheme (GSM7 charset): ", scheme);
|
||||
} else if (scheme == MM_MODEM_GSM_USSD_SCHEME_UCS2) {
|
||||
decoded = mm_modem_charset_byte_array_to_utf8 (data, MM_MODEM_CHARSET_UCS2);
|
||||
decoded = mm_modem_charset_bytearray_to_utf8 (data, MM_MODEM_CHARSET_UCS2, FALSE, error);
|
||||
if (!decoded)
|
||||
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED,
|
||||
"Error decoding USSD command in 0x%04x scheme (UCS2 charset)",
|
||||
scheme);
|
||||
g_prefix_error (error, "Error decoding USSD command in 0x%04x scheme (UCS2 charset): ", scheme);
|
||||
} else
|
||||
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED,
|
||||
"Failed to decode USSD command in unsupported 0x%04x scheme", scheme);
|
||||
|
@@ -7281,11 +7281,9 @@ ussd_decode (QmiVoiceUssDataCodingScheme scheme,
|
||||
"Error decoding USSD command in 0x%04x scheme (ASCII charset)",
|
||||
scheme);
|
||||
} else if (scheme == QMI_VOICE_USS_DATA_CODING_SCHEME_UCS2) {
|
||||
decoded = mm_modem_charset_byte_array_to_utf8 ((GByteArray *) data, MM_MODEM_CHARSET_UCS2);
|
||||
decoded = mm_modem_charset_bytearray_to_utf8 ((GByteArray *) data, MM_MODEM_CHARSET_UCS2, FALSE, error);
|
||||
if (!decoded)
|
||||
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED,
|
||||
"Error decoding USSD command in 0x%04x scheme (UCS2 charset)",
|
||||
scheme);
|
||||
g_prefix_error (error, "Error decoding USSD command in 0x%04x scheme (UCS2 charset): ", scheme);
|
||||
} else
|
||||
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED,
|
||||
"Failed to decode USSD command in unsupported 0x%04x scheme", scheme);
|
||||
|
@@ -96,29 +96,6 @@ charset_iconv_from (MMModemCharset charset)
|
||||
return settings ? settings->iconv_name : NULL;
|
||||
}
|
||||
|
||||
gchar *
|
||||
mm_modem_charset_byte_array_to_utf8 (GByteArray *array,
|
||||
MMModemCharset charset)
|
||||
{
|
||||
const gchar *iconv_from;
|
||||
g_autofree gchar *converted = NULL;
|
||||
g_autoptr(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", iconv_from,
|
||||
NULL, NULL, &error);
|
||||
if (!converted || error)
|
||||
return NULL;
|
||||
|
||||
return g_steal_pointer (&converted);
|
||||
}
|
||||
|
||||
gchar *
|
||||
mm_modem_charset_hex_to_utf8 (const gchar *src,
|
||||
MMModemCharset charset)
|
||||
|
@@ -37,11 +37,6 @@ MMModemCharset mm_modem_charset_from_string (const gchar *string);
|
||||
|
||||
/*****************************************************************************************/
|
||||
|
||||
/* Take a string encoded in the given charset in binary form, and
|
||||
* convert it to UTF-8. */
|
||||
gchar *mm_modem_charset_byte_array_to_utf8 (GByteArray *array,
|
||||
MMModemCharset charset);
|
||||
|
||||
/* Take a string in hex representation ("00430052" or "A4BE11" for example)
|
||||
* and convert it from the given character set to UTF-8.
|
||||
*/
|
||||
|
@@ -264,17 +264,14 @@ sms_decode_text (const guint8 *text,
|
||||
return utf8;
|
||||
}
|
||||
|
||||
/* Always assume UTF-16 instead of UCS-2! */
|
||||
if (encoding == MM_SMS_ENCODING_UCS2) {
|
||||
g_autoptr(GByteArray) bytearray = NULL;
|
||||
gchar *utf8;
|
||||
|
||||
bytearray = g_byte_array_append (g_byte_array_sized_new (len), (const guint8 *)text, len);
|
||||
/* Always assume UTF-16 instead of UCS-2! */
|
||||
utf8 = mm_modem_charset_byte_array_to_utf8 (bytearray, MM_MODEM_CHARSET_UTF16);
|
||||
if (!utf8)
|
||||
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
|
||||
"Couldn't convert SMS part contents from UTF-16BE to UTF-8: not decoding any text");
|
||||
else
|
||||
utf8 = mm_modem_charset_bytearray_to_utf8 (bytearray, MM_MODEM_CHARSET_UTF16, FALSE, error);
|
||||
if (utf8)
|
||||
mm_obj_dbg (log_object, "converted SMS part text from UTF-16BE to UTF-8: %s", utf8);
|
||||
return utf8;
|
||||
}
|
||||
|
Reference in New Issue
Block a user