// ExpParser Class
function ExpParser(exp, parserType){
	this.exp = exp;
	this.nextExp = null;
	this.type = parserType;
	this.column = exp;
	
	if (exp.indexOf('c') != -1)
		this.column = "Category";

	else if (exp.indexOf('C') != -1)
		this.column = "Class";
		
	else if (exp.indexOf('d') != -1)
		this.column = "Date";
		
	else if (exp.indexOf('F') != -1)
		this.column = "File Name";
		
	else if (exp.indexOf('l') != -1)
		this.column = "Location";
		
	else if (exp.indexOf('L') != -1)
		this.column = "Line Number";
		
	else if (exp.indexOf('m') != -1)
		this.column = "Message";

	else if (exp.indexOf('M') != -1)
		this.column = "Method";
		
	else if (exp.indexOf('p') != -1)
		this.column = "Priority";

	else if (exp.indexOf('r') != -1)
		this.column = "Miliseconds";

	else if (exp.indexOf('t') != -1)
		this.column = "Thread";
		
	else if (exp.indexOf('x') != -1)
		this.column = "NDC";
		
	else if (exp.indexOf('X') != -1)
		this.column = "MDC";

this.parse = function(msg, pos){		
	return this.parseLine(msg, pos, this.nextExp);
}

this.parseLine = function(msg, pos, delimiter){
	var i = 0;
	if (this.nextExp != null && this.nextExp.exp != null){
		var hasNonSpaces = false;
		while (i<this.nextExp.exp.length){
			if (this.nextExp.exp.charAt(i) != ' ') hasNonSpaces = true;
			i++;
		}
		if (hasNonSpaces)
		while (this.nextExp.exp.charAt(i) == ' ') i++;
	}
	
	var line = msg.substring(pos, msg.length);
	var startPos = 0;
	while (line.charAt(startPos) == ' '){
		startPos++;
	}
	var endExpPos = 0;
	if (this.nextExp == null || this.nextExp.exp == "%n"){
		endExpPos = line.length;
	}
	else{
		endExpPos = line.indexOf(this.nextExp.exp, startPos);
	}

	if (line == null || line=='' || endExpPos>line.length)
		return "";

	var value = line.substring(0, endExpPos);
	//alert(this.column + ' ' + value + 'next=' + this.nextExp.exp);
	return value;
}
}
