Skip to content

Commit

Permalink
Update 0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
TiagoDanin committed Mar 28, 2016
1 parent 8eca1e9 commit 204bf6d
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 75 deletions.
Empty file modified LICENSE
100644 → 100755
Empty file.
7 changes: 7 additions & 0 deletions Makefile
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CC = gcc
INSTALL = install
TEST = test

PREFIX = /usr/local
SOURCES = src/htmlEntities.lua
Expand All @@ -18,6 +19,12 @@ msg_end = "Files can be located in:'\n '$(LUA_LIBDIR)/*Version' and '$(LUA_SHARE
install: all
unistall: unistallall

info:
@echo -e '\e[31m \n Module for Lua'
@echo -e '\e[32m \n Name:htmlEntities-for-lua\n Author TiagoDanin\n Version: 0.4.0\n License: MIT\n \e[0m'

test:
@lua test.lua

installall: all
all:
Expand Down
35 changes: 29 additions & 6 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ Module for decoding of text using entities html,
or encode of text to entities html.


##Requires
## Requires
Written for Lua 5.2 but will probably run on 5.3 or 5.1.


##Setup
Use the terminal `wget https://github.com/TiagoDanin/htmlEntities-for-lua/releases/download/0.3.1/htmlEntities-for-lua.0.3.1.zip && unzip htmlEntities-for-lua.0.3.zip && make install`
## Setup
Use the terminal `wget https://github.com/TiagoDanin/htmlEntities-for-lua/releases/download/0.4.0/htmlEntities-for-lua.0.4.0.zip && unzip htmlEntities-for-lua.0.4.0.zip && make install


Makefile:
Expand All @@ -30,11 +30,34 @@ The same goes for remove `$ make unistall5.x`
## Releases
[htmlEntities-for-lua BETA](https://github.com/TiagoDanin/htmlEntities-for-lua/tree/master)

[htmlEntities-for-lua V0.4.0](https://github.com/TiagoDanin/htmlEntities-for-lua/releases/tag/0.4.0)

[htmlEntities-for-lua V0.3.1](https://github.com/TiagoDanin/htmlEntities-for-lua/releases/tag/0.3.1)

[htmlEntities-for-lua V0.2](https://github.com/TiagoDanin/htmlEntities-for-lua/releases/tag/0.2)
[htmlEntities-for-lua V0.2.0](https://github.com/TiagoDanin/htmlEntities-for-lua/releases/tag/0.2)

[htmlEntities-for-lua V0.1.0](https://github.com/TiagoDanin/htmlEntities-for-lua/releases/tag/0.1)


## DOC
Module function:

Function | Info |
---------|------|
htmlEntities.decode(input) | Decode html entities to text
htmlEntities.encode(input) | Encode text to html entities :v
htmlEntities.ASCII_HEX(input) | Decode for ASCII HEX
htmlEntities.ASCII_DEC(input) | Decode for ASCII DEC

Module option:

[htmlEntities-for-lua V0.1](https://github.com/TiagoDanin/htmlEntities-for-lua/releases/tag/0.1)
String | Default | Info |
-------|---------|------|
debug_htmlEntities | false | Print in output
ASCII_htmlEntities | true | Decode for entities ASCII
utf8_htmlEntities | true | Force utf8 for <= lua5.2
register_global_module_htmlEntities | false | register module global
global_module_name_htmlEntities | "htmlEntities" | Name (global module)


## Pages
Expand All @@ -49,7 +72,7 @@ Suggestions and Support [New Issue](https://github.com/TiagoDanin/htmlEntities-f
For stable versions to access [Releases](https://github.com/TiagoDanin/htmlEntities-for-lua/releases)


##LICENSE
## LICENSE
The MIT License [(MIT)](https://github.com/TiagoDanin/htmlEntities-for-lua/blob/master/LICENSE)

---
Expand Down
35 changes: 0 additions & 35 deletions example.lua

This file was deleted.

25 changes: 0 additions & 25 deletions html-entities-0.3.1-0.rockspec

This file was deleted.

33 changes: 24 additions & 9 deletions src/htmlEntities.lua
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ Copyright (c) 2016 Tiago Danin
]==]--

local htmlEntities = {
version = '0.3.1',
version = '0.4.0',
name = 'htmlEntities-for-lua',
author = 'Tiago Danin - 2016',
license = 'The MIT License (MIT)',
license = 'MIT',
page = 'github.com/TiagoDanin/htmlEntities-for-lua'
}

Expand Down Expand Up @@ -311,14 +311,25 @@ local htmlEntities_table = {
['&#8482;'] = ''
}

function htmlEntities.ASCII_dec (input)
if not input then print('htmlEntities >> ERRO: input is value nil') return end
function htmlEntities.ASCII_DEC (input)
if not input then print('htmlEntities[ASCII_DEC] >> ERRO: input is value nil') return end
if string.len(input) == 2 then
input = tonumber(input, 16)
local output = htmlEntities.ASCII_HEX(input)
return output
else
return input
end
end

function htmlEntities.ASCII_HEX (input)
if not input then print('htmlEntities[ASCII_HEX] >> ERRO: input is value nil') return end
if math.abs(input) < 256 then
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
if utf8_htmlEntities and not output:match('([%z\1-\127\194-\244][\128-\191]*)') then
return input
end
return output
Expand All @@ -329,23 +340,27 @@ function htmlEntities.ASCII_dec (input)
end

function htmlEntities.decode (input)
if not input then print('htmlEntities >> ERRO: input is value nil') return end
if not input then print('htmlEntities[decode] >> 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)
output = string.gsub(output, '&#x([1234567890]*);', htmlEntities.ASCII_DEC)
output = string.gsub(output, '&#([1234567890]*);', htmlEntities.ASCII_HEX)
end

if debug_htmlEntities then print('>>'..output) end
return output
end

function htmlEntities.encode (input)
if not input then print('htmlEntities >> ERRO: input is value nil') return end
if not input then print('htmlEntities[encode] >> 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() ..';'
local input = string.sub(input,k,k)
output = output .. '&#'.. input:byte() ..';'
end

if debug_htmlEntities then print('>>'..output) end
return output
end

Expand Down
119 changes: 119 additions & 0 deletions test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
htmlEntities = require('src/htmlEntities')

print('\n\nInit test htmlEntities')
local text = [[&amp;&#88;&#65;&#77;&#80;&#76;&#69; text
&it;&equiv;&equiv;&equiv;&equiv;&equiv;&equiv;&equiv;&equiv;&equiv;&equiv;&gt;]]

for k,v in pairs(htmlEntities) do
if v and type(v) == 'string' then -- Print Info
print(k .. ': ' .. v)
end
end

local dec = htmlEntities.decode(text)
print('\nInput: ' .. text .. '\n\nOutput: ' .. dec)


repeat
io.write('\nYou want to do a test (y/n) ')
io.flush()
res = io.read()
until res == 'y' or res == 'n'

function type()
repeat
io.write('\n d = Decode e = Encode s = SpeedTest a = ASCII_Decode\n > ')
io.flush()
res = io.read()
until res == 'd' or res == 'e' or res == 's' or res == 'a'

function test_decode()
local init = true
while init do
print('\nPut text')
io.write('> ')
input = io.read()
print('Input: ' .. input .. '\nOutput: ' .. htmlEntities.decode(input) .. '\n')
end
end

function test_encode()
local init = true
while init do
print('\nPut text')
io.write('> ')
input = io.read()
print('Input: '.. input .. '\nOutput: ' .. htmlEntities.encode(input) .. '\n')
end
end

function test_speed()
print('\n\nInit Time')
local time_init = io.popen('date +%S.%N'):read('*all')

print('ASCII Decode [HEX 33-255 to DEC] to Char')
local char = {}
for i = 33, 255 do
hex = i
dec = string.format('%02X', hex)
local x_1 = htmlEntities.ASCII_HEX(hex)
table.insert(char, x_1)
local x_2 = htmlEntities.ASCII_DEC(dec)
table.insert(char, x_2)
end
local time_1 = io.popen('date +%S.%N'):read('*all')

print('Char to encode htmlEntities')
local encode = {'&micro;', '&yen;', '&uuml;', '&lrm;', '&#8482;', '&lceil;', '&#45;'}
for i,v in ipairs(char) do
local x = htmlEntities.encode(v)
table.insert(encode, x)
end
local time_2 = io.popen('date +%S.%N'):read('*all')

print('decode htmlEntities to Char')
for i,v in ipairs(encode) do
htmlEntities.decode(v)
end
local time_3 = io.popen('date +%S.%N'):read('*all')

local time = (((time_1 + time_2 + time_3) / 3) - time_init)
print('TIME (%S.%N):' .. time .. '\n\n')
end

function test_ascii()
print('\nInit Table')
local dec = ''
local hex = ''
for i = 33, 255 do
hex = i
dec = string.format('%02X', hex)

if string.len(hex) == 3 then
print('HEX: ' .. hex .. ' Output: ' .. htmlEntities.ASCII_HEX(hex))
else
print('HEX: ' .. hex .. ' Output: ' .. htmlEntities.ASCII_HEX(hex))
end

if string.len(dec) == 3 then
print('DEC: ' .. dec .. ' Output: ' .. htmlEntities.ASCII_DEC(dec) .. '\n')
else
print('DEC: ' .. dec .. ' Output: ' .. htmlEntities.ASCII_DEC(dec) .. '\n')
end

end
end

-- Res
if res == 'd' then
test_decode()
elseif res == 'e' then
test_encode()
elseif res == 's' then
test_speed()
elseif res == 'a' then
test_ascii()
end
end

if res == 'y' then type() end

0 comments on commit 204bf6d

Please sign in to comment.