From: Jason Hollingsworth Date: Thu, 25 Oct 2012 14:11:31 +0000 (-0500) Subject: Update to Fix Issue 162: Support DOS-style line endings. X-Git-Tag: v1.0.0~176^2~1 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=df268bccea10372766eab881216ab8e2f29458f8;p=dygraphs.git Update to Fix Issue 162: Support DOS-style line endings. IE8/IE7 does not support string iteration using [], this fix uses charAt. Also I added support for \r\n (CRLF), which is more common than \n\r (LFCR). It now supports all four --- diff --git a/dygraph-utils.js b/dygraph-utils.js index 200617c..04d2ae3 100644 --- a/dygraph-utils.js +++ b/dygraph-utils.js @@ -1082,17 +1082,25 @@ Dygraph.IFrameTarp.prototype.uncover = function() { }; /** - * Determine whether |data| is delimited by CR, LF or CRLF. + * Determine whether |data| is delimited by CR, CRLF, LF, LFCR. * @param {string} data * @return {string|null} the delimiter that was detected. */ Dygraph.detectLineDelimiter = function(data) { for (var i = 0; i < data.length; i++) { - var code = data[i]; - if (code == '\r') return code; - if (code == '\n') { + var code = data.charAt(i); + if (code === '\r') { + // Might actually be "\r\n". + if (((i + 1) < data.length) && (data.charAt(i + 1) === '\n')) { + return '\r\n'; + } + return code; + } + if (code === '\n') { // Might actually be "\n\r". - if (i < data.length && data[i + 1] == '\r') return '\n\r'; + if (((i + 1) < data.length) && (data.charAt(i + 1) === '\r')) { + return '\n\r'; + } return code; } }