# --- T2-COPYRIGHT-NOTE-BEGIN ---
|
|
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
|
|
#
|
|
# T2 SDE: package/.../lua/string-split.patch
|
|
# Copyright (C) 2006 The T2 SDE Project
|
|
#
|
|
# More information can be found in the files COPYING and README.
|
|
#
|
|
# This patch file is dual-licensed. It is available under the license the
|
|
# patched project is licensed under, as long as it is an OpenSource license
|
|
# as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
|
|
# of the GNU General Public License as published by the Free Software
|
|
# Foundation; either version 2 of the License, or (at your option) any later
|
|
# version.
|
|
# --- T2-COPYRIGHT-NOTE-END ---
|
|
|
|
--- lua-5.1/src/lstrlib.c.orig 2006-03-08 16:50:15.000000000 +0100
|
|
+++ lua-5.1/src/lstrlib.c 2006-03-08 16:52:44.000000000 +0100
|
|
@@ -815,6 +815,33 @@
|
|
return 1;
|
|
}
|
|
|
|
+static int str_split (lua_State *L) {
|
|
+ size_t slen;
|
|
+ const char *s = luaL_checklstring(L, 1, &slen);
|
|
+ size_t seplen;
|
|
+ const char *sep = luaL_optlstring(L, 2, " \t\n\r\v\f", &seplen);
|
|
+
|
|
+ size_t pos,p,i;
|
|
+ size_t t=1;
|
|
+
|
|
+ lua_newtable(L);
|
|
+
|
|
+ /* loop over string */
|
|
+ for(pos=0,p=0; p<slen; p++) {
|
|
+ /* loop over seperators */
|
|
+ for(i=0; i<seplen; i++) {
|
|
+ if (s[p] == sep[i]) {
|
|
+ if (pos-p > 1) { /* FIXME really skip empty elements? */
|
|
+ lua_pushlstring(L, s+pos, p-pos);
|
|
+ lua_rawseti(L, -2, t++);
|
|
+ }
|
|
+ pos = p+1;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ return 1;
|
|
+}
|
|
|
|
static const luaL_Reg strlib[] = {
|
|
{"byte", str_byte},
|
|
@@ -832,6 +859,7 @@
|
|
{"reverse", str_reverse},
|
|
{"sub", str_sub},
|
|
{"upper", str_upper},
|
|
+ {"split", str_split},
|
|
{NULL, NULL}
|
|
};
|
|
|