Mercurial Hosting > luan
changeset 1719:2f3a8f16f583
add regex.split
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 25 Jul 2022 14:31:48 -0600 |
parents | 5603ee8e2a71 |
children | 2f4c99c02436 |
files | src/luan/modules/Boot.luan src/luan/modules/RegexLuan.java website/src/manual.html.luan |
diffstat | 3 files changed, 27 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
diff -r 5603ee8e2a71 -r 2f3a8f16f583 src/luan/modules/Boot.luan --- a/src/luan/modules/Boot.luan Mon Jul 25 11:32:05 2022 -0600 +++ b/src/luan/modules/Boot.luan Mon Jul 25 14:31:48 2022 -0600 @@ -59,6 +59,7 @@ match = regex.match matches = regex.matches set = regex.set + split = regex.split } end Boot.regex = regex
diff -r 5603ee8e2a71 -r 2f3a8f16f583 src/luan/modules/RegexLuan.java --- a/src/luan/modules/RegexLuan.java Mon Jul 25 11:32:05 2022 -0600 +++ b/src/luan/modules/RegexLuan.java Mon Jul 25 14:31:48 2022 -0600 @@ -144,4 +144,10 @@ public boolean matches(String s) { return pattern.matcher(s).find(); } + + public String[] split(String s,Integer limit) throws LuanException { + Utils.checkNotNull(s); + int n = limit==null ? -1 : limit; + return pattern.split(s,n); + } }
diff -r 5603ee8e2a71 -r 2f3a8f16f583 website/src/manual.html.luan --- a/website/src/manual.html.luan Mon Jul 25 11:32:05 2022 -0600 +++ b/website/src/manual.html.luan Mon Jul 25 14:31:48 2022 -0600 @@ -3032,6 +3032,26 @@ <% end } + ["regex.set"] = { + title = "<code>regex.set (pattern)</code>" + content = function() +%> +<p> +Changes the regex pattern to <code>pattern</code>. +</p> +<% + end + } + ["regex.split"] = { + title = "<code>regex.split (s [, limit])</code>" + content = function() +%> +<p> +Splits <code>s</code> using the regex 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. +</p> +<% + end + } } } binary_lib = {