Browse Source

Unicode index() now considers the last character. Fixes #59.

Dmitry Panov 7 years ago
parent
commit
034fb74b51
2 changed files with 3 additions and 5 deletions
  1. 2 4
      runtime_test.go
  2. 1 1
      string_unicode.go

+ 2 - 4
runtime_test.go

@@ -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) {

+ 1 - 1
string_unicode.go

@@ -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