import java.util.*;
import java.lang.Object;
public class Position implements Comparable<Position> {
private String text;
private int line, pos, index;
public Position (String text) {
this.text = text;
line = pos = 1;
index = 0;
}
public String Text(){return text;}
public int Line(){return line;}
public int Pos(){return pos;}
public int Index(){return index;}
public Position copyPos(){
return new Position(text);
}
public int compareTo (Position other){
return Integer.compare(index, other.index);
}
public String toString(){
return "(" + line + ',' + pos + ')';
}
public int cP() {
if (index == text.length())
return -1;
return Character.codePointAt(text, index);
}
public boolean isWhiteSpace() {
return Character.isWhitespace(cP());
}
public boolean isLetter() {
return Character.isLetter(cP());
}
public boolean isLetterOrDigit() {
return Character.isLetterOrDigit(cP());
}
public boolean isDecimalDigit() {
return (index != text.length() &&
text.charAt(index) >= '0' && text.charAt(index) <= '9');
}
public boolean isNewLine() {
if (index == text.length())
return true;
if (text.charAt(index) == '\r' &&
index + 1 < text.length())
return (text.charAt(index + 1) == '\n');
return (text.charAt(index) == '\n');
}
public void iterate() {
if (index < text.length()) {
if (isNewLine()) {
if (text.charAt(index) == '\r')
index++;
line++;
pos = 1;
} else {
if (Character.isHighSurrogate(text.charAt(index))) {
index++;
}
pos++;
}
index++;
}
}
}