| 226 | } |
| 227 | |
| 228 | func 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 | |
| 253 | func (sp StrWithPos) Prepend(str string) StrWithPos { |
| 254 | return StrWithPos{Str: str + sp.Str, Pos: utf8.RuneCountInString(str) + sp.Pos} |