Adds a count to string->list

master
sloum 2 years ago
parent b3aab85a01
commit 8e980584b0

@ -258,7 +258,7 @@ Implemented:
<li><code>(string-append [value...])</code>: <code>string</code></li>
<li><code>(string-format [format: string] [value...])</code>: <code>string</code> (replaces `{}`'s in string with successive values)</li>
<li><code>(string->number [string] [[base: number]])</code>: <code>number/#f</code> If a non-decimal base is supplied, the input string will be parsed as an integer and any flaoting point value will be floored. A valid base passed with a string that does not parse to a number will return <code>#f</code></li>
<li><code>(string->list [string] [[value]])</code>: <code>list</code> (splits the first string at each instance of value, cast as a string)</li>
<li><code>(string->list [string] [[split-point: value]] [[count: number]])</code>: <code>list</code> (splits the first string at each instance of value, cast as a string)</li>
<li><code>(string->md5 [string])</code>: <code>string</code></li>
<li><code>(string->sha256 [string])</code>: <code>string</code></li>
<li><code>(string-fields [string])</code>: <code>list</code></li>

@ -1311,7 +1311,19 @@ var stdLibrary = vars{
return exception("'string->list' could not convert the given split point to a string upon which to split")
}
}
sSlice := strings.SplitN(stringIn, splitPoint, -1)
count := -1
if len(a) > 2 {
num, ok := a[2].(number)
if !ok {
return exception("'string->list' expected a number as its third argument, but a non-number value was given")
}
if num < 1 {
count = -1
} else {
count = int(num)
}
}
sSlice := strings.SplitN(stringIn, splitPoint, count)
return StringSliceToExpressionSlice(sSlice).([]expression)
},
"regex-match?": func(a ...expression) expression {

Loading…
Cancel
Save