Skip to content

Commit

Permalink
Wrap ucdn_paired_bracket and ucdn_paired_bracket_type. Fix #3
Browse files Browse the repository at this point in the history
  • Loading branch information
deepakjois committed Apr 22, 2016
1 parent 6f1286e commit 4100431
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
16 changes: 16 additions & 0 deletions spec/ucdn_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,20 @@ describe("ucdn module", function()
assert.are_equal(ucdn.UCDN_BIDI_CLASS_L, ucdn.get_bidi_class(0x0907)) -- U+0907 DEVANAGARI LETTER I
assert.are_equal(ucdn.UCDN_BIDI_CLASS_WS, ucdn.get_bidi_class(0x0020)) -- U+0020 SPACE
end)

it("returns the Bidi_Paired_Bracket_Type for a given codepoint", function()
assert.are_equal(ucdn.UCDN_BIDI_PAIRED_BRACKET_TYPE_OPEN, ucdn.paired_bracket_type(0x0028)) -- U+0028 LEFT PARENTHESIS
assert.are_equal(ucdn.UCDN_BIDI_PAIRED_BRACKET_TYPE_CLOSE, ucdn.paired_bracket_type(0x0029)) -- U+0029 RIGHT PARENTHESIS
assert.are_equal(ucdn.UCDN_BIDI_PAIRED_BRACKET_TYPE_NONE, ucdn.paired_bracket_type(0x0041)) -- U+0041 LATIN CAPITAL LETTER A
end)

it("returns the corresponding Bidi_Paired_Bracket codepoint for a given codepoint", function()
-- LEFT PARENTHESIS and RIGHT PARENTHESIS
assert.are_equal(0x0029, ucdn.paired_bracket(0x0028))
assert.are_equal(0x0028, ucdn.paired_bracket(0x0029))

-- HALFWIDTH LEFT CORNER BRACKET and HALFWIDTH RIGHT CORNER BRACKET
assert.are_equal(0xFF62, ucdn.paired_bracket(0xFF63))
assert.are_equal(0xFF63, ucdn.paired_bracket(0xFF62))
end)
end)
14 changes: 14 additions & 0 deletions src/luaucdn/luaucdn.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,23 @@ int get_bidi_class(lua_State *L) {
return 1;
}

int paired_bracket_type(lua_State *L) {
uint32_t c = lua_tounsigned(L, 1);
lua_pushinteger(L, ucdn_paired_bracket_type(c));
return 1;
}

int paired_bracket(lua_State *L) {
uint32_t c = lua_tounsigned(L, 1);
lua_pushinteger(L, ucdn_paired_bracket(c));
return 1;
}

static const struct luaL_Reg lib_table [] = {
{"get_unicode_version", get_unicode_version},
{"get_bidi_class", get_bidi_class},
{"paired_bracket_type", paired_bracket_type},
{"paired_bracket", paired_bracket},
{NULL, NULL}
};

Expand Down
5 changes: 5 additions & 0 deletions src/ucdn.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ lu.UCDN_BIDI_CLASS_RLI = 20
lu.UCDN_BIDI_CLASS_FSI = 21
lu.UCDN_BIDI_CLASS_PDI = 22

-- Bidi_Paired_Bracket_Type values
lu.UCDN_BIDI_PAIRED_BRACKET_TYPE_OPEN = 0
lu.UCDN_BIDI_PAIRED_BRACKET_TYPE_CLOSE = 1
lu.UCDN_BIDI_PAIRED_BRACKET_TYPE_NONE = 2

return lu
22 changes: 22 additions & 0 deletions src/ucdn.luadoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@
-- @return value according to ucdn.UCDN_BIDI_CLASS_* and as defined in UAX#44.
-- @function get_bidi_class

--- Get paired bracket for a codepoint.
-- @param code Unicode codepoint
-- @return paired bracket codepoint or the original codepoint if no paired bracket character exists
-- @function paired_bracket

--- Get paired bracket type for a codepoint.
-- @param code Unicode codepoint
-- @return value according to ucdn.UCDN_BIDI_PAIRED_BRACKET_TYPE_* and as defined in UAX#9.
-- @function paired_bracket_type

--- Bidi_Class property.
-- Enumerated constants representing [Bidi_Class values](http://www.unicode.org/reports/tr44/#Bidi_Class_Values).
-- @section
Expand Down Expand Up @@ -89,3 +99,15 @@
--- Pop\_Directional_Isolate
-- @field ucdn.UCDN_BIDI_CLASS_PDI

--- Bidi_Paired_Bracket_Type property.
-- Enumerated constants representing [Bidi\_Paired_Bracket\_Type values](http://www.unicode.org/Public/UCD/latest/ucd/BidiBrackets.txt).
-- @section

--- Open
-- @field ucdn.UCDN_BIDI_PAIRED_BRACKET_TYPE_OPEN

--- Close
-- @field ucdn.UCDN_BIDI_PAIRED_BRACKET_TYPE_CLOSE

--- None
-- @field ucdn.UCDN_BIDI_PAIRED_BRACKET_TYPE_NONE

0 comments on commit 4100431

Please sign in to comment.