[Bug 19003] Bugs in toNativeLineEndings()

https://www.w3.org/Bugs/Public/show_bug.cgi?id=19003

Glenn Maynard <glenn@zewt.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |glenn@zewt.org

--- Comment #1 from Glenn Maynard <glenn@zewt.org> 2012-09-25 15:09:44 UTC ---
Yeah, that's what I meant in
https://www.w3.org/Bugs/Public/show_bug.cgi?id=16733#c21: convert the line
endings in a string.

> 3. Let /lines/ be an empty array.
> 4. While /position/ is not past the end of /input/:
>     1. Collect a sequence of characters that are not U+000A or U+000D.
>     2. Add the string collected in the previous step to /lines/.
>     3. If the character at /position/ is U+000D, and the character at
> /position/+1 is U+000A, advance /position/ by two characters. Otherwise,
> advance /position/ to the next character.
> 6. Let /output/ be the result of joining /lines/ with /native line ending/.

This doesn't seem quite right--an input of "\n" results in "" (instead of eg.
"\r\n"), because /lines/ becomes [""].  Also, "joining string with a string"
would need to be defined.

Maybe:

1. Let /position/ be a pointer into /string/, initially pointing at the start
of
the string.
2. Let /result/ be the empty string.
3. Let /native line ending/ be the character U+000A, or the character U+000D
followed by the character U+000A, as determined by the underlying platform's
conventions.
4. /Line loop/: Collect a sequence of characters that are not U+000A or U+000D.
5. Add the string collected in the previous step to /result/.
6. If the character at /position/ is past the end of /string/, return /result/.
7. Add /native line ending/ to /result/.
8. If the character at /position/ is U+000D, and the character at
/position/+1 is U+000A, advance /position/ by two characters.  Otherwise,
advance /position/ to the next character.
9. Jump back to the step labeled /line loop/ in these steps.

-- 
Configure bugmail: https://www.w3.org/Bugs/Public/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.

Received on Tuesday, 25 September 2012 15:10:09 UTC