(str, substr string, offset int64)
| 682 | } |
| 683 | |
| 684 | func lastIndexOfOffset(str, substr string, offset int64) (int64, error) { |
| 685 | off := int(offset) |
| 686 | if off < 0 { |
| 687 | return -1, fmt.Errorf("index out of range: %d", off) |
| 688 | } |
| 689 | runes := []rune(str) |
| 690 | if substr == "" { |
| 691 | // The empty string matches at the search offset, clamped to the end of the string. |
| 692 | if off > len(runes) { |
| 693 | return int64(len(runes)), nil |
| 694 | } |
| 695 | return offset, nil |
| 696 | } |
| 697 | subrunes := []rune(substr) |
| 698 | // If the offset is far greater than the length return -1 |
| 699 | if off >= len(runes) { |
| 700 | return -1, nil |
| 701 | } |
| 702 | if off > len(runes)-len(subrunes) { |
| 703 | off = len(runes) - len(subrunes) |
| 704 | } |
| 705 | for i := off; i >= 0; i-- { |
| 706 | found := true |
| 707 | for j := 0; j < len(subrunes); j++ { |
| 708 | if runes[i+j] != subrunes[j] { |
| 709 | found = false |
| 710 | break |
| 711 | } |
| 712 | } |
| 713 | if found { |
| 714 | return int64(i), nil |
| 715 | } |
| 716 | } |
| 717 | return -1, nil |
| 718 | } |
| 719 | |
| 720 | func lowerASCII(str string) (string, error) { |
| 721 | runes := []rune(str) |
no outgoing calls
no test coverage detected