[LIB-13] Functional for working with strings moved to StringUtils
[chesshog-scanner.git] / src / main / java / org / hedgecode / chess / scanner / format / PGNTag.java
index 10d6fec..74a066e 100644 (file)
@@ -19,6 +19,8 @@ package org.hedgecode.chess.scanner.format;
 import java.util.Arrays;
 import java.util.Comparator;
 
+import org.hedgecode.chess.scanner.StringUtils;
+
 /**
  * PGNTag
  *
@@ -64,6 +66,7 @@ public enum PGNTag {
     MODE          ( "Mode",         false,       PGNTag.EMPTY         ),
     PLY_COUNT     ( "PlyCount",     false,       PGNTag.EMPTY         );
 
+    // todo: -> PGNConstants
     public static final String EMPTY = "";
     public static final String HYPHEN = "-";
     public static final String ZERO = "0";
@@ -74,6 +77,8 @@ public enum PGNTag {
 
     public static final String TAG_FORMAT = "[%s \"%s\"]";
 
+    public static final char[] TAG_SHIELD_CHARS = { '\\', '"' };
+
     private String tagName;
     private boolean isRequired;
     private String defaultValue;
@@ -96,6 +101,12 @@ public enum PGNTag {
         return defaultValue;
     }
 
+    public static String formatTagValue(String tagValue) {
+        return StringUtils.shield(
+                tagValue, TAG_SHIELD_CHARS
+        );
+    }
+
     public static PGNTag[] tags() {
         PGNTag[] tags = values();
         Arrays.sort(