MCPcopy Create free account
hub / github.com/cel-expr/cel-go / indexOfOffset

Function indexOfOffset

ext/strings.go:639–670  ·  view source on GitHub ↗
(str, substr string, offset int64)

Source from the content-addressed store, hash-verified

637}
638
639func indexOfOffset(str, substr string, offset int64) (int64, error) {
640 off := int(offset)
641 if off < 0 {
642 return -1, fmt.Errorf("index out of range: %d", off)
643 }
644 runes := []rune(str)
645 if substr == "" {
646 // The empty string matches at the search offset, clamped to the end of the string.
647 if off > len(runes) {
648 return int64(len(runes)), nil
649 }
650 return offset, nil
651 }
652 subrunes := []rune(substr)
653 // If the offset exceeds the length, return -1 rather than error.
654 if off >= len(runes) {
655 return -1, nil
656 }
657 for i := off; i < len(runes)-(len(subrunes)-1); i++ {
658 found := true
659 for j := 0; j < len(subrunes); j++ {
660 if runes[i+j] != subrunes[j] {
661 found = false
662 break
663 }
664 }
665 if found {
666 return int64(i), nil
667 }
668 }
669 return -1, nil
670}
671
672func lastIndexOf(str, substr string) (int64, error) {
673 runes := []rune(str)

Callers 2

CompileOptionsMethod · 0.85
indexOfFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected