Skip to content

Commit 204bf6d

Browse files
committed
Update 0.4.0
1 parent 8eca1e9 commit 204bf6d

File tree

7 files changed

+179
-75
lines changed

7 files changed

+179
-75
lines changed

LICENSE

100644100755
File mode changed.

Makefile

100644100755
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
CC = gcc
22
INSTALL = install
3+
TEST = test
34

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

22+
info:
23+
@echo -e '\e[31m \n Module for Lua'
24+
@echo -e '\e[32m \n Name:htmlEntities-for-lua\n Author TiagoDanin\n Version: 0.4.0\n License: MIT\n \e[0m'
25+
26+
test:
27+
@lua test.lua
2128

2229
installall: all
2330
all:

README.md

100644100755
Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ Module for decoding of text using entities html,
66
or encode of text to entities html.
77

88

9-
##Requires
9+
## Requires
1010
Written for Lua 5.2 but will probably run on 5.3 or 5.1.
1111

1212

13-
##Setup
14-
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`
13+
## Setup
14+
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
1515

1616

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

33+
[htmlEntities-for-lua V0.4.0](https://github.com/TiagoDanin/htmlEntities-for-lua/releases/tag/0.4.0)
34+
3335
[htmlEntities-for-lua V0.3.1](https://github.com/TiagoDanin/htmlEntities-for-lua/releases/tag/0.3.1)
3436

35-
[htmlEntities-for-lua V0.2](https://github.com/TiagoDanin/htmlEntities-for-lua/releases/tag/0.2)
37+
[htmlEntities-for-lua V0.2.0](https://github.com/TiagoDanin/htmlEntities-for-lua/releases/tag/0.2)
38+
39+
[htmlEntities-for-lua V0.1.0](https://github.com/TiagoDanin/htmlEntities-for-lua/releases/tag/0.1)
40+
41+
42+
## DOC
43+
Module function:
44+
45+
Function | Info |
46+
---------|------|
47+
htmlEntities.decode(input) | Decode html entities to text
48+
htmlEntities.encode(input) | Encode text to html entities :v
49+
htmlEntities.ASCII_HEX(input) | Decode for ASCII HEX
50+
htmlEntities.ASCII_DEC(input) | Decode for ASCII DEC
51+
52+
Module option:
3653

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

3962

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

5174

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

5578
---

example.lua

Lines changed: 0 additions & 35 deletions
This file was deleted.

html-entities-0.3.1-0.rockspec

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/htmlEntities.lua

100644100755
Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ Copyright (c) 2016 Tiago Danin
3030
]==]--
3131

3232
local htmlEntities = {
33-
version = '0.3.1',
33+
version = '0.4.0',
3434
name = 'htmlEntities-for-lua',
3535
author = 'Tiago Danin - 2016',
36-
license = 'The MIT License (MIT)',
36+
license = 'MIT',
3737
page = 'github.com/TiagoDanin/htmlEntities-for-lua'
3838
}
3939

@@ -311,14 +311,25 @@ local htmlEntities_table = {
311311
['&#8482;'] = ''
312312
}
313313

314-
function htmlEntities.ASCII_dec (input)
315-
if not input then print('htmlEntities >> ERRO: input is value nil') return end
314+
function htmlEntities.ASCII_DEC (input)
315+
if not input then print('htmlEntities[ASCII_DEC] >> ERRO: input is value nil') return end
316+
if string.len(input) == 2 then
317+
input = tonumber(input, 16)
318+
local output = htmlEntities.ASCII_HEX(input)
319+
return output
320+
else
321+
return input
322+
end
323+
end
324+
325+
function htmlEntities.ASCII_HEX (input)
326+
if not input then print('htmlEntities[ASCII_HEX] >> ERRO: input is value nil') return end
316327
if math.abs(input) < 256 then
317328
if _VERSION == 'Lua 5.3' then
318329
return utf8.char(input)
319330
else
320331
local output = string.char(input)
321-
if utf8_htmlEntities and not output:match('([%z\1-\127\194-\244][\128-\191]*)')then
332+
if utf8_htmlEntities and not output:match('([%z\1-\127\194-\244][\128-\191]*)') then
322333
return input
323334
end
324335
return output
@@ -329,23 +340,27 @@ function htmlEntities.ASCII_dec (input)
329340
end
330341

331342
function htmlEntities.decode (input)
332-
if not input then print('htmlEntities >> ERRO: input is value nil') return end
343+
if not input then print('htmlEntities[decode] >> ERRO: input is value nil') return end
333344
local output = string.gsub(input, '&.-;', htmlEntities_table)
334345
if ASCII_htmlEntities then
335-
output = string.gsub(output, '&#([1234567890]*);', htmlEntities.ASCII_dec)
346+
output = string.gsub(output, '&#x([1234567890]*);', htmlEntities.ASCII_DEC)
347+
output = string.gsub(output, '&#([1234567890]*);', htmlEntities.ASCII_HEX)
336348
end
337349

338350
if debug_htmlEntities then print('>>'..output) end
339351
return output
340352
end
341353

342354
function htmlEntities.encode (input)
343-
if not input then print('htmlEntities >> ERRO: input is value nil') return end
355+
if not input then print('htmlEntities[encode] >> ERRO: input is value nil') return end
344356
input = htmlEntities.decode(input)
345357
local output = ''
346358
for k = 1, string.len(input) do
347-
output = output .. '&#'.. string.sub(input,k,k):byte() ..';'
359+
local input = string.sub(input,k,k)
360+
output = output .. '&#'.. input:byte() ..';'
348361
end
362+
363+
if debug_htmlEntities then print('>>'..output) end
349364
return output
350365
end
351366

test.lua

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
htmlEntities = require('src/htmlEntities')
2+
3+
print('\n\nInit test htmlEntities')
4+
local text = [[&amp;&#88;&#65;&#77;&#80;&#76;&#69; text
5+
&it;&equiv;&equiv;&equiv;&equiv;&equiv;&equiv;&equiv;&equiv;&equiv;&equiv;&gt;]]
6+
7+
for k,v in pairs(htmlEntities) do
8+
if v and type(v) == 'string' then -- Print Info
9+
print(k .. ': ' .. v)
10+
end
11+
end
12+
13+
local dec = htmlEntities.decode(text)
14+
print('\nInput: ' .. text .. '\n\nOutput: ' .. dec)
15+
16+
17+
repeat
18+
io.write('\nYou want to do a test (y/n) ')
19+
io.flush()
20+
res = io.read()
21+
until res == 'y' or res == 'n'
22+
23+
function type()
24+
repeat
25+
io.write('\n d = Decode e = Encode s = SpeedTest a = ASCII_Decode\n > ')
26+
io.flush()
27+
res = io.read()
28+
until res == 'd' or res == 'e' or res == 's' or res == 'a'
29+
30+
function test_decode()
31+
local init = true
32+
while init do
33+
print('\nPut text')
34+
io.write('> ')
35+
input = io.read()
36+
print('Input: ' .. input .. '\nOutput: ' .. htmlEntities.decode(input) .. '\n')
37+
end
38+
end
39+
40+
function test_encode()
41+
local init = true
42+
while init do
43+
print('\nPut text')
44+
io.write('> ')
45+
input = io.read()
46+
print('Input: '.. input .. '\nOutput: ' .. htmlEntities.encode(input) .. '\n')
47+
end
48+
end
49+
50+
function test_speed()
51+
print('\n\nInit Time')
52+
local time_init = io.popen('date +%S.%N'):read('*all')
53+
54+
print('ASCII Decode [HEX 33-255 to DEC] to Char')
55+
local char = {}
56+
for i = 33, 255 do
57+
hex = i
58+
dec = string.format('%02X', hex)
59+
local x_1 = htmlEntities.ASCII_HEX(hex)
60+
table.insert(char, x_1)
61+
local x_2 = htmlEntities.ASCII_DEC(dec)
62+
table.insert(char, x_2)
63+
end
64+
local time_1 = io.popen('date +%S.%N'):read('*all')
65+
66+
print('Char to encode htmlEntities')
67+
local encode = {'&micro;', '&yen;', '&uuml;', '&lrm;', '&#8482;', '&lceil;', '&#45;'}
68+
for i,v in ipairs(char) do
69+
local x = htmlEntities.encode(v)
70+
table.insert(encode, x)
71+
end
72+
local time_2 = io.popen('date +%S.%N'):read('*all')
73+
74+
print('decode htmlEntities to Char')
75+
for i,v in ipairs(encode) do
76+
htmlEntities.decode(v)
77+
end
78+
local time_3 = io.popen('date +%S.%N'):read('*all')
79+
80+
local time = (((time_1 + time_2 + time_3) / 3) - time_init)
81+
print('TIME (%S.%N):' .. time .. '\n\n')
82+
end
83+
84+
function test_ascii()
85+
print('\nInit Table')
86+
local dec = ''
87+
local hex = ''
88+
for i = 33, 255 do
89+
hex = i
90+
dec = string.format('%02X', hex)
91+
92+
if string.len(hex) == 3 then
93+
print('HEX: ' .. hex .. ' Output: ' .. htmlEntities.ASCII_HEX(hex))
94+
else
95+
print('HEX: ' .. hex .. ' Output: ' .. htmlEntities.ASCII_HEX(hex))
96+
end
97+
98+
if string.len(dec) == 3 then
99+
print('DEC: ' .. dec .. ' Output: ' .. htmlEntities.ASCII_DEC(dec) .. '\n')
100+
else
101+
print('DEC: ' .. dec .. ' Output: ' .. htmlEntities.ASCII_DEC(dec) .. '\n')
102+
end
103+
104+
end
105+
end
106+
107+
-- Res
108+
if res == 'd' then
109+
test_decode()
110+
elseif res == 'e' then
111+
test_encode()
112+
elseif res == 's' then
113+
test_speed()
114+
elseif res == 'a' then
115+
test_ascii()
116+
end
117+
end
118+
119+
if res == 'y' then type() end

0 commit comments

Comments
 (0)