From c6cbe72c4085cc172f8799d8637cfa79fbc76449 Mon Sep 17 00:00:00 2001 From: Tiago Danin Date: Thu, 3 Mar 2016 20:21:10 -0300 Subject: [PATCH] Update module for 0.3 --- Makefile | 90 +++++++++++++++++++++++++++++++------------- example.lua | 12 ++++-- src/htmlEntities.lua | 35 +++++++++++++---- 3 files changed, 101 insertions(+), 36 deletions(-) diff --git a/Makefile b/Makefile index 7ee4996..c5ca6a7 100644 --- a/Makefile +++ b/Makefile @@ -8,44 +8,82 @@ LUA = /5.2 BETA = /5.3 LUA_DIR = $(PREFIX) -LUA_SHAREDIR = $(LUA_DIR)/share/lua LUA_LIBDIR = $(LUA_DIR)/lib/lua +LUA_SHAREDIR = $(LUA_DIR)/share/lua + +msg_install = 'Requires permission of "root" to create the system directory' +msg_unistall = 'Requires permission of "root" to remove the system directory' +msg_end = "Files can be located in:'\n '$(LUA_LIBDIR)/*Version' and '$(LUA_SHAREDIR)/*Version'\nTo remove use '$ make unistall'" + +install: all +unistall: all + + +installall: all +all: + @echo 'Module for Lua' + @echo $(msg_install) + @sudo mkdir -p $(LUA_LIBDIR)$(LAST) + @sudo cp -f $(SOURCES) $(LUA_LIBDIR)$(LAST) + @sudo mkdir -p $(LUA_LIBDIR)$(LUA) + @sudo cp -f $(SOURCES) $(LUA_LIBDIR)$(LUA) + @sudo mkdir -p $(LUA_LIBDIR)$(BETA) + @sudo cp -f $(SOURCES) $(LUA_LIBDIR)$(BETA) + @sudo mkdir -p $(LUA_SHAREDIR)$(LAST) + @sudo cp -f $(SOURCES) $(LUA_SHAREDIR)$(LAST) + @sudo mkdir -p $(LUA_SHAREDIR)$(LUA) + @sudo cp -f $(SOURCES) $(LUA_SHAREDIR)$(LUA) + @sudo mkdir -p $(LUA_SHAREDIR)$(BETA) + @sudo cp -f $(SOURCES) $(LUA_SHAREDIR)$(BETA) + @echo $(msg_end) -install: 5.2 - 5.1: - @echo 'Libs for Lua5.1' - @echo 'Requirement permission "root" to create directory in the system' + @echo 'Module for Lua5.1' + @echo $(msg_install) @sudo mkdir -p $(LUA_LIBDIR)$(LAST) + @sudo cp -f $(SOURCES) $(LUA_LIBDIR)$(LAST) @sudo mkdir -p $(LUA_SHAREDIR)$(LAST) - @cp -f $(SOURCES) $(LUA_LIBDIR)$(LAST) - @cp -f $(SOURCES) $(LUA_SHAREDIR)$(LAST) - @echo 'Files can be located in:' - @echo "'$(LUA_LIBDIR)' and '@(LUA_SHAREDIR)'" - @echo "To remove use '$ make unistall'" + @sudo cp -f $(SOURCES) $(LUA_SHAREDIR)$(LAST) + @echo $(msg_end) 5.2: - @echo 'Libs for Lua5.2' - @echo 'Requirement permission "root" to create directory in the system' + @echo 'Module for Lua5.2' + @echo $(msg_install) @sudo mkdir -p $(LUA_LIBDIR)$(LUA) + @sudo cp -f $(SOURCES) $(LUA_LIBDIR)$(LUA) @sudo mkdir -p $(LUA_SHAREDIR)$(LUA) - @cp -f $(SOURCES) $(LUA_LIBDIR)$(LUA) - @cp -f $(SOURCES) $(LUA_SHAREDIR)$(LUA) - @echo 'Files can be located in:' - @echo "'$(LUA_LIBDIR)' and '@(LUA_SHAREDIR)'" - @echo "To remove use '$ make unistall'" + @sudo cp -f $(SOURCES) $(LUA_SHAREDIR)$(LUA) + @echo $(msg_end) 5.3: - @echo 'Libs for Lua5.3' - @echo 'Requirement permission "root" to create directory in the system' + @echo 'Module for Lua5.3' + @echo $(msg_install) @sudo mkdir -p $(LUA_LIBDIR)$(BETA) + @sudo cp -f $(SOURCES) $(LUA_LIBDIR)$(BETA) @sudo mkdir -p $(LUA_SHAREDIR)$(BETA) - @cp -f $(SOURCES) $(LUA_LIBDIR)$(BETA) - @cp -f $(SOURCES) $(LUA_SHAREDIR)$(BETA) - @echo 'Files can be located in:' - @echo "'$(LUA_LIBDIR)' and '@(LUA_SHAREDIR)'" - @echo "To remove use '$ make unistall'" + @sudo cp -f $(SOURCES) $(LUA_SHAREDIR)$(BETA) + @echo $(msg_end) + +unistall5.1: + @echo $(msg_install) + @sudo rm -f $(LUA_LIBDIR)$(LAST)/htmlEntities.lua + @sudo rm -f $(LUA_LIBDIR)$(LAST)/htmlEntities.lua + +unistall5.2: + @echo $(msg_install) + @sudo rm -f $(LUA_LIBDIR)$(LUA)/htmlEntities.lua + @sudo rm -f $(LUA_SHAREDIR)$(LUA)/htmlEntities.lua + +unistall5.3: + @echo $(msg_install) + @sudo rm -f $(LUA_LIBDIR)$(BETA)/htmlEntities.lua + @sudo rm -f $(LUA_SHAREDIR)$(BETA)/htmlEntities.lua -unistall: +unistallall: + @echo $(msg_install) + @sudo rm -f $(LUA_LIBDIR)$(LAST)/htmlEntities.lua @sudo rm -f $(LUA_LIBDIR)$(LUA)/htmlEntities.lua - @sudo rm -f $(LUA_SHAREDIR)$(LUA)/htmlEntities.lua \ No newline at end of file + @sudo rm -f $(LUA_LIBDIR)$(BETA)/htmlEntities.lua + @sudo rm -f $(LUA_SHAREDIR)$(LAST)/htmlEntities.lua + @sudo rm -f $(LUA_SHAREDIR)$(LUA)/htmlEntities.lua + @sudo rm -f $(LUA_SHAREDIR)$(BETA)/htmlEntities.lua diff --git a/example.lua b/example.lua index dba1b3b..e55421b 100644 --- a/example.lua +++ b/example.lua @@ -5,9 +5,14 @@ function test_module() local text = [[&XAMPLE text ⁢≡≡≡≡≡≡≡≡≡≡>]] + for k,v in pairs(htmlEntities) do + if v and type(v) == 'string' then + print(k .. ': ' .. v) + end + end + local dec = htmlEntities.decode(text) - print('Version'..htmlEntities.version) - print('Input: ' .. text .. '\n\nOutput: ' .. dec) + print('\nInput: ' .. text .. '\n\nOutput: ' .. dec) repeat io.write('\nYou want to do a test (y/n) ') @@ -20,7 +25,8 @@ function test_module() io.write('> ') io.flush() local input = io.read() - print('\nInput: ' .. input .. '\n\nOutput: ' .. htmlEntities.decode(input)) + --print('\nInput: ' .. input .. '\n\nOutput: ' .. htmlEntities.encode(input)) --Encode + print('\nInput: ' .. input .. '\n\nOutput: ' .. htmlEntities.decode(input)) --Decode test() end if res == 'y' then test() end diff --git a/src/htmlEntities.lua b/src/htmlEntities.lua index 2034db0..76645b3 100644 --- a/src/htmlEntities.lua +++ b/src/htmlEntities.lua @@ -1,6 +1,7 @@ -- Module options: local debug_htmlEntities = false local ASCII_htmlEntities = true +local utf8_htmlEntities = true local register_global_module_htmlEntities = false local global_module_name_htmlEntities = 'htmlEntities' @@ -29,9 +30,11 @@ Copyright (c) 2016 Tiago Danin ]==]-- local htmlEntities = { - version = "htmlEntities 0.2", - name = "htmlEntities", - author = "Tiago Danin - 2016" + version = '0.3', + name = 'htmlEntities-for-lua', + author = 'Tiago Danin - 2016', + license = 'The MIT License (MIT)', + page = 'github.com/TiagoDanin/htmlEntities-for-lua' } if register_global_module_htmlEntities then @@ -309,16 +312,24 @@ local htmlEntities_table = { } function htmlEntities.ASCII_dec (input) + if not input then print('htmlEntities >> ERRO: input is value nil') return end if math.abs(input) < 256 then - local output = input:char() - return output + if _VERSION == 'Lua 5.3' then + return utf8.char(input) + else + local output = string.char(input) + if utf8_htmlEntities and not output:match('([%z\1-\127\194-\244][\128-\191]*)')then + return input + end + return output + end else return input end end function htmlEntities.decode (input) - if not input then print('htmlEntities >> ERRO: input is value nil') end + if not input then print('htmlEntities >> ERRO: input is value nil') return end local output = string.gsub(input, '&.-;', htmlEntities_table) if ASCII_htmlEntities then output = string.gsub(output, '&#([1234567890]*);', htmlEntities.ASCII_dec) @@ -328,4 +339,14 @@ function htmlEntities.decode (input) return output end -return htmlEntities \ No newline at end of file +function htmlEntities.encode (input) + if not input then print('htmlEntities >> ERRO: input is value nil') return end + input = htmlEntities.decode(input) + local output = '' + for k = 1, string.len(input) do + output = output .. '&#'.. string.sub(input,k,k):byte() ..';' + end + return output +end + +return htmlEntities