Commit 1e3f0b45 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

input: do not override subtitles encoding if BOM is found (fixes #5239)

That horrible hack caused all subtitles to be parsed as Unicode if one
(but not necessarily all) opened subtitles started with a UTF-8 or
UTF-16 Byte Order Mark. If any other subtitle was neither in UTF-8 nor
in UTF-16 with a BOM, that hack failed.
parent 7ec1ad38
...@@ -1485,49 +1485,31 @@ char *stream_ReadLine( stream_t *s ) ...@@ -1485,49 +1485,31 @@ char *stream_ReadLine( stream_t *s )
/* BOM detection */ /* BOM detection */
i_pos = stream_Tell( s ); i_pos = stream_Tell( s );
if( i_pos == 0 && i_data >= 3 ) if( i_pos == 0 && i_data >= 2 )
{ {
const char *psz_encoding = NULL; const char *psz_encoding = NULL;
if( !memcmp( p_data, "\xEF\xBB\xBF", 3 ) ) if( !memcmp( p_data, "\xFF\xFE", 2 ) )
{
psz_encoding = "UTF-8";
}
else if( !memcmp( p_data, "\xFF\xFE", 2 ) )
{ {
psz_encoding = "UTF-16LE"; psz_encoding = "UTF-16LE";
s->p_text->b_little_endian = true; s->p_text->b_little_endian = true;
s->p_text->i_char_width = 2;
} }
else if( !memcmp( p_data, "\xFE\xFF", 2 ) ) else if( !memcmp( p_data, "\xFE\xFF", 2 ) )
{ {
psz_encoding = "UTF-16BE"; psz_encoding = "UTF-16BE";
s->p_text->i_char_width = 2;
} }
/* Open the converter if we need it */ /* Open the converter if we need it */
if( psz_encoding != NULL ) if( psz_encoding != NULL )
{ {
msg_Dbg( s, "%s BOM detected", psz_encoding ); msg_Dbg( s, "UTF-16 BOM detected" );
if( s->p_text->i_char_width > 1 ) s->p_text->i_char_width = 2;
{
s->p_text->conv = vlc_iconv_open( "UTF-8", psz_encoding ); s->p_text->conv = vlc_iconv_open( "UTF-8", psz_encoding );
if( s->p_text->conv == (vlc_iconv_t)-1 ) if( s->p_text->conv == (vlc_iconv_t)-1 )
{
msg_Err( s, "iconv_open failed" ); msg_Err( s, "iconv_open failed" );
} }
} }
/* FIXME that's UGLY */
input_thread_t *p_input = s->p_input;
if( p_input != NULL)
{
var_Create( p_input, "subsdec-encoding", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
var_SetString( p_input, "subsdec-encoding", "UTF-8" );
}
}
}
if( i_data % s->p_text->i_char_width ) if( i_data % s->p_text->i_char_width )
{ {
/* keep i_char_width boundary */ /* keep i_char_width boundary */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment