MCPcopy Create free account
hub / github.com/dlclark/regexp2 / stringByteOffsets

Function stringByteOffsets

match.go:110–135  ·  view source on GitHub ↗
(s string)

Source from the content-addressed store, hash-verified

108}
109
110func stringByteOffsets(s string) []int {
111 var byteOffsets []int
112 runeIndex := 0
113 for strIdx, ch := range s {
114 if byteOffsets != nil {
115 byteOffsets[runeIndex] = strIdx
116 }
117 runeLen := utf8.RuneLen(ch)
118 if ch == utf8.RuneError {
119 _, runeLen = utf8.DecodeRuneInString(s[strIdx:])
120 }
121 if byteOffsets == nil && (strIdx != runeIndex || runeLen != 1) {
122 byteOffsets = make([]int, len(s)+1)
123 for i := 0; i < runeIndex; i++ {
124 byteOffsets[i] = i
125 }
126 byteOffsets[runeIndex] = strIdx
127 }
128 runeIndex++
129 }
130 if byteOffsets != nil {
131 byteOffsets[runeIndex] = len(s)
132 return byteOffsets[:runeIndex+1]
133 }
134 return nil
135}
136
137func runeByteOffsets(runes []rune) []int {
138 var byteOffsets []int

Callers 1

buildByteOffsetsMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected