| 22 | } |
| 23 | |
| 24 | func LineNumber(source string, head int) (int, int) { |
| 25 | // Calculate the true line and column number for a query, ignoring spaces |
| 26 | var comment bool |
| 27 | var loc, line, col int |
| 28 | for i, char := range source { |
| 29 | loc += 1 |
| 30 | col += 1 |
| 31 | // TODO: Check bounds |
| 32 | if char == '-' && source[i+1] == '-' { |
| 33 | comment = true |
| 34 | } |
| 35 | if char == '\n' { |
| 36 | comment = false |
| 37 | line += 1 |
| 38 | col = 0 |
| 39 | } |
| 40 | if loc <= head { |
| 41 | continue |
| 42 | } |
| 43 | if unicode.IsSpace(char) { |
| 44 | continue |
| 45 | } |
| 46 | if comment { |
| 47 | continue |
| 48 | } |
| 49 | break |
| 50 | } |
| 51 | return line + 1, col |
| 52 | } |
| 53 | |
| 54 | func Pluck(source string, location, length int) (string, error) { |
| 55 | head := location |