Skip to content

Commit 98ecafb

Browse files
committed
update browser version
1 parent 5394898 commit 98ecafb

2 files changed

Lines changed: 70 additions & 26 deletions

File tree

dist/csvtojson.js

Lines changed: 66 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,28 +1049,73 @@ function rowSplit(rowStr, param) {
10491049
var quoteBuff = '';
10501050
for (var i=0;i<rowArr.length;i++){
10511051
var e=rowArr[i];
1052-
if (isToogleQuote(e, quote)) { //if current col has odd quotes, switch quote status
1053-
if (inquote) { //if currently in open quote status, close it and output data
1054-
quoteBuff += delimiter;
1055-
quoteBuff += twoDoubleQuote(e.substr(0, e.length - 1), quote);
1056-
row.push(trim ? quoteBuff.trim() : quoteBuff);
1057-
quoteBuff = '';
1058-
} else { // currently not in open quote status, open it
1059-
quoteBuff += twoDoubleQuote(e.substring(1), quote);
1060-
}
1061-
inquote = !inquote;
1062-
} else if (inquote) { // if current col has even quotes, do not switch quote status
1063-
//if current status is in quote, add to buffer wait to close
1064-
quoteBuff += delimiter + twoDoubleQuote(e, quote);
1065-
} else { // if current status is not in quote, out put data
1066-
if (e.indexOf(quote) === 0 && e[e.length - 1] === quote) { //if current col contain full quote segment,remove quote first
1067-
e = e.substring(1, e.length - 1);
1052+
if (!inquote && trim){
1053+
e=e.trim();
1054+
}
1055+
var len=e.length;
1056+
if (!inquote){
1057+
if (e[0] === quote){ //possible open
1058+
e=e.substr(1);
1059+
len-=1;
1060+
if (e[0]!==quote){ // open quote
1061+
if (e[len-1] === quote){ // possible close
1062+
if (e[len-2]!==quote){ // close quote
1063+
e=e.substring(0,len-1);
1064+
e=twoDoubleQuote(e,quote);
1065+
row.push(e);
1066+
continue;
1067+
}
1068+
}
1069+
inquote=true;
1070+
quoteBuff+=e;
1071+
continue;
1072+
}else{
1073+
row.push(e);
1074+
continue;
1075+
}
1076+
}else{
1077+
row.push(e);
1078+
continue;
10681079
}
1069-
if (trim) {
1070-
e = e.trim();
1080+
}else{ //previous quote not closed
1081+
if (e[len-1] === quote && e[len-2] !==quote){ //close double quote
1082+
inquote=false;
1083+
e=e.substr(0,len-1);
1084+
quoteBuff+=delimiter+e;
1085+
quoteBuf=twoDoubleQuote(quoteBuff,quote);
1086+
if (trim){
1087+
quoteBuff=quoteBuff.trimRight();
1088+
}
1089+
row.push(quoteBuff);
1090+
quoteBuff="";
1091+
}else{
1092+
quoteBuff+=delimiter+e;
10711093
}
1072-
row.push(twoDoubleQuote(e, quote));
10731094
}
1095+
1096+
1097+
// if (isToogleQuote(e, quote)) { //if current col has odd quotes, switch quote status
1098+
// if (inquote) { //if currently in open quote status, close it and output data
1099+
// quoteBuff += delimiter;
1100+
// quoteBuff += twoDoubleQuote(e.substr(0, e.length - 1), quote);
1101+
// row.push(trim ? quoteBuff.trim() : quoteBuff);
1102+
// quoteBuff = '';
1103+
// } else { // currently not in open quote status, open it
1104+
// quoteBuff += twoDoubleQuote(e.substring(1), quote);
1105+
// }
1106+
// inquote = !inquote;
1107+
// } else if (inquote) { // if current col has even quotes, do not switch quote status
1108+
// //if current status is in quote, add to buffer wait to close
1109+
// quoteBuff += delimiter + twoDoubleQuote(e, quote);
1110+
// } else { // if current status is not in quote, out put data
1111+
// if (trim) {
1112+
// e = e.trim();
1113+
// }
1114+
// if (e.indexOf(quote) === 0 && e[e.length - 1] === quote) { //if current col contain full quote segment,remove quote first
1115+
// e = e.substring(1, e.length - 1);
1116+
// }
1117+
// row.push(twoDoubleQuote(e, quote));
1118+
// }
10741119
}
10751120
return row;
10761121
}
@@ -10096,7 +10141,7 @@ module.exports={
1009610141
"email": "t3dodson@gmail.com"
1009710142
}
1009810143
],
10099-
"version": "0.5.4",
10144+
"version": "0.5.6",
1010010145
"keywords": [
1010110146
"csv",
1010210147
"csvtojson",
@@ -10134,8 +10179,7 @@ module.exports={
1013410179
"mocha": "^2.2.5"
1013510180
},
1013610181
"dependencies": {
10137-
"async": "^1.2.1",
10138-
"csv-string": "^2.3.0"
10182+
"async": "^1.2.1"
1013910183
}
1014010184
}
1014110185

0 commit comments

Comments
 (0)