changeset 1195:9a57f0b16c2b

better String.split
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 26 Feb 2018 19:07:49 -0700
parents bd0420fb3dd0
children 44491798e431
files conv.txt src/luan/modules/StringLuan.java website/src/manual.html.luan
diffstat 3 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/conv.txt	Mon Feb 26 16:29:07 2018 -0700
+++ b/conv.txt	Mon Feb 26 19:07:49 2018 -0700
@@ -10,3 +10,4 @@
 "assert"
 
 "Io.repr"
+"String.split"
--- a/src/luan/modules/StringLuan.java	Mon Feb 26 16:29:07 2018 -0700
+++ b/src/luan/modules/StringLuan.java	Mon Feb 26 19:07:49 2018 -0700
@@ -239,9 +239,10 @@
 		return Pattern.compile(pattern).matcher(s).find();
 	}
 
-	public static LuanTable split(String s,String pattern) throws LuanException {
+	@LuanMethod public static String[] split(String s,String pattern,Integer limit) throws LuanException {
 		Utils.checkNotNull(s);
-		return new LuanTable(Arrays.asList(s.split(pattern)));
+		int n = limit==null ? -1 : limit;
+		return s.split(pattern,n);
 	}
 
 }
--- a/website/src/manual.html.luan	Mon Feb 26 16:29:07 2018 -0700
+++ b/website/src/manual.html.luan	Mon Feb 26 19:07:49 2018 -0700
@@ -2494,6 +2494,12 @@
 
 
 
+<h4 heading><a name="String.split" href="#String.match"><code>String.split (s, pattern [, limit])</code></a></h4>
+
+<p>
+Splits <code>s</code> using regex <code>pattern</code> and returns the results.  If <code>limit</code> is positive, then only returns at most that many results.  If <code>limit</code> is zero, then remove trailing empty results.
+
+
 
 <h4 heading><a name="String.sub" href="#String.sub"><code>String.sub (s, i [, j])</code></a></h4>