[LIB-9] Add SAN, NAG, move number and result PGN tokens
[chesshog.git] / chesshog-format / src / main / java / org / hedgecode / chess / pgn / token / TagToken.java
index e2550b9..874cf81 100644 (file)
@@ -20,7 +20,7 @@ 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;
 
 /**
@@ -31,12 +31,13 @@ import org.hedgecode.chess.pgn.entity.Game;
 public class TagToken implements Token<Game> {
 
     private static final String TAG_REGEX = "^\\[([^\"]+)\\s\"([^\"]+)\"\\]$";
-    private static final Pattern TAG_PATTERN = Pattern.compile(TAG_REGEX, Pattern.MULTILINE);
+    private static final Pattern TAG_PATTERN = Pattern.compile(TAG_REGEX);
     private static final int NAME_GROUP = 1, VALUE_GROUP = 2;
 
     @Override
     public int token(Game game, String pgn) throws ParseException {
-        Matcher matcher = TAG_PATTERN.matcher(pgn);
+        String tag = PGNUtils.nextLine(pgn);
+        Matcher matcher = TAG_PATTERN.matcher(tag);
         if (!matcher.find()) {
             throw new ParseException("parse.pgn.incorrect.tag", pgn);
         } else {
@@ -44,7 +45,7 @@ public class TagToken implements Token<Game> {
             String value = matcher.group(VALUE_GROUP);
             game.addTag(name, value);
         }
-        return pgn.indexOf(PGNConstants.PGN_CRLF) + 1;
+        return tag.length();
     }
 
 }