From f7b4fd2979e3a47c854638e4289883ba15e07705 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Mon, 26 Nov 2012 14:26:43 +0000 Subject: libs/web: various changes in template library - rename sanitize_pcdata() and sanitize_utf8() to pcdata() and utf8() - implement striptags() --- libs/web/src/template_lualib.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'libs/web/src/template_lualib.c') diff --git a/libs/web/src/template_lualib.c b/libs/web/src/template_lualib.c index f40ef2d6ae..0d43641041 100644 --- a/libs/web/src/template_lualib.c +++ b/libs/web/src/template_lualib.c @@ -44,11 +44,11 @@ int template_L_parse(lua_State *L) return rv; } -int template_L_sanitize_utf8(lua_State *L) +int template_L_utf8(lua_State *L) { size_t len = 0; const char *str = luaL_checklstring(L, 1, &len); - char *res = sanitize_utf8(str, len); + char *res = utf8(str, len); if (res != NULL) { @@ -61,11 +61,28 @@ int template_L_sanitize_utf8(lua_State *L) return 0; } -int template_L_sanitize_pcdata(lua_State *L) +int template_L_pcdata(lua_State *L) { size_t len = 0; const char *str = luaL_checklstring(L, 1, &len); - char *res = sanitize_pcdata(str, len); + char *res = pcdata(str, len); + + if (res != NULL) + { + lua_pushstring(L, res); + free(res); + + return 1; + } + + return 0; +} + +int template_L_striptags(lua_State *L) +{ + size_t len = 0; + const char *str = luaL_checklstring(L, 1, &len); + char *res = striptags(str, len); if (res != NULL) { @@ -129,8 +146,9 @@ static int template_L_hash(lua_State *L) { /* module table */ static const luaL_reg R[] = { { "parse", template_L_parse }, - { "sanitize_utf8", template_L_sanitize_utf8 }, - { "sanitize_pcdata", template_L_sanitize_pcdata }, + { "utf8", template_L_utf8 }, + { "pcdata", template_L_pcdata }, + { "striptags", template_L_striptags }, { "load_catalog", template_L_load_catalog }, { "close_catalog", template_L_close_catalog }, { "change_catalog", template_L_change_catalog }, -- cgit v1.2.3