mirror of
https://github.com/apple/pkl.git
synced 2026-04-18 22:50:01 +02:00
Add String.splitLimit API (#666)
* Add String.splitLimit API * Update stdlib/base.pkl Co-authored-by: Daniel Chao <daniel.h.chao@gmail.com> --------- Co-authored-by: Daniel Chao <daniel.h.chao@gmail.com>
This commit is contained in:
@@ -739,6 +739,22 @@ public final class StringNodes {
|
||||
}
|
||||
}
|
||||
|
||||
public abstract static class splitLimit extends ExternalMethod2Node {
|
||||
@TruffleBoundary
|
||||
@Specialization
|
||||
protected VmList eval(String self, String separator, long limit) {
|
||||
var parts = self.split(Pattern.quote(separator), (int) limit);
|
||||
return VmList.create(parts);
|
||||
}
|
||||
|
||||
@TruffleBoundary
|
||||
@Specialization
|
||||
protected VmList eval(String self, VmRegex separator, long limit) {
|
||||
var parts = separator.getPattern().split(self, (int) limit);
|
||||
return VmList.create(parts);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract static class capitalize extends ExternalMethod0Node {
|
||||
@TruffleBoundary
|
||||
@Specialization
|
||||
|
||||
Reference in New Issue
Block a user