Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Strings = {
- /**
- * Wrapped csv line parser
- * @param s string delimited csv string
- * @param sep separator
- * @attribution : http://www.greywyvern.com/?post=258 (comments closed on blog :( )
- */
- parseCSV : function(s,sep) {
- // http://stackoverflow.com/questions/1155678/javascript-string-newline-character
- var universalNewline = /\r\n|\r|\n/g;
- var a = s.split(universalNewline);
- for(var i in a){
- for (var f = a[i].split(sep = sep || ","), x = f.length - 1, tl; x >= 0; x--) {
- if (f[x].replace(/"\s+$/, '"').charAt(f[x].length - 1) == '"') {
- if ((tl = f[x].replace(/^\s+"/, '"')).length > 1 && tl.charAt(0) == '"') {
- f[x] = f[x].replace(/^\s*"|"\s*$/g, '').replace(/""/g, '"');
- } else if (x) {
- f.splice(x - 1, 2, [f[x - 1], f[x]].join(sep));
- } else f = f.shift().split(sep).concat(f);
- } else f[x].replace(/""/g, '"');
- } a[i] = f;
- }
- return a;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement