package Lib;

import java.io.Reader;
import java.io.IOException;

public final class Parse {
	private Parse(){}
	public static String read(Reader in) throws IOException{
		String tmp = "";
		char c=0;
		do {
			c = (char)in.read();
			tmp += c;
		}while(c!=' ' && c!='\n' && in.ready());

		return tmp.replaceAll(" ","").replaceAll("\n", "").replaceAll("\r","");
	}

	public static void expect(Reader in, String str) throws IOException, Exception{
		if (!read(in).equals(str))
			throw new Exception("expected " + str);
	}

	public static void expect(Reader in, char c) throws IOException, Exception{
		if ((char)in.read() != c)
			throw new Exception("expected " + c);
	}

	public static int readInt(Reader in) throws NumberFormatException, IOException{
		return Integer.parseInt(read(in));
	}

	public static double readDouble(Reader in) throws NumberFormatException, IOException{
		return Double.parseDouble(read(in));
	}
}
