Skip to content

Commit

Permalink
Unicode index() now considers the last character. Fixes dop251#59.
Browse files Browse the repository at this point in the history
  • Loading branch information
dop251 committed Jan 2, 2018
1 parent f24d0f0 commit 034fb74
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
6 changes: 2 additions & 4 deletions runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,10 @@ func TestIndexOf(t *testing.T) {

func TestUnicodeIndexOf(t *testing.T) {
const SCRIPT = `
"абвгд".indexOf("вг", 1)
"абвгд".indexOf("вг", 1) === 2 && '中国'.indexOf('国') === 1
`

testScript1(SCRIPT, intToValue(2), t)
testScript1(SCRIPT, valueTrue, t)
}

func TestLastIndexOf(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion string_unicode.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func (s unicodeString) index(substr valueString, start int64) int64 {

// TODO: optimise
end := int64(len(s) - len(ss))
for start < end {
for start <= end {
for i := int64(0); i < int64(len(ss)); i++ {
if s[start+i] != ss[i] {
goto nomatch
Expand Down

0 comments on commit 034fb74

Please sign in to comment.