mirror of
https://github.com/apple/pkl.git
synced 2026-01-11 22:30:54 +01: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:
@@ -1367,6 +1367,21 @@ external class String extends Any {
|
||||
/// Splits this string around matches of [pattern].
|
||||
external function split(pattern: String|Regex): List<String>
|
||||
|
||||
/// Splits this string matches of [pattern], up to [limit] substrings.
|
||||
///
|
||||
/// Returns a [List] with at most [limit] elements.
|
||||
/// If the limit has been reached, the last entry will contain the un-split remainder of this string.
|
||||
///
|
||||
/// Facts:
|
||||
/// ```
|
||||
/// "a.b.c".splitLimit(".", 2) == List("a", "b.c")
|
||||
/// "a.b.c".splitLimit(".", 1) == List("a.b.c")
|
||||
/// "a.b.c".splitLimit(".", 50) == List("a", "b", "c")
|
||||
/// "a.b:c".splitLimit(Regex("[.:]"), 3) == List("a", "b", "c")
|
||||
/// ```
|
||||
@Since { version = "0.27.0" }
|
||||
external function splitLimit(pattern: String|Regex, limit: Int(this > 0)): List<String>
|
||||
|
||||
/// Converts the first character of this string to title case.
|
||||
///
|
||||
/// Facts:
|
||||
|
||||
Reference in New Issue
Block a user