view core/src/luan/LuanElement.java @ 498:ee55be414a34

Http.response is now mostly luan
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 18 May 2015 00:25:35 -0600
parents 5d4a78c93383
children
line wrap: on
line source

package luan;


public final class LuanElement {
	public final LuanSource source;
	public final int start;
	public final int end;
	private final String text;

	public LuanElement(LuanSource source,int start,int end) {
		this(source,start,end,null);
	}

	public LuanElement(LuanSource source,int start,int end,String text) {
		if( source==null )
			throw new NullPointerException("source is null");
		this.source = source;
		this.start = start;
		while( end > 0 && Character.isWhitespace(source.text.charAt(end-1)) ) {
			end--;
		}
		this.end = end;
		this.text = text;
	}

	public String text() {
		return text!=null ? text : source.text.substring(start,end);
	}

	int lineNumber() {
		int line = 0;
		int i = -1;
		do {
			line++;
			i = source.text.indexOf('\n',i+1);
		} while( i != -1 && i < start );
		return line;
	}

}