split has default behaviour with no delimiter present
This commit is contained in:
1 parent
020866c0e9
commit
183dd0293b
3 files changed
+27
-9
No files matched your search
@@ -1579,12 +1579,14 @@ join('-','foo') => foo
|
||||
join('-', 'foo', 'bar') => foo-bar
|
||||
</pre>
|
||||
|
||||
### `split(delim, expr)`
|
||||
### `split(delim?, expr)`
|
||||
|
||||
Splits a string undr `expr` by `delim` which can be a regular expression
|
||||
Splits a string under `expr` by `delim` which can be a regular expression. If no delimiter is specified, it splits
|
||||
by characters.
|
||||
|
||||
<pre>
|
||||
split('',foo) => [f, o, o]
|
||||
split('foo') => [f, o, o]
|
||||
split('','foo') => [f, o, o]
|
||||
split('.','foo.bar') => []
|
||||
split('\\.','foo.bar') => [foo, bar]
|
||||
</pre>
|
||||
|
||||
@@ -155,12 +155,14 @@ join('-','foo') => foo
|
||||
join('-', 'foo', 'bar') => foo-bar
|
||||
</pre>
|
||||
|
||||
### `split(delim, expr)`
|
||||
### `split(delim?, expr)`
|
||||
|
||||
Splits a string undr `expr` by `delim` which can be a regular expression
|
||||
Splits a string under `expr` by `delim` which can be a regular expression. If no delimiter is specified, it splits
|
||||
by characters.
|
||||
|
||||
<pre>
|
||||
split('',foo) => [f, o, o]
|
||||
split('foo') => [f, o, o]
|
||||
split('','foo') => [f, o, o]
|
||||
split('.','foo.bar') => []
|
||||
split('\\.','foo.bar') => [foo, bar]
|
||||
</pre>
|
||||
|
||||
@@ -52,10 +52,24 @@ public class DataStructures {
|
||||
return new StringValue(toJoin.stream().map(Value::getString).collect(Collectors.joining(delimiter)));
|
||||
});
|
||||
|
||||
expression.addBinaryFunction("split", (d, v) ->
|
||||
expression.addFunction("split", (lv) ->
|
||||
{
|
||||
String delimiter = d.getString();
|
||||
String hwat = v.getString();
|
||||
String delimiter;
|
||||
String hwat;
|
||||
if (lv.size() == 1)
|
||||
{
|
||||
hwat = lv.get(0).getString();
|
||||
delimiter = "";
|
||||
}
|
||||
else if (lv.size() == 2)
|
||||
{
|
||||
delimiter = lv.get(0).getString();
|
||||
hwat = lv.get(1).getString();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InternalExpressionException("'split' takes 1 or 2 arguments");
|
||||
}
|
||||
try
|
||||
{
|
||||
return ListValue.wrap(Arrays.stream(hwat.split(delimiter)).map(StringValue::new).collect(Collectors.toList()));
|
||||
|
||||
Reference in new issue
Block a user