В письме от 8 июня 2017 19:56:02 пользователь Fabien COELHO написал:
> > So this should be fixed in both expr_scanner_get_substring cases, and keep
> > last symbol only if it is not "\n".
>
> Indeed, this is a mess. The code assumes all stuff is a line ending with
> '\n', but this is not always the case.
>
> Here is a v7 which chomps the final newline only if there is one.
Sorry, but I still have problems with new solution...
First is function name. "expr_scanner_get_line" does not deal with any line at
all... it gets substring and "chomps" it.
As for me, I would do expr_scanner_chomp_substring(PsqlScanState, int, int&);
that changes end_offset as desired... And use it instead of end_offset =
expr_scanner_offset(sstate) - 1;
The second issue: you are removing all trailing \n and \r. I think you should
remove only one \n at the end of the string, and one \r before \n if there was
one.
I do not think there will be any practical difference between my and yours
solutions here, but mine is more neat, I think... I do not have enough
imagination to think about if "\n\r\r\r\r\r\n" case can happen, and what will
happen of we remove them all... So I suggest to remove only the last one.
--
Do code for fun. Can do it for money (Perl & C/C++ ~10h/week)