OpenSDE Packages Database (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.6 KiB

  1. # --- T2-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # T2 SDE: package/.../lua/string-split.patch
  5. # Copyright (C) 2006 The T2 SDE Project
  6. #
  7. # More information can be found in the files COPYING and README.
  8. #
  9. # This patch file is dual-licensed. It is available under the license the
  10. # patched project is licensed under, as long as it is an OpenSource license
  11. # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
  12. # of the GNU General Public License as published by the Free Software
  13. # Foundation; either version 2 of the License, or (at your option) any later
  14. # version.
  15. # --- T2-COPYRIGHT-NOTE-END ---
  16. --- lua-5.1/src/lstrlib.c.orig 2006-03-08 16:50:15.000000000 +0100
  17. +++ lua-5.1/src/lstrlib.c 2006-03-08 16:52:44.000000000 +0100
  18. @@ -815,6 +815,33 @@
  19. return 1;
  20. }
  21. +static int str_split (lua_State *L) {
  22. + size_t slen;
  23. + const char *s = luaL_checklstring(L, 1, &slen);
  24. + size_t seplen;
  25. + const char *sep = luaL_optlstring(L, 2, " \t\n\r\v\f", &seplen);
  26. +
  27. + size_t pos,p,i;
  28. + size_t t=1;
  29. +
  30. + lua_newtable(L);
  31. +
  32. + /* loop over string */
  33. + for(pos=0,p=0; p<slen; p++) {
  34. + /* loop over seperators */
  35. + for(i=0; i<seplen; i++) {
  36. + if (s[p] == sep[i]) {
  37. + if (pos-p > 1) { /* FIXME really skip empty elements? */
  38. + lua_pushlstring(L, s+pos, p-pos);
  39. + lua_rawseti(L, -2, t++);
  40. + }
  41. + pos = p+1;
  42. + }
  43. + }
  44. + }
  45. +
  46. + return 1;
  47. +}
  48. static const luaL_Reg strlib[] = {
  49. {"byte", str_byte},
  50. @@ -832,6 +859,7 @@
  51. {"reverse", str_reverse},
  52. {"sub", str_sub},
  53. {"upper", str_upper},
  54. + {"split", str_split},
  55. {NULL, NULL}
  56. };