fix: use rune for length over string

This commit is contained in:
Jayme Bird 2022-10-21 09:06:10 +01:00 committed by Dave Cunningham
parent 03df4dc6e9
commit 3aab052ecc
4 changed files with 4 additions and 4 deletions

View File

@ -1179,7 +1179,7 @@ func builtinSubstr(i *interpreter, inputStr, inputFrom, inputLen value) (value,
} }
fromInt := int(fromV.value) fromInt := int(fromV.value)
strStr := strV.getGoString() strStr := strV.getRunes()
endIndex := fromInt + lenInt endIndex := fromInt + lenInt
@ -1190,9 +1190,7 @@ func builtinSubstr(i *interpreter, inputStr, inputFrom, inputLen value) (value,
if fromInt > len(strStr) { if fromInt > len(strStr) {
return makeValueString(""), nil return makeValueString(""), nil
} }
return makeValueString(string(strStr[fromInt:endIndex])), nil
runes := []rune(strStr)
return makeValueString(string(runes[fromInt:endIndex])), nil
} }
func builtinSplitLimit(i *interpreter, strv, cv, maxSplitsV value) (value, error) { func builtinSplitLimit(i *interpreter, strv, cv, maxSplitsV value) (value, error) {

View File

@ -0,0 +1 @@
"🤩"

View File

@ -0,0 +1 @@
std.substr("🤩", 0, 5)

View File