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

Commit

Permalink
rtrim: accept tab
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Dec 7, 2018
1 parent c7c68af commit 7487424
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,12 @@

# Changelog

## Trunk

Fix:

* rtrim: accept tab

## Version 4.1.0

New features:
Expand Down
15 changes: 10 additions & 5 deletions lib/es5/index.js
Expand Up @@ -69,6 +69,7 @@ var default_options = {
var cr = 13;
var nl = 10;
var space = 32;
var tab = 9;

var Parser =
/*#__PURE__*/
Expand Down Expand Up @@ -262,7 +263,8 @@ function (_Transform) {
wasRowDelimiter: false
};
return _this;
}
} // Implementation of `Transform._transform`


_createClass(Parser, [{
key: "_transform",
Expand All @@ -278,7 +280,8 @@ function (_Transform) {
}

callback(err);
}
} // Implementation of `Transform._flush`

}, {
key: "_flush",
value: function _flush(callback) {
Expand All @@ -289,7 +292,8 @@ function (_Transform) {
var err = this.__parse(undefined, true);

callback(err);
}
} // Central parser implementation

}, {
key: "__parse",
value: function __parse(nextBuf, end) {
Expand Down Expand Up @@ -561,11 +565,12 @@ function (_Transform) {
this.info.lines++;
this.state.wasRowDelimiter = false;
}
}
} // Helper to test if a character is a space or a line delimiter

}, {
key: "__isCharTrimable",
value: function __isCharTrimable(chr) {
return chr === space || chr === cr || chr === nl;
return chr === space || chr === tab || chr === cr || chr === nl;
}
}, {
key: "__onRow",
Expand Down
7 changes: 6 additions & 1 deletion lib/index.js
Expand Up @@ -29,6 +29,7 @@ const default_options = {
const cr = 13
const nl = 10
const space = 32
const tab = 9

class Parser extends Transform {
constructor(opts = {}){
Expand Down Expand Up @@ -188,6 +189,7 @@ class Parser extends Transform {
wasRowDelimiter: false
}
}
// Implementation of `Transform._transform`
_transform(buf, encoding, callback){
if(this.state.stop === true){
return
Expand All @@ -198,13 +200,15 @@ class Parser extends Transform {
}
callback(err)
}
// Implementation of `Transform._flush`
_flush(callback){
if(this.state.stop === true){
return
}
const err = this.__parse(undefined, true)
callback(err)
}
// Central parser implementation
__parse(nextBuf, end){
const {comment, escape, from, from_line, info, ltrim, max_record_size, quote, raw, relax, rtrim, skip_empty_lines, to, to_line} = this.options
let {record_delimiter} = this.options
Expand Down Expand Up @@ -411,8 +415,9 @@ class Parser extends Transform {
this.state.wasRowDelimiter = false
}
}
// Helper to test if a character is a space or a line delimiter
__isCharTrimable(chr){
return chr === space || chr === cr || chr === nl
return chr === space || chr === tab || chr === cr || chr === nl
}
__onRow(){
const {columns, info, from, relax_column_count, raw, skip_lines_with_empty_values} = this.options
Expand Down
11 changes: 11 additions & 0 deletions test/option.rtrim.coffee
Expand Up @@ -45,6 +45,17 @@ describe 'Option `rtrim`', ->
parser.write chr for chr in data
parser.end()

it 'with tags around quotes', (next) ->
data = '''
"a\tb\t"\t\t\t,"c\td\t\t\t"\t
"e\tf\t"\t,"g\th\t\t\t"\t\t\t
'''
parser = parse rtrim: true, (err, data) ->
data.should.eql [['a\tb\t', 'c\td\t\t\t'],['e\tf\t', 'g\th\t\t\t']] unless err
next err
parser.write chr for chr in data
parser.end()

it 'with char after whitespaces', (next) ->
data = '''
"a b " x ,"c d " x
Expand Down

0 comments on commit 7487424

Please sign in to comment.