001package org.jsoup.parser;
002
003/**
004 * A Parse Error records an error in the input HTML that occurs in either the tokenisation or the tree building phase.
005 */
006public class ParseError {
007    private final int pos;
008    private final String cursorPos;
009    private final String errorMsg;
010
011    ParseError(CharacterReader reader, String errorMsg) {
012        pos = reader.pos();
013        cursorPos = reader.posLineCol();
014        this.errorMsg = errorMsg;
015    }
016
017    ParseError(CharacterReader reader, String errorFormat, Object... args) {
018        pos = reader.pos();
019        cursorPos = reader.posLineCol();
020        this.errorMsg = String.format(errorFormat, args);
021    }
022
023    ParseError(int pos, String errorMsg) {
024        this.pos = pos;
025        cursorPos = String.valueOf(pos);
026        this.errorMsg = errorMsg;
027    }
028
029    ParseError(int pos, String errorFormat, Object... args) {
030        this.pos = pos;
031        cursorPos = String.valueOf(pos);
032        this.errorMsg = String.format(errorFormat, args);
033    }
034
035    /**
036     * Retrieve the error message.
037     * @return the error message.
038     */
039    public String getErrorMessage() {
040        return errorMsg;
041    }
042
043    /**
044     * Retrieves the offset of the error.
045     * @return error offset within input
046     */
047    public int getPosition() {
048        return pos;
049    }
050
051    /**
052     Get the formatted line:column cursor position where the error occurred.
053     @return line:number cursor position
054     */
055    public String getCursorPos() {
056        return cursorPos;
057    }
058
059    @Override
060    public String toString() {
061        return "<" + cursorPos + ">: " + errorMsg;
062    }
063}