Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
update cctype to put dependencies in proper order
  • Loading branch information
William Adams committed Jun 25, 2017
1 parent b358771 commit 11673fa
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 19 deletions.
42 changes: 25 additions & 17 deletions cctype.lua
Expand Up @@ -11,17 +11,7 @@ local band = bit.band
local bor = bit.bor
local function tolower(c)
return band(0xff,bor(c, 0x20))
end
local function toupper(c)
if (islower(c)) then
return band(c, 0x5f)
end
return c
end
local t_a = string.byte('a')
local t_f = string.byte('f')
Expand All @@ -32,15 +22,23 @@ local t_Z = string.byte('Z')
local t_0 = string.byte('0')
local t_9 = string.byte('9')
local function isalnum(c)
return (isalpha(c) or isdigit(c))
end
local function isalpha(c)
return (c >= t_a and c <= t_z) or
(c >= t_A and c <= t_Z)
end
local function isdigit(c)
return c >= t_0 and c <= t_9
end
local function isalnum(c)
return (isalpha(c) or isdigit(c))
end
local function isascii(c)
return (c >= 0) and (c <= 0x7f)
end
Expand All @@ -53,9 +51,7 @@ local function iscntrl(c)
return (c >= 0 and c < 0x20) or (c == 0x7f)
end
local function isdigit(c)
return c >= t_0 and c <= t_9
end
local function isgraph(c)
return c > 0x20 and c < 0x7f
Expand Down Expand Up @@ -96,6 +92,18 @@ local function isxdigit(c)
(c >= t_A and c <= t_F)
end
local function tolower(c)
return band(0xff,bor(c, 0x20))
end
local function toupper(c)
if (islower(c)) then
return band(c, 0x5f)
end
return c
end
return {
isalnum = isalnum,
isalpha = isalpha,
Expand All @@ -105,10 +113,10 @@ return {
isdigit = isdigit,
isgraph = isgraph,
islower = islower,
isupper = isupper,
isprint = isprint,
ispunct = ispunct,
isspace = isspace,
isupper = isupper,
isxdigit = isxdigit,
tolower = tolower,
Expand Down
2 changes: 1 addition & 1 deletion enumbits.lua
Expand Up @@ -3,7 +3,7 @@
flags of some state, we want to get the string value which
is used as a key to represent the integer flag value in a table.
The enumbits() runction returns an iterator, which will push
The enumbits() function returns an iterator, which will push
out the names of the individual bits, as they are found in a
table.
Expand Down
4 changes: 4 additions & 0 deletions maths.lua
Expand Up @@ -16,6 +16,8 @@ local function round(n)
return ceil(n-0.5)
end

-- determine whether the specified
-- value is a power of two
local function is_power_of_two(value)
if value == 0 then
return false;
Expand All @@ -38,6 +40,8 @@ local function roundup32(x)
return x
end

-- minimum number of bytes needed ro
-- represent a specific value
local function min_bytes_needed(value)
local bytes;

Expand Down
9 changes: 8 additions & 1 deletion tests/test_cctype.lua
Expand Up @@ -4,8 +4,13 @@ local ctype = require "cctype"

ffi = require "ffi"

function test_isspace ()
function test_toupper()
print("==== test_toupper ====")
print('a', string.char(ctype.toupper(string.byte('a'))))
end

function test_isspace ()
print("==== test_isspace ====")
local c;
local i=0;
local str = ffi.cast("char *", "Example \vsentence\t to test isspace\n");
Expand All @@ -24,6 +29,7 @@ function test_isspace ()
end

function test_isalpha()
print("==== test_isalpha ====")
assert(ctype.isalpha(string.byte('a')))
assert(ctype.isalpha(string.byte('z')))
assert(ctype.isalpha(string.byte('A')))
Expand All @@ -36,5 +42,6 @@ end

test_isalpha();
test_isspace();
test_toupper();

print("PASS")

0 comments on commit 11673fa

Please sign in to comment.