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

LUA: use FromCharset()

parent 4dcd9522
......@@ -113,31 +113,18 @@ static int vlclua_convert_xml_special_chars( lua_State *L )
return i_top;
}
static int vlclua_iconv( lua_State *L )
static int vlclua_from_charset( lua_State *L )
{
int i_ret;
size_t i_out_bytes, i_in_bytes;
char *psz_output, *psz_original;
if( lua_gettop( L ) < 3 ) return vlclua_error( L );
const char *psz_input = luaL_checklstring( L, 3, &i_in_bytes );
size_t i_in_bytes;
const char *psz_input = luaL_checklstring( L, 2, &i_in_bytes );
if( i_in_bytes == 0 ) return vlclua_error( L );
vlc_iconv_t iconv_handle = vlc_iconv_open( luaL_checkstring(L, 1),
luaL_checkstring(L, 2) );
if( iconv_handle == (vlc_iconv_t)-1 )
return vlclua_error( L );
i_out_bytes = 4 * i_in_bytes;
psz_output = psz_original = malloc( i_out_bytes + 1 );
i_ret = vlc_iconv( iconv_handle, &psz_input ,
&i_in_bytes, &psz_output, &i_out_bytes );
*psz_output = '\0';
lua_pushstring( L, psz_original );
vlc_iconv_close( iconv_handle );
free( psz_original );
const char *psz_charset = luaL_checkstring( L, 1 );
char *psz_output = FromCharset( psz_charset, psz_input, i_in_bytes );
lua_pushstring( L, psz_output ? psz_output : "" );
free( psz_output );
return 1;
}
......@@ -149,7 +136,7 @@ static const luaL_Reg vlclua_strings_reg[] = {
{ "encode_uri_component", vlclua_encode_uri_component },
{ "resolve_xml_special_chars", vlclua_resolve_xml_special_chars },
{ "convert_xml_special_chars", vlclua_convert_xml_special_chars },
{ "iconv", vlclua_iconv },
{ "from_charset", vlclua_from_charset },
{ NULL, NULL }
};
......
......@@ -378,8 +378,8 @@ strings.resolve_xml_special_chars( [str1, [str2, [...]]] ): Resolve XML
variables as it had arguments.
strings.convert_xml_special_chars( [str1, [str2, [...]]] ): Do the inverse
operation.
strings.iconv( str1 to, str2 from, str ): use vlc_iconv to convert string
from encoding to another
strings.from_charset( charset, str ): convert a string from a specified
character encoding into UTF-8.
Variables
---------
......
......@@ -51,7 +51,7 @@ function parse()
if string.match( line, "<title>" )
then
title = vlc.strings.decode_uri( find( line, "<title>(.-)<" ) )
title = vlc.strings.iconv( "UTF-8", "ISO_8859-1", title )
title = vlc.strings.from_charset( "ISO_8859-1", title )
end
if( find( line, "img class=\"pngImg\" src=\"/multimedia/template/logos" ) )
then
......@@ -59,13 +59,13 @@ function parse()
end
for treeid,name in string.gmatch( line, "/\?treeId=(%d+)\">([^<]+)</a") do
name = vlc.strings.resolve_xml_special_chars( name )
name = vlc.strings.iconv( "UTF-8", "ISO_8859-1", name )
name = vlc.strings.from_charset( "ISO_8859-1", name )
path = "http://www.katsomo.fi/?treeId="..treeid
table.insert( p, { path = path; name = name; url = vlc.path; arturl=arturl; } )
end
for programid in string.gmatch( line, "<li class=\"program.*\" id=\"program(%d+)\" title=\".+\"" ) do
description = vlc.strings.resolve_xml_special_chars( find( line, "title=\"(.+)\"" ) )
description = vlc.strings.iconv( "UTF-8", "ISO_8859-1", description )
description = vlc.strings.from_charset( "ISO_8859-1", description )
path = "http://www.katsomo.fi/metafile.asx?p="..programid.."&bw=800"
table.insert( p, { path = path; name = description; url = vlc.path; arturl=arturl; } )
end
......
......@@ -38,7 +38,7 @@ function parse()
if string.match( line, "id=\"nom_fichier\">" ) then
title = string.gsub( line, ".*\"nom_fichier\">([^<]*).*", "%1" )
if title then
title = vlc.strings.iconv( "UTF8", "ISO_8859-1", title )
title = vlc.strings.from_charset( "ISO_8859-1", title )
end
elseif string.match( line, "'file'" ) then
_,_,path = string.find( line, "'file', *'([^']*)")
......
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