Commit 979ee1a3 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

TS: use FromCharset()

parent e8b9642e
...@@ -2621,10 +2621,8 @@ static char *EITConvertToUTF8( const unsigned char *psz_instring, ...@@ -2621,10 +2621,8 @@ static char *EITConvertToUTF8( const unsigned char *psz_instring,
bool b_broken ) bool b_broken )
{ {
const char *psz_encoding; const char *psz_encoding;
char *psz_outstring;
char psz_encbuf[sizeof( "ISO_8859-123" )]; char psz_encbuf[sizeof( "ISO_8859-123" )];
size_t i_in, i_out, offset = 1; size_t offset = 1;
vlc_iconv_t iconv_handle;
if( i_length < 1 ) return NULL; if( i_length < 1 ) return NULL;
if( psz_instring[0] >= 0x20 ) if( psz_instring[0] >= 0x20 )
...@@ -2710,55 +2708,26 @@ static char *EITConvertToUTF8( const unsigned char *psz_instring, ...@@ -2710,55 +2708,26 @@ static char *EITConvertToUTF8( const unsigned char *psz_instring,
offset = 0; offset = 0;
} }
i_in = i_length - offset; psz_instring += offset;
i_out = i_in * 6 + 1; i_length -= offset;
psz_outstring = malloc( i_out ); char *psz = FromCharset( psz_encoding, psz_instring, i_length );
if( !psz_outstring ) if( psz == NULL )
{ { /* Invalid character set (e.g. ISO_8859-12) */
return NULL; psz = strndup( (const char *)psz_instring, i_length );
if( unlikely(psz == NULL) )
return NULL;
EnsureUTF8( psz );
} }
iconv_handle = vlc_iconv_open( "UTF-8", psz_encoding ); /* Convert EIT-coded CR/LFs */
if( iconv_handle == (vlc_iconv_t)(-1) ) for(char *p = strstr( psz, "\xc2\x8a" ); p != NULL;
{ p = strstr( p, "\xc2\x8a" ))
/* Invalid character set (e.g. ISO_8859-12) */
memcpy( psz_outstring, &psz_instring[offset], i_in );
psz_outstring[i_in] = '\0';
EnsureUTF8( psz_outstring );
}
else
{ {
const char *psz_in = (const char *)&psz_instring[offset]; p[0] = ' ';
char *psz_out = psz_outstring; p[1] = '\n';
while( vlc_iconv( iconv_handle, &psz_in, &i_in,
&psz_out, &i_out ) == (size_t)(-1) )
{
/* skip naughty byte. This may fail terribly for multibyte stuff,
* but what can we do anyway? */
psz_in++;
i_in--;
vlc_iconv( iconv_handle, NULL, NULL, NULL, NULL ); /* reset */
}
vlc_iconv_close( iconv_handle );
*psz_out = '\0';
/* Convert EIT-coded CR/LFs */
unsigned char *pbuf = (unsigned char *)psz_outstring;
for( ; pbuf < (unsigned char *)psz_out ; pbuf++)
{
if( pbuf[0] == 0xc2 && pbuf[1] == 0x8a )
{
pbuf[0] = ' ';
pbuf[1] = '\n';
}
}
} }
return psz_outstring; return psz;
} }
static void SDTCallBack( demux_t *p_demux, dvbpsi_sdt_t *p_sdt ) static void SDTCallBack( demux_t *p_demux, dvbpsi_sdt_t *p_sdt )
......
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