From df268bccea10372766eab881216ab8e2f29458f8 Mon Sep 17 00:00:00 2001 From: Jason Hollingsworth Date: Thu, 25 Oct 2012 09:11:31 -0500 Subject: [PATCH] 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 --- dygraph-utils.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) 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; } } -- 2.7.4