commit 9be4e9c: [Minor] Add Lua API for transliterate function
Vsevolod Stakhov
vsevolod at rspamd.com
Thu Jul 20 21:21:04 UTC 2023
Author: Vsevolod Stakhov
Date: 2023-07-20 22:18:33 +0100
URL: https://github.com/rspamd/rspamd/commit/9be4e9c559238b5bdd2cf6ca89725306ab52b70b (HEAD -> master)
[Minor] Add Lua API for transliterate function
---
src/lua/lua_util.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c
index 9f0630557..39e08c1fb 100644
--- a/src/lua/lua_util.c
+++ b/src/lua/lua_util.c
@@ -252,6 +252,15 @@ LUA_FUNCTION_DEF (util, lower_utf8);
*/
LUA_FUNCTION_DEF (util, normalize_utf8);
+
+/***
+ * @function util.transliterate(str)
+ * Converts utf8 encoded string to latin transliteration
+ * @param {string/text} str utf8 encoded string
+ * @return {text} transliterated string
+ */
+LUA_FUNCTION_DEF (util, transliterate);
+
/***
* @function util.strequal_caseless(str1, str2)
* Compares two strings regardless of their case using ascii comparison.
@@ -686,6 +695,7 @@ static const struct luaL_reg utillib_f[] = {
LUA_INTERFACE_DEF (util, strlen_utf8),
LUA_INTERFACE_DEF (util, lower_utf8),
LUA_INTERFACE_DEF (util, normalize_utf8),
+ LUA_INTERFACE_DEF (util, transliterate),
LUA_INTERFACE_DEF (util, strequal_caseless),
LUA_INTERFACE_DEF (util, strequal_caseless_utf8),
LUA_INTERFACE_DEF (util, get_ticks),
@@ -1635,6 +1645,24 @@ lua_util_normalize_utf8 (lua_State *L)
return 2;
}
+static gint
+lua_util_transliterate (lua_State *L)
+{
+ LUA_TRACE_POINT;
+ struct rspamd_lua_text *t;
+ t = lua_check_text_or_string (L, 1);
+
+ if (!t) {
+ return luaL_error(L, "invalid arguments");
+ }
+
+ gsize outlen;
+ char *transliterated = rspamd_utf8_transliterate(t->start, t->len, &outlen);
+ lua_new_text(L, transliterated, outlen, TRUE);
+
+ return 1;
+}
+
static gint
lua_util_strequal_caseless (lua_State *L)
{
More information about the Commits
mailing list