view core/src/luan/LuanElement.java @ 571:cd944b010f25

fix Http_test
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 08 Jul 2015 23:10:52 -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;
	}

}