mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-05 23:18:52 +00:00
gst/id3demux/id3v2frames.c: Recognise and skip any byte order marker (BOM) in
Original commit message from CVS: * gst/id3demux/id3v2frames.c: (has_utf16_bom), (parse_split_strings): Recognise and skip any byte order marker (BOM) in UTF-16 strings.
This commit is contained in:
parent
b88deddeca
commit
d5296f2895
2 changed files with 31 additions and 0 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
2006-04-28 Tim-Philipp Müller <tim at centricular dot net>
|
||||||
|
|
||||||
|
* gst/id3demux/id3v2frames.c: (has_utf16_bom),
|
||||||
|
(parse_split_strings):
|
||||||
|
Recognise and skip any byte order marker (BOM) in
|
||||||
|
UTF-16 strings.
|
||||||
|
|
||||||
2006-04-27 Tim-Philipp Müller <tim at centricular dot net>
|
2006-04-27 Tim-Philipp Müller <tim at centricular dot net>
|
||||||
|
|
||||||
* docs/plugins/Makefile.am:
|
* docs/plugins/Makefile.am:
|
||||||
|
|
|
@ -668,6 +668,24 @@ parse_insert_string_field (const gchar * encoding, gchar * data, gint data_size,
|
||||||
g_array_append_val (fields, field);
|
g_array_append_val (fields, field);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
has_utf16_bom (gchar * data, const gchar ** p_in_encoding)
|
||||||
|
{
|
||||||
|
guint16 marker = (GST_READ_UINT8 (data) << 8) | GST_READ_UINT8 (data + 1);
|
||||||
|
|
||||||
|
switch (marker) {
|
||||||
|
case 0xFFFE:
|
||||||
|
*p_in_encoding = "UTF16LE";
|
||||||
|
return TRUE;
|
||||||
|
case 0xFEFF:
|
||||||
|
*p_in_encoding = "UTF16BE";
|
||||||
|
return TRUE;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
parse_split_strings (guint8 encoding, gchar * data, gint data_size,
|
parse_split_strings (guint8 encoding, gchar * data, gint data_size,
|
||||||
GArray ** out_fields)
|
GArray ** out_fields)
|
||||||
|
@ -719,6 +737,9 @@ parse_split_strings (guint8 encoding, gchar * data, gint data_size,
|
||||||
/* Find '\0\0' terminator */
|
/* Find '\0\0' terminator */
|
||||||
for (text_pos = 0; text_pos < data_size - 1; text_pos += 2) {
|
for (text_pos = 0; text_pos < data_size - 1; text_pos += 2) {
|
||||||
if (data[text_pos] == '\0' && data[text_pos + 1] == '\0') {
|
if (data[text_pos] == '\0' && data[text_pos + 1] == '\0') {
|
||||||
|
if (has_utf16_bom (data + prev, &in_encode)) {
|
||||||
|
prev += 2; /* skip BOM */
|
||||||
|
}
|
||||||
/* found a delimiter */
|
/* found a delimiter */
|
||||||
parse_insert_string_field (in_encode, data + prev,
|
parse_insert_string_field (in_encode, data + prev,
|
||||||
text_pos - prev + 2, fields);
|
text_pos - prev + 2, fields);
|
||||||
|
@ -729,6 +750,9 @@ parse_split_strings (guint8 encoding, gchar * data, gint data_size,
|
||||||
}
|
}
|
||||||
if (data_size - prev > 1 &&
|
if (data_size - prev > 1 &&
|
||||||
(data[prev] != 0x00 || data[prev + 1] != 0x00)) {
|
(data[prev] != 0x00 || data[prev + 1] != 0x00)) {
|
||||||
|
if (has_utf16_bom (data + prev, &in_encode)) {
|
||||||
|
prev += 2; /* skip BOM */
|
||||||
|
}
|
||||||
/* There were 2 or more non-null chars left, convert those too */
|
/* There were 2 or more non-null chars left, convert those too */
|
||||||
parse_insert_string_field (in_encode, data + prev,
|
parse_insert_string_field (in_encode, data + prev,
|
||||||
data_size - prev, fields);
|
data_size - prev, fields);
|
||||||
|
|
Loading…
Reference in a new issue