> > > Wait, if we don't need to handle leading whitespaces (which we don't need
> > > AFAIK, although it might be nice), the logic is merely if (*line && *line
> > > != '[' && *line != '#') comment();, isn't it?
>
> > Yes, but I also think we shouldn't add # on empty lines or lines containing
> > only whitespaces.
>
> I could modify the code to use `sci_get_line()` and work on lines instead of
> individual characters, it just mens allocating/deallocating strings for each
> line (not that it matters much performance-wise though). Not sure which
> option is better here.
It doesn't matter, you don't have to switch to fetching lines to implement
either, my "code" was merely laying out my thoughts, not really a suggestion of
implementation *per se*.
And it's be easy enough to support all-whitespace lines if you really want to,
just do something like (again, this has *not* to be the actual implementation):
```c
for (line in document) { // see, pseudo-code :)
const char *p = line;
while (*p && isspace(*p))
p++;
if (! *p) continue; // empty line
if (*p == '[') continue; // section, leave it alone
if (*line == '#') continue; // already commented at column 0, leave it alone
comment(&line);
}
```
which, given you have all the info, simplifies to `if (*p && *p != '[' && *line
!= '#') comment()`.
--
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany/pull/3413#issuecomment-1465314070
You are receiving this because you are subscribed to this thread.
Message ID: <geany/geany/pull/3413/[email protected]>