(function(){function e(e){if(!e){return e}return e.escapeRegExp(e)}u8.Base.Csv=function(e){$.extend(this,u8.Base.Csv.defaults,e)};u8.Base.Csv.defaults={delimiter:",",escapeCharacter:"\\"};$.extend(u8.Base.Csv.prototype,{join:function(e){if(!e){return""}var t,r="";for(var i=0;i<e.length;i++){t=this.escape(e[i]);if(i>0&&this.delimiter){r+=this.delimiter}r+=t}return r},joinKeyValue:function(e){if(!e){return""}var t,r="";if(u8.tools.isArray(e)){for(var i=0;i<e.length;i++){t=this.escape(e[i][0])+"="+this.escape(e[i][1]);if(r.length>0){r+=this.delimiter}r+=t}}else{for(var a in e){t=this.escape(a)+"="+this.escape(e[a]);if(r.length>0){r+=this.delimiter}r+=t}}return r},split:function(e){if(!e){return[]}var t=[];var r=this.delimiter;var i=this.escapeCharacter;var a=0,s=0;while(true){var h=e.indexOf(r,s);if(h<0){break}var n=h-1;while(n>=s&&e.charAt(n)==i){n--}var c=h-n-1;if(c%2){s=h+1}else{t.push(this.unescape(e.substr(a,h-a)));a=s=h+1}}if(a<=e.length){t.push(this.unescape(e.substr(a)))}return t},splitKeyValue:function(t,r){if(!t){return[]}var i=new RegExp("(("+e(this.escapeCharacter)+e(this.delimiter)+"|"+e(this.escapeCharacter)+"=|[^"+e(this.delimiter)+"^=])*)=(("+e(this.escapeCharacter)+e(this.delimiter)+"|[^"+e(this.delimiter)+"])*)","g");if(!r){r=function(e,t,r){if(!r){r=[]}r.push([e,t]);return r}}else if(r=="object"){r=function(e,t,r){if(!r){r={}}r[e]=t;return r}}var a;var s=undefined;do{a=i.exec(t);if(a){s=r(this.unescape(a[1]),this.unescape(a[3]),s)}}while(a);return s},escape:function(t){if(!t&&t!==0){return""}if("string"!=typeof t){t=t.toString()}var r=new RegExp(e(this.delimiter),"g");t=t.replace(new RegExp(e(this.escapeCharacter),"g"),this.escapeCharacter+this.escapeCharacter);t=t.replace(r,this.escapeCharacter+this.delimiter);t=t.replace(/=/g,this.escapeCharacter+"=");return t},unescape:function(t){var r=new RegExp(e(this.escapeCharacter)+e(this.delimiter),"g");t=t.replace(r,this.delimiter);t=t.replace(new RegExp(e(this.escapeCharacter)+"=","g"),"=");t=t.replace(new RegExp(e(this.escapeCharacter)+e(this.escapeCharacter),"g"),this.escapeCharacter);return t}});u8.csv=new u8.Base.Csv})();