cgag / loc

Count lines of code quickly.
MIT License
2.31k stars 126 forks source link

Check for whitespaces between comments #31

Closed Ngo-The-Trung closed 7 years ago

Ngo-The-Trung commented 7 years ago

This correct counts lines such as

/* comment 1 */ /* comment 2 */

as comments

cgag commented 7 years ago

I commented in the issue, but as is, this has crashes because trimmed.nth(pos) is not equivalent to trimmed[pos], since pos is in bytes and nth is in characters. You can end up doing things like doing nth(pos) where pos is bigger than the number of chars in the string.

I implemented an equivalent in master. The larger issue of needing to handle whitespace here, and the general approach is correct though and I based my solution on it. Thanks again for the pr.