From 9af31e5c7840e276a65f5a4b341c88831eb9ab97 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Tue, 25 Jun 2013 10:54:09 +0000 Subject: testing/lua5.2-stringy: new aport Lua string utility library https://code.google.com/p/bpbio/downloads/list --- testing/lua5.2-stringy/stringy-memcmp.patch | 64 +++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 testing/lua5.2-stringy/stringy-memcmp.patch (limited to 'testing/lua5.2-stringy/stringy-memcmp.patch') diff --git a/testing/lua5.2-stringy/stringy-memcmp.patch b/testing/lua5.2-stringy/stringy-memcmp.patch new file mode 100644 index 0000000000..d9019b79cc --- /dev/null +++ b/testing/lua5.2-stringy/stringy-memcmp.patch @@ -0,0 +1,64 @@ +--- ./stringy.c.orig ++++ ./stringy.c +@@ -8,49 +8,27 @@ + + + static int endswith(lua_State *L) { +- const char *string = luaL_checkstring(L, 1); +- int string_len = lua_objlen(L, 1); ++ size_t string_len, token_len; ++ const char *string = luaL_checklstring(L, 1, &string_len); ++ const char *token = luaL_checklstring(L, 2, &token_len); ++ int end = 0; + +- const char *token = luaL_checkstring(L, 2); +- int token_len = lua_objlen(L, 2); +- +- int ti = token_len, si = string_len, end = 1; + if(token_len <= string_len){ +- while(ti > 0) { +- if(string[--si] != token[--ti]){ +- end = 0; +- break; +- +- } +- } ++ string += string_len - token_len; ++ end = memcmp(string, token, token_len) == 0; + } +- else { +- end = 0; +- } + lua_pushboolean(L, end); + return 1; + } + + static int startswith(lua_State *L) { +- const char *string = luaL_checkstring(L, 1); +- int string_len = lua_objlen(L, 1); ++ size_t string_len, token_len; ++ const char *string = luaL_checklstring(L, 1, &string_len); ++ const char *token = luaL_checklstring(L, 2, &token_len); ++ int start = 0; + +- const char *token = luaL_checkstring(L, 2); +- int token_len = lua_objlen(L, 2); +- int i, start = 1; +- // please make this less ugly... +- if(token_len <= string_len){ +- while(i < token_len) { +- if(string[i] != token[i]){ +- start = 0; +- break; +- } +- i++; +- } +- } +- else { +- start = 0; +- } ++ if(token_len <= string_len) ++ start = memcmp(string, token, token_len) == 0; + lua_pushboolean(L, start); + return 1; + } -- cgit v1.2.3