ParseCursorLocation turns a cursor location like 10:5 (LINE:COL) into a loc
(cursorPositions []string)
| 1293 | // ParseCursorLocation turns a cursor location like 10:5 (LINE:COL) |
| 1294 | // into a loc |
| 1295 | func ParseCursorLocation(cursorPositions []string) (Loc, error) { |
| 1296 | startpos := Loc{0, 0} |
| 1297 | var err error |
| 1298 | |
| 1299 | // if no positions are available exit early |
| 1300 | if cursorPositions == nil { |
| 1301 | return startpos, errors.New("No cursor positions were provided.") |
| 1302 | } |
| 1303 | |
| 1304 | startpos.Y, err = strconv.Atoi(cursorPositions[0]) |
| 1305 | startpos.Y-- |
| 1306 | if err == nil { |
| 1307 | if len(cursorPositions) > 1 { |
| 1308 | startpos.X, err = strconv.Atoi(cursorPositions[1]) |
| 1309 | if startpos.X > 0 { |
| 1310 | startpos.X-- |
| 1311 | } |
| 1312 | } |
| 1313 | } |
| 1314 | |
| 1315 | return startpos, err |
| 1316 | } |
| 1317 | |
| 1318 | // Line returns the string representation of the given line number |
| 1319 | func (b *Buffer) Line(i int) string { |
no outgoing calls
no test coverage detected