parse.js
Summary
No overview generated for 'parse.js'
Zapatec.Parse=function(str2parse, delim)
{
this.init()
this.arr=[]
if (arguments.length > 1)
{
this.str2parse=this.trim(str2parse)
this.delim=delim
this.parse(this.str2parse, this.delim)
}
}
Zapatec.Parse.prototype.init=function() {
}
Zapatec.Parse.prototype.arr_clear=function() {
this.arr=[]
}
Zapatec.Parse.prototype.parse=function(str2parse, delim)
{
var i
this.arr=str2parse.split(this.delim)
for (i=0; i<this.arr.length; i++)
this.arr[i]=this.trim(this.arr[i])
}
Zapatec.Parse.prototype.NF=function(s) { return this.arr.length }
Zapatec.Parse.prototype.validField=function(iFld) { return iFld >=0 && iFld <=this.NF()-1 }
Zapatec.Parse.prototype.getField=function(iFld) {
if (!this.validField(iFld)) return undefined
return this.arr[iFld]
}
Zapatec.Parse.prototype.setField=function(iFld, value) {
if (!validField(iFld)) return undefined
this.arr[iFld]=value
}
Zapatec.Parse.prototype.pushField=function(value) { this.arr.push(value) }
Zapatec.Parse.prototype.popField=function(value) { return this.arr.pop() }
Zapatec.Parse.prototype.insertField=function(iFld, value) { this.arr.splice(iFld,0,value) }
Zapatec.Parse.prototype.pretrim = function(s) {
s += '';
return s.replace(/^\s?/, '');
};
Zapatec.Parse.prototype.posttrim = function(s) {
s += '';
return s.replace(/\s?$/, '');
};
Zapatec.Parse.prototype.trim=function(s)
{
s=this.pretrim(s)
s=this.posttrim(s)
return s
}
Zapatec.Parse.prototype.flatfile=function(delimOut)
{
var strFld, i, strFlat=''
for (i=0; i<this.NF(); i++)
{
strFld=this.getField(i) || ''
strFld=strFld.replace(/"/, "\"")
if (strFld.indexOf(delimOut) != -1)
strFld='"' + strFld + '"'
strFlat+=strFld
if (i<this.NF()-1)
strFlat += delimOut
}
return strFlat
}
Documentation generated by
JSDoc on Thu Aug 16 12:18:39 2007