[vlc-commits] commit: LUA: use FromCharset() ( Rémi Denis-Courmont )

git at videolan.org git at videolan.org
Wed Oct 27 21:31:32 CEST 2010


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Oct 27 22:31:01 2010 +0300| [a6e6fbffe4ff156a594908a53a6c143f9e3bb9b5] | committer: Rémi Denis-Courmont 

LUA: use FromCharset()

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a6e6fbffe4ff156a594908a53a6c143f9e3bb9b5
---

 modules/misc/lua/libs/strings.c  |   29 ++++++++---------------------
 share/lua/README.txt             |    4 ++--
 share/lua/playlist/katsomo.lua   |    6 +++---
 share/lua/playlist/lelombrik.lua |    2 +-
 4 files changed, 14 insertions(+), 27 deletions(-)

diff --git a/modules/misc/lua/libs/strings.c b/modules/misc/lua/libs/strings.c
index 94efa36..ae4a37f 100644
--- a/modules/misc/lua/libs/strings.c
+++ b/modules/misc/lua/libs/strings.c
@@ -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 }
 };
 
diff --git a/share/lua/README.txt b/share/lua/README.txt
index 1dd3609..55fa352 100644
--- a/share/lua/README.txt
+++ b/share/lua/README.txt
@@ -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
 ---------
diff --git a/share/lua/playlist/katsomo.lua b/share/lua/playlist/katsomo.lua
index daadf12..bf461c7 100644
--- a/share/lua/playlist/katsomo.lua
+++ b/share/lua/playlist/katsomo.lua
@@ -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
diff --git a/share/lua/playlist/lelombrik.lua b/share/lua/playlist/lelombrik.lua
index 5de87d8..6972dd6 100644
--- a/share/lua/playlist/lelombrik.lua
+++ b/share/lua/playlist/lelombrik.lua
@@ -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', *'([^']*)")



More information about the vlc-commits mailing list