Skip to content

Commit

Permalink
Add compat_decompose method
Browse files Browse the repository at this point in the history
  • Loading branch information
deepakjois committed Sep 24, 2016
1 parent cea7be4 commit 126b7d8
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 1 deletion.
31 changes: 30 additions & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ <h2><a href="#Functions">Functions</a></h2>
<td class="name" nowrap><a href="#paired_bracket_type">paired_bracket_type (code)</a></td>
<td class="summary">Get paired bracket type for a codepoint.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#compat_decompose">compat_decompose (code)</a></td>
<td class="summary">Get compatibility decomposition for a codepoint.</td>
</tr>
</table>
<h2><a href="#Bidi_Class_property">Bidi_Class property</a></h2>
<table class="function_list">
Expand Down Expand Up @@ -290,6 +294,31 @@ <h3>Returns:</h3>



</dd>
<dt>
<a name = "compat_decompose"></a>
<strong>compat_decompose (code)</strong>
</dt>
<dd>
Get compatibility decomposition for a codepoint.


<h3>Parameters:</h3>
<ul>
<li><span class="parameter">code</span>
Unicode codepoint
</li>
</ul>

<h3>Returns:</h3>
<ol>

table containing the decomposed codepoints.
</ol>




</dd>
</dl>
<h2 class="section-header has-description"><a name="Bidi_Class_property"></a>Bidi_Class property</h2>
Expand Down Expand Up @@ -676,7 +705,7 @@ <h2 class="section-header has-description"><a name="Bidi_Paired_Bracket_Type_pro
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.5</a></i>
<i style="float:right;">Last updated 2016-09-02 19:22:23 </i>
<i style="float:right;">Last updated 2016-09-24 20:20:06 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
Expand Down
22 changes: 22 additions & 0 deletions luaucdn-0.0.4-0.rockspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package = "luaucdn"
version = "0.0.4-0"
source = {
url = "git://github.com/deepakjois/luaucdn",
tag = "v0.0.4"
}
description = {
summary = "Lua bindings for ucdn",
homepage = "https://github.com/deepakjois/luaucdn",
license = "MIT",
maintainer = "Deepak Jois <[email protected]>"
}
dependencies = {
"lua ~> 5.2"
}
build = {
type = "builtin",
modules = {
ucdn = "src/ucdn.lua",
luaucdn = {"src/luaucdn/ucdn.c", "src/luaucdn/luaucdn.c"}
}
}
6 changes: 6 additions & 0 deletions spec/ucdn_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@ describe("ucdn module", function()
assert.are_equal(0xFF62, ucdn.paired_bracket(0xFF63))
assert.are_equal(0xFF63, ucdn.paired_bracket(0xFF62))
end)

it("returns the compatibility decomposition for a given codepoint", function()
assert.are_equal(0x3009, ucdn.compat_decompose(0x232a)[1])
assert.are_equal(0x3008, ucdn.compat_decompose(0x2329)[1])
assert.are.same({},ucdn.compat_decompose(0x3008))
end)
end)
17 changes: 17 additions & 0 deletions src/luaucdn/luaucdn.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,28 @@ int paired_bracket(lua_State *L) {
return 1;
}

int compat_decompose(lua_State *L) {
uint32_t c = lua_tounsigned(L, 1);

uint32_t decomposed[18];
unsigned int len = ucdn_compat_decompose(c, decomposed);

lua_newtable(L);
for (unsigned int i = 0; i < len; i++) {
lua_pushinteger(L, i+1);
lua_pushinteger(L, decomposed[i]);
lua_settable(L,-3);
}

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},
{"compat_decompose", compat_decompose},
{NULL, NULL}
};

Expand Down
5 changes: 5 additions & 0 deletions src/ucdn.luadoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
-- @return value according to ucdn.UCDN\_BIDI\_PAIRED\_BRACKET\_TYPE\_* and as defined in UAX#9.
-- @function paired_bracket_type

--- Get compatibility decomposition for a codepoint.
-- @param code Unicode codepoint
-- @return table containing the decomposed codepoints.
-- @function compat_decompose

--- Bidi_Class property.
-- Enumerated constants representing [Bidi_Class values](http://www.unicode.org/reports/tr44/#Bidi_Class_Values).
-- @section
Expand Down

0 comments on commit 126b7d8

Please sign in to comment.