Skip to content

Commit

Permalink
Merge pull request #244 from kaorahi/clip_sgf
Browse files Browse the repository at this point in the history
Ignore garbage texts around SGF
  • Loading branch information
featurecat authored May 25, 2018
2 parents 0c1ecdc + 58fe590 commit 21f049d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/main/java/wagner/stephanie/lizzie/rules/SGFParser.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package wagner.stephanie.lizzie.rules;

import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import wagner.stephanie.lizzie.Lizzie;
import wagner.stephanie.lizzie.analysis.GameInfo;

Expand Down Expand Up @@ -55,10 +57,12 @@ public static int[] convertSgfPosToCoord(String pos) {
}

private static boolean parse(String value) {
value = value.trim();
if (value.charAt(0) != '(') {
return false;
} else if (value.charAt(value.length() - 1) != ')') {
// Drop anything outside "(;...)"
final Pattern SGF_PATTERN = Pattern.compile("(?s).*?(\\(\\s*;.*\\)).*?");
Matcher sgfMatcher = SGF_PATTERN.matcher(value);
if (sgfMatcher.matches()) {
value = sgfMatcher.group(1);
} else {
return false;
}
int subTreeDepth = 0;
Expand Down

0 comments on commit 21f049d

Please sign in to comment.