Re: [EventSource] feedback from implementors

On Fri, 18 Sep 2009 11:37:24 -0400, Per-Erik Brodin  
<> wrote:

> When parsing an event stream, allowing carriage return, carriage return
> line feed, and line feed to denote line endings introduces unnecessary
> ambiguity into the spec. For example, the sequence "\r\r\n\n" could be
> interpreted as three or four line endings.

That would always be 3 lines: a mac, a windows and a nix. "\n\r\n\r" would  
be the reverse order, but still 3.

Universal newline normalization for input with mixed newline formats:

// normalize newlines to \n
.replace(/\r\n|\r/g, "\n");

// normalize newlines to \r\n
.replace(/\r\n|r|\n/g, "\r\n");

// normalize newlines to \r
.replace(/\r\n|\n/g, "\r");

Ideally, I think it's often best to do the first to normalize to \n for  
processing (like if you need to know line count) and then normalize to a  
different format *if needed* afterwards.



Received on Saturday, 19 September 2009 16:44:21 UTC