Handles scenarios where lines might not end with a newline at the end of the file. Fixes #49.

This commit is contained in:
Ryan McGrath 2013-05-03 16:18:16 -04:00
parent 9d8a81592f
commit f8ed81ad5a

View file

@ -411,13 +411,13 @@ exports.LineReader.prototype = {
if(this.currentPosition === -1) return false; if(this.currentPosition === -1) return false;
} }
if(this.buffer.indexOf("\n") > -1) return true; if(this.buffer.indexOf("\n") > -1 || this.buffer.length !== 0) return true;
return false; return false;
}, },
getNextLine: function() { getNextLine: function() {
var lineEnd = this.buffer.indexOf("\n"), var lineEnd = this.buffer.indexOf("\n"),
result = this.buffer.substring(0, lineEnd); result = this.buffer.substring(0, lineEnd ? lineEnd : this.buffer.length);
this.buffer = this.buffer.substring(result.length + 1, this.buffer.length); this.buffer = this.buffer.substring(result.length + 1, this.buffer.length);
return result; return result;