hasCodeBeforeOnLine checks if there are non-whitespace characters on the same line before the given byte index. Used to determine if a comment is inline.
(idx int)
| 1813 | // hasCodeBeforeOnLine checks if there are non-whitespace characters on the same |
| 1814 | // line before the given byte index. Used to determine if a comment is inline. |
| 1815 | func (t *Tokenizer) hasCodeBeforeOnLine(idx int) bool { |
| 1816 | // Find the start of the line containing idx |
| 1817 | lineStart := 0 |
| 1818 | for i := len(t.lineStarts) - 1; i >= 0; i-- { |
| 1819 | if t.lineStarts[i] <= idx { |
| 1820 | lineStart = t.lineStarts[i] |
| 1821 | break |
| 1822 | } |
| 1823 | } |
| 1824 | // Check for non-whitespace between lineStart and idx |
| 1825 | for i := lineStart; i < idx && i < len(t.input); i++ { |
| 1826 | if t.input[i] != ' ' && t.input[i] != '\t' && t.input[i] != '\r' { |
| 1827 | return true |
| 1828 | } |
| 1829 | } |
| 1830 | return false |
| 1831 | } |