[Bug 16733] Drop 'endings'?

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

--- Comment #9 from Simon Pieters <simonp@opera.com> 2012-04-16 05:18:56 UTC ---
OK here's a stawman API, implemented in javascript:

function normalizeLineEndings(s, endings) {
  if (arguments.length == 1)
    endings = 'LF';
  endings = String(endings);
  s = String(s);
  if (endings != 'LF' && endings != 'CRLF' && endings != 'native') { // CR
intentionally not supported
    throw "SyntaxError";
  }
  if (endings == 'native') {
    endings = navigator.platform.substr(0, 3) == 'Win' ? 'CRLF' : 'LF';
  }
  var newline = '\n';
  if (endings == 'CRLF') {
    newline = '\r\n';
  }
  return s.replace(/\n|\r|\r\n/g, newline);
}

When writing a file with FileWriter wanting the file to open in Notepad on
Windows and whatever text editor that only works with LF on other OSes, you'd
use normalizeLineEndings(foo, 'native'). When reading a file with unknown
endings and want LF, you'd use normalizeLineEndings(bar).

I'm not sure why we should provide this convenience API in the platform,
though, rather than letting authors use the above javascript function.

-- 
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 Monday, 16 April 2012 05:19:01 UTC