@@ -42,28 +42,73 @@ function rowSplit(rowStr, param) {
4242 var quoteBuff = '' ;
4343 for ( var i = 0 ; i < rowArr . length ; i ++ ) {
4444 var e = rowArr [ i ] ;
45- if ( isToogleQuote ( e , quote ) ) { //if current col has odd quotes, switch quote status
46- if ( inquote ) { //if currently in open quote status, close it and output data
47- quoteBuff += delimiter ;
48- quoteBuff += twoDoubleQuote ( e . substr ( 0 , e . length - 1 ) , quote ) ;
49- row . push ( trim ? quoteBuff . trim ( ) : quoteBuff ) ;
50- quoteBuff = '' ;
51- } else { // currently not in open quote status, open it
52- quoteBuff += twoDoubleQuote ( e . substring ( 1 ) , quote ) ;
53- }
54- inquote = ! inquote ;
55- } else if ( inquote ) { // if current col has even quotes, do not switch quote status
56- //if current status is in quote, add to buffer wait to close
57- quoteBuff += delimiter + twoDoubleQuote ( e , quote ) ;
58- } else { // if current status is not in quote, out put data
59- if ( e . indexOf ( quote ) === 0 && e [ e . length - 1 ] === quote ) { //if current col contain full quote segment,remove quote first
60- e = e . substring ( 1 , e . length - 1 ) ;
45+ if ( ! inquote && trim ) {
46+ e = e . trim ( ) ;
47+ }
48+ var len = e . length ;
49+ if ( ! inquote ) {
50+ if ( e [ 0 ] === quote ) { //possible open
51+ e = e . substr ( 1 ) ;
52+ len -= 1 ;
53+ if ( e [ 0 ] !== quote ) { // open quote
54+ if ( e [ len - 1 ] === quote ) { // possible close
55+ if ( e [ len - 2 ] !== quote ) { // close quote
56+ e = e . substring ( 0 , len - 1 ) ;
57+ e = twoDoubleQuote ( e , quote ) ;
58+ row . push ( e ) ;
59+ continue ;
60+ }
61+ }
62+ inquote = true ;
63+ quoteBuff += e ;
64+ continue ;
65+ } else {
66+ row . push ( e ) ;
67+ continue ;
68+ }
69+ } else {
70+ row . push ( e ) ;
71+ continue ;
6172 }
62- if ( trim ) {
63- e = e . trim ( ) ;
73+ } else { //previous quote not closed
74+ if ( e [ len - 1 ] === quote && e [ len - 2 ] !== quote ) { //close double quote
75+ inquote = false ;
76+ e = e . substr ( 0 , len - 1 ) ;
77+ quoteBuff += delimiter + e ;
78+ quoteBuf = twoDoubleQuote ( quoteBuff , quote ) ;
79+ if ( trim ) {
80+ quoteBuff = quoteBuff . trimRight ( ) ;
81+ }
82+ row . push ( quoteBuff ) ;
83+ quoteBuff = "" ;
84+ } else {
85+ quoteBuff += delimiter + e ;
6486 }
65- row . push ( twoDoubleQuote ( e , quote ) ) ;
6687 }
88+
89+
90+ // if (isToogleQuote(e, quote)) { //if current col has odd quotes, switch quote status
91+ // if (inquote) { //if currently in open quote status, close it and output data
92+ // quoteBuff += delimiter;
93+ // quoteBuff += twoDoubleQuote(e.substr(0, e.length - 1), quote);
94+ // row.push(trim ? quoteBuff.trim() : quoteBuff);
95+ // quoteBuff = '';
96+ // } else { // currently not in open quote status, open it
97+ // quoteBuff += twoDoubleQuote(e.substring(1), quote);
98+ // }
99+ // inquote = !inquote;
100+ // } else if (inquote) { // if current col has even quotes, do not switch quote status
101+ // //if current status is in quote, add to buffer wait to close
102+ // quoteBuff += delimiter + twoDoubleQuote(e, quote);
103+ // } else { // if current status is not in quote, out put data
104+ // if (trim) {
105+ // e = e.trim();
106+ // }
107+ // if (e.indexOf(quote) === 0 && e[e.length - 1] === quote) { //if current col contain full quote segment,remove quote first
108+ // e = e.substring(1, e.length - 1);
109+ // }
110+ // row.push(twoDoubleQuote(e, quote));
111+ // }
67112 }
68113 return row ;
69114}
0 commit comments