@@ -2,8 +2,7 @@ var extended = require("./extended"),
2
2
isUndefinedOrNull = extended . isUndefinedOrNull ,
3
3
trim = extended . trim ,
4
4
trimLeft = extended . trimLeft ,
5
- trimRight = extended . trimRight ,
6
- LINE_BREAK = extended . LINE_BREAK ;
5
+ trimRight = extended . trimRight ;
7
6
8
7
function createParser ( options ) {
9
8
options = options || { } ;
@@ -13,9 +12,10 @@ function createParser(options) {
13
12
doTrim = options . trim || false ,
14
13
ESCAPE = options . quote || '"' ,
15
14
VALUE_REGEXP = new RegExp ( "([^" + delimiter + "'\"\\s\\\\]*(?:\\s+[^" + delimiter + "'\"\\s\\\\]+)*)" ) ,
16
- SEARCH_REGEXP = new RegExp ( "(?:\\n|" + delimiter + ")" ) ,
15
+ SEARCH_REGEXP = new RegExp ( "(?:\\n|\\r| " + delimiter + ")" ) ,
17
16
ESCAPE_CHAR = options . escape || '"' ,
18
- NEXT_TOKEN_REGEXP = new RegExp ( "([^\\s]|\\\n|" + delimiter + ")" ) ;
17
+ NEXT_TOKEN_REGEXP = new RegExp ( "([^\\s]|\\n|\\r|" + delimiter + ")" ) ,
18
+ LINE_BREAK = / [ \r \n ] / ;
19
19
20
20
function formatItem ( item ) {
21
21
if ( doTrim ) {
@@ -67,11 +67,11 @@ function createParser(options) {
67
67
if ( hasMoreData ) {
68
68
cursor = null ;
69
69
} else {
70
- throw new Error ( "Parse Error: expected: '" + ESCAPE + "' got: '" + nextToken + "'. at '" + str . substr ( cursor ) . replace ( / \n / g, "\\n" + "'" ) ) ;
70
+ throw new Error ( "Parse Error: expected: '" + ESCAPE + "' got: '" + nextToken + "'. at '" + str . substr ( cursor ) . replace ( / [ r \n ] / g, "\\n" + "'" ) ) ;
71
71
}
72
72
} else if ( ( ! depth && nextToken && nextToken . search ( SEARCH_REGEXP ) === - 1 ) ) {
73
- throw new Error ( "Parse Error: expected: '" + ESCAPE + "' got: '" + nextToken + "'. at '" + str . substr ( cursor , 10 ) . replace ( / \n / g, "\\n" + "'" ) ) ;
74
- } else if ( hasMoreData && ( ! nextToken || nextToken . search ( LINE_BREAK ) === - 1 ) ) {
73
+ throw new Error ( "Parse Error: expected: '" + ESCAPE + "' got: '" + nextToken + "'. at '" + str . substr ( cursor , 10 ) . replace ( / [ \r \n ] / g, "\\n" + "'" ) ) ;
74
+ } else if ( hasMoreData && ( ! nextToken || ! LINE_BREAK . test ( nextToken ) ) ) {
75
75
cursor = null ;
76
76
}
77
77
if ( cursor !== null ) {
@@ -98,7 +98,7 @@ function createParser(options) {
98
98
items . push ( formatItem ( searchStr . substr ( 0 , nextIndex ) ) ) ;
99
99
cursor += nextIndex + 1 ;
100
100
}
101
- } else if ( nextChar . search ( LINE_BREAK ) !== - 1 ) {
101
+ } else if ( LINE_BREAK . test ( nextChar ) ) {
102
102
items . push ( formatItem ( searchStr . substr ( 0 , nextIndex ) ) ) ;
103
103
cursor += nextIndex ;
104
104
} else if ( ! hasMoreData ) {
@@ -127,7 +127,7 @@ function createParser(options) {
127
127
if ( isUndefinedOrNull ( token ) ) {
128
128
i = lastLineI ;
129
129
break ;
130
- } else if ( token === LINE_BREAK ) {
130
+ } else if ( LINE_BREAK . test ( token ) ) {
131
131
i = nextToken . cursor + 1 ;
132
132
if ( i < l ) {
133
133
rows . push ( items ) ;
0 commit comments