Skip to content

Commit 034fb74

Browse files
committed
Unicode index() now considers the last character. Fixes dop251#59.
1 parent f24d0f0 commit 034fb74

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

runtime_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,10 @@ func TestIndexOf(t *testing.T) {
185185

186186
func TestUnicodeIndexOf(t *testing.T) {
187187
const SCRIPT = `
188-
189-
"абвгд".indexOf("вг", 1)
190-
188+
"абвгд".indexOf("вг", 1) === 2 && '中国'.indexOf('国') === 1
191189
`
192190

193-
testScript1(SCRIPT, intToValue(2), t)
191+
testScript1(SCRIPT, valueTrue, t)
194192
}
195193

196194
func TestLastIndexOf(t *testing.T) {

string_unicode.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ func (s unicodeString) index(substr valueString, start int64) int64 {
236236

237237
// TODO: optimise
238238
end := int64(len(s) - len(ss))
239-
for start < end {
239+
for start <= end {
240240
for i := int64(0); i < int64(len(ss)); i++ {
241241
if s[start+i] != ss[i] {
242242
goto nomatch

0 commit comments

Comments
 (0)