On Mon, 11 Apr 2022 09:51:12 GMT, Prasanta Sadhukhan <psadhuk...@openjdk.org> 
wrote:

> > > I guess in that case "else" part in l359 will be executed...I was talking 
> > > about requirement of "else" part in l345
> > 
> > 
> > I did a sample test for this case, it did entered l345, I added \n manually 
> > at the end of string, since it passes `if (array[counter] == '\n') {` 
> > (l340) condition and fails `if (array[counter - 1] == '\r')` (l342), it 
> > executes the else part in l345.....
> 
> If you manually add \n to end of string, then as per your previous 
> statements, this code block should have `\n\r\n` and then `\n` , right? Then, 
> I guess user would expect one new line because he manually added \n, but as 
> per your observation, the "else" part is executed so wouldn't 
> `out.write(array, last, counter - last);` write the full \n\r\n\n again, ie 3 
> new lines?

I admit I got lost in the discussion.

If I understand correctly, the text model removes `\r` from `\r\n` when reading 
text files. In the `Document` model, `\n` represents the end of the line.

The user explicitly added a text with Windows line end into the text model. 
When such a text is written out on Windows, an extra `\r` gets added. Then when 
this text is read in, the `\r` which is not followed by `\n` gets converted to 
`\n` which results in a new line break.

The `else` block is needed, and it's the most common branch. The text model 
doesn't contain `\r` (should not contain). When the text is written out on 
Windows, line ends of `\n` are converted to `\r\n`.

-------------

PR: https://git.openjdk.java.net/jdk/pull/8122

Reply via email to