MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / strWithCursor

Function strWithCursor

pkg/util/utilfn/utilfn.go:228–251  ·  view source on GitHub ↗
(str string, pos int)

Source from the content-addressed store, hash-verified

226}
227
228func strWithCursor(str string, pos int) string {
229 if pos == NoStrPos {
230 return str
231 }
232 if pos < 0 {
233 // invalid position
234 return "[*]_" + str
235 }
236 if pos > len(str) {
237 // invalid position
238 return str + "_[*]"
239 }
240 if pos == len(str) {
241 return str + "[*]"
242 }
243 var rtn []rune
244 for _, ch := range str {
245 if len(rtn) == pos {
246 rtn = append(rtn, '[', '*', ']')
247 }
248 rtn = append(rtn, ch)
249 }
250 return string(rtn)
251}
252
253func (sp StrWithPos) Prepend(str string) StrWithPos {
254 return StrWithPos{Str: str + sp.Str, Pos: utf8.RuneCountInString(str) + sp.Pos}

Callers 1

StringMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected