Skip to content

Commit

Permalink
fix(parser/split): implement keep quotes option (fixes #468)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Sep 27, 2019
1 parent 8fb6f0d commit 8f1fe60
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion docs/parser/split-parser-math.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ data:
- regexp: !regexp /!!math/

split:
keepQuotes: true
keepQuotes: false
quotes: true
separator: " "
10 changes: 9 additions & 1 deletion src/parser/SplitParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class SplitParser extends BaseParser<SplitParserData> implements Parser {
}

public split(msg: string): Array<string> {
return this.splitBody(msg).map(trim).filter((it) => !isEmpty(it));
return this.splitBody(msg).map((it) => this.trim(it)).filter((it) => !isEmpty(it));
}

public splitBody(msg: string): Array<string> {
Expand All @@ -70,4 +70,12 @@ export class SplitParser extends BaseParser<SplitParserData> implements Parser {
return split(msg, this.data.split);
}
}

public trim(item: string): string {
if (this.data.split.keepQuotes) {
return trim(item);
} else {
return trim(item, ' \'"');
}
}
}

0 comments on commit 8f1fe60

Please sign in to comment.