MCPcopy Create free account
hub / github.com/dop251/goja / lastIndex

Method lastIndex

string_unicode.go:531–560  ·  view source on GitHub ↗
(substr String, start int)

Source from the content-addressed store, hash-verified

529}
530
531func (s unicodeString) lastIndex(substr String, start int) int {
532 var ss []uint16
533 a, u := devirtualizeString(substr)
534 if u != nil {
535 ss = u[1:]
536 } else {
537 ss = make([]uint16, len(a))
538 for i := 0; i < len(a); i++ {
539 ss[i] = uint16(a[i])
540 }
541 }
542
543 s1 := s[1:]
544 if maxStart := len(s1) - len(ss); start > maxStart {
545 start = maxStart
546 }
547 // TODO: optimise
548 for start >= 0 {
549 for i := 0; i < len(ss); i++ {
550 if s1[start+i] != ss[i] {
551 goto nomatch
552 }
553 }
554
555 return start
556 nomatch:
557 start--
558 }
559 return -1
560}
561
562func unicodeStringFromRunes(r []rune) unicodeString {
563 return unistring.NewFromRunes(r).AsUtf16()

Callers

nothing calls this directly

Calls 1

devirtualizeStringFunction · 0.85

Tested by

no test coverage detected