[LIB-9] Add SAN, NAG, move number and result PGN tokens
[chesshog.git] / chesshog-format / src / main / java / org / hedgecode / chess / pgn / PGNUtils.java
index 822c31f..884a388 100644 (file)
@@ -19,6 +19,8 @@ package org.hedgecode.chess.pgn;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import static org.hedgecode.chess.pgn.PGNConstants.*;
+
 /**
  * PGNUtils
  *
@@ -29,8 +31,8 @@ public final class PGNUtils {
     private static final char BACKSLASH = '\\';
     private static final String SHIELD_REGEX = "\\\\";
 
-    private static final String CRLF = "\\r?\\n";
-    private static final String SPACE = " ";
+    private static final String EMPTY = "";
+    private static final String CRLF_REGEX = "\\r?\\n";
 
     public static String match(String source, String regex) {
         Matcher matcher = Pattern.compile(
@@ -48,7 +50,7 @@ public final class PGNUtils {
     public static boolean isPgn(String source) {
         return match(
                 source,
-                PGNConstants.PGN_DETECT_REGEX
+                PGN_DETECT_REGEX
         ) != null;
     }
 
@@ -68,8 +70,16 @@ public final class PGNUtils {
         return source;
     }
 
+    public static boolean isEmpty(String pgn) {
+        return pgn.replaceAll(CRLF_REGEX, EMPTY).isEmpty();
+    }
+
+    public static String nextLine(String pgn) {
+        return pgn.substring(0, pgn.indexOf(PGN_CRLF) + 1);
+    }
+
     public static String stripCrlf(String pgn) {
-        return pgn.replaceAll(CRLFSPACE);
+        return pgn.replaceAll(CRLF_REGEX, PGN_SPACE);
     }
 
     private PGNUtils() {