Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

Commit

Permalink
internal: rename rowDelimiterLength to rowDelimiterMaxLength
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Oct 5, 2018
1 parent 875fb69 commit 391b708
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,10 @@

# Changelog

## Trunk

* internal: rename rowDelimiterLength to rowDelimiterMaxLength

## Version 3.1.2

* readme: fix links to project website
Expand Down
9 changes: 4 additions & 5 deletions lib/es5/index.js
Expand Up @@ -279,7 +279,7 @@ Parser = function Parser() {
chunks: [],
rawBuf: '',
buf: '',
rowDelimiterLength: this.options.rowDelimiter ? Math.max.apply(Math, _toConsumableArray(this.options.rowDelimiter.map(function (v) {
rowDelimiterMaxLength: this.options.rowDelimiter ? Math.max.apply(Math, _toConsumableArray(this.options.rowDelimiter.map(function (v) {
return v.length;
}))) : void 0,
lineHasError: false,
Expand Down Expand Up @@ -421,7 +421,6 @@ Parser.prototype.__push = function (line) {
columnName = this.options.columns[i];

if (columnName === void 0 || columnName === null || columnName === false) {
// console.log('columnName', columnName)
continue;
}

Expand Down Expand Up @@ -554,9 +553,9 @@ Parser.prototype.__write = function (chars, end) {
// Skip if the remaining buffer can be comment
// Skip if the remaining buffer can be row delimiter

if (!this.options.rowDelimiter && i + 3 > l || !this._.commenting && l - i < this.options.comment.length && this.options.comment.substr(0, l - i) === remainingBuffer || this.options.rowDelimiter && l - i < this._.rowDelimiterLength && this.options.rowDelimiter.some(function (rd) {
if (!this.options.rowDelimiter && i + 3 > l || !this._.commenting && l - i < this.options.comment.length && this.options.comment.substr(0, l - i) === remainingBuffer || this.options.rowDelimiter && l - i < this._.rowDelimiterMaxLength && this.options.rowDelimiter.some(function (rd) {
return rd.substr(0, l - i) === remainingBuffer; // Skip if the remaining buffer can be row delimiter following the closing quote
}) || this.options.rowDelimiter && this._.quoting && l - i < this.options.quote.length + this._.rowDelimiterLength && this.options.rowDelimiter.some(function (rd) {
}) || this.options.rowDelimiter && this._.quoting && l - i < this.options.quote.length + this._.rowDelimiterMaxLength && this.options.rowDelimiter.some(function (rd) {
return (_this2.options.quote + rd).substr(0, l - i) === remainingBuffer; // Skip if the remaining buffer can be delimiter
// Skip if the remaining buffer can be escape sequence
}) || l - i <= this.options.delimiter.length && this.options.delimiter.substr(0, l - i) === remainingBuffer || l - i <= this.options.escape.length && this.options.escape.substr(0, l - i) === remainingBuffer) {
Expand Down Expand Up @@ -590,7 +589,7 @@ Parser.prototype.__write = function (chars, end) {
}

this.options.rowDelimiter = [rowDelimiter];
this._.rowDelimiterLength = rowDelimiter.length;
this._.rowDelimiterMaxLength = rowDelimiter.length;
}
} // Parse that damn char
// Note, shouldn't we have sth like chars.substr(i, @options.escape.length)
Expand Down
9 changes: 4 additions & 5 deletions lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions src/index.coffee.md
Expand Up @@ -135,7 +135,7 @@ Options are documented [here](http://csv.js.org/parse/options/).
chunks: []
rawBuf: ''
buf: ''
rowDelimiterLength: Math.max(@options.rowDelimiter.map( (v) -> v.length)...) if @options.rowDelimiter
rowDelimiterMaxLength: Math.max(@options.rowDelimiter.map( (v) -> v.length)...) if @options.rowDelimiter
lineHasError: false
isEnded: false
@
Expand Down Expand Up @@ -224,7 +224,6 @@ Implementation of the [`stream.Transform` API](https://nodejs.org/api/stream.htm
lineAsColumns = {}
for field, i in line
columnName = @options.columns[i]
# console.log('columnName', columnName)
continue if columnName is undefined or columnName is null or columnName is false
throw Error "Invalid column name #{JSON.stringify columnName}" if typeof columnName isnt 'string'
lineAsColumns[columnName] = field
Expand Down Expand Up @@ -293,9 +292,9 @@ Implementation of the [`stream.Transform` API](https://nodejs.org/api/stream.htm
# Skip if the remaining buffer can be comment
(not @_.commenting and l - i < @options.comment.length and @options.comment.substr(0, l - i) is remainingBuffer) or
# Skip if the remaining buffer can be row delimiter
(@options.rowDelimiter and l - i < @_.rowDelimiterLength and @options.rowDelimiter.some( (rd) -> rd.substr(0, l - i) is remainingBuffer)) or
(@options.rowDelimiter and l - i < @_.rowDelimiterMaxLength and @options.rowDelimiter.some( (rd) -> rd.substr(0, l - i) is remainingBuffer)) or
# Skip if the remaining buffer can be row delimiter following the closing quote
(@options.rowDelimiter and @_.quoting and l - i < (@options.quote.length + @_.rowDelimiterLength) and @options.rowDelimiter.some((rd) => (@options.quote + rd).substr(0, l - i) is remainingBuffer)) or
(@options.rowDelimiter and @_.quoting and l - i < (@options.quote.length + @_.rowDelimiterMaxLength) and @options.rowDelimiter.some((rd) => (@options.quote + rd).substr(0, l - i) is remainingBuffer)) or
# Skip if the remaining buffer can be delimiter
(l - i <= @options.delimiter.length and @options.delimiter.substr(0, l - i) is remainingBuffer) or
# Skip if the remaining buffer can be escape sequence
Expand All @@ -318,7 +317,7 @@ Implementation of the [`stream.Transform` API](https://nodejs.org/api/stream.htm
if rowDelimiter
rowDelimiter += '\n' if rowDelimiter is '\r' and chars.charAt(nextCharPos) is '\n'
@options.rowDelimiter = [rowDelimiter]
@_.rowDelimiterLength = rowDelimiter.length
@_.rowDelimiterMaxLength = rowDelimiter.length
# Parse that damn char
# Note, shouldn't we have sth like chars.substr(i, @options.escape.length)
if not @_.commenting and char is @options.escape
Expand Down

0 comments on commit 391b708

Please sign in to comment.