[vlc-devel] [PATCH 1/2] lua: add a guess_encoding function to convert Latin1 to UTF8
Ludovic Fauvet
etix at videolan.org
Tue Aug 27 15:15:52 CEST 2013
---
modules/lua/libs/strings.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/modules/lua/libs/strings.c b/modules/lua/libs/strings.c
index 39ae85e..356183a 100644
--- a/modules/lua/libs/strings.c
+++ b/modules/lua/libs/strings.c
@@ -148,6 +148,22 @@ static int vlclua_from_charset( lua_State *L )
return 1;
}
+static int vlclua_guess_encoding( lua_State *L )
+{
+ if( lua_gettop( L ) < 1 ) return vlclua_error( L );
+
+ size_t i_in_bytes;
+ const char *psz_input = luaL_checklstring( L, 1, &i_in_bytes );
+ if( i_in_bytes == 0 ) return vlclua_error( L );
+
+ char *psz_output = IsUTF8 ( psz_input ) ?
+ strdup ( psz_input ) : FromLatin1 ( psz_input );
+ lua_pushstring( L, psz_output ? psz_output : "" );
+ free( psz_output );
+ return 1;
+}
+
+
/*****************************************************************************
*
*****************************************************************************/
@@ -159,6 +175,7 @@ static const luaL_Reg vlclua_strings_reg[] = {
{ "resolve_xml_special_chars", vlclua_resolve_xml_special_chars },
{ "convert_xml_special_chars", vlclua_convert_xml_special_chars },
{ "from_charset", vlclua_from_charset },
+ { "guess_encoding", vlclua_guess_encoding },
{ NULL, NULL }
};
--
1.8.4
More information about the vlc-devel
mailing list