Bug: long strings with REALLY long delimiters…

classic Classic list List threaded Threaded
21 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: Bug: long strings with REALLY long delimiters…

Martin
On 12/15/18 12:33 AM, Andrew Gierth wrote:

>>>>>> "dyngeccetor8" == dyngeccetor8  <[hidden email]> writes:
>
>  >>> https://github.com/martin-eden/workshop/blob/master/formats/lua/quote_string/intact.lua#L16
>
>  dyngeccetor8> Sadly, link now points to current version.
>
> I don't think this is quite right for the case where the string starts
> with \r not followed by \n.
>
> According to the docs, long strings don't preserve the exact bytes of
> newline sequences, but they recognize any of \r, \n, \r\n, \n\r as being
> newlines. So if the string starts with \r alone, your code does not
> insert a \n, and the \r will be eaten when reading the string back in.
> If on the other hand you added a \n, then the \n\r would still be
> treated as a single newline, and it would still be eaten.
>

I agree. I'll handle this case in next commits. Thank you for discovering!

> I think what you need to do is: if the first character of the string is
> either \r or \n, then duplicate it.

Yes, it does the job but takes time to understand why exactly.

-- Martin

12