package org.hedgecode.chess.pgn.token;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
import org.hedgecode.chess.ParseException;
-import org.hedgecode.chess.pgn.PGNConstants;
+import org.hedgecode.chess.pgn.PGNUtils;
import org.hedgecode.chess.pgn.entity.Game;
/**
*/
public class EmptyToken implements Token<Game> {
- private static final String EMPTY_REGEX = "^\\s*$";
- private static final Pattern EMPTY_PATTERN = Pattern.compile(EMPTY_REGEX, Pattern.MULTILINE);
-
@Override
public int token(Game game, String pgn) throws ParseException {
- Matcher matcher = EMPTY_PATTERN.matcher(pgn);
- if (!matcher.find()) {
+ String empty = PGNUtils.nextLine(pgn);
+ if (!PGNUtils.isEmpty(empty)) {
throw new ParseException("parse.pgn.incorrect.empty", pgn);
}
- return pgn.indexOf(PGNConstants.PGN_CRLF) + 1;
+ return empty.length();
}
}