Skip to content

Commit

Permalink
Improved PGN parser
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-bovet committed May 2, 2021
1 parent 7296801 commit ec6a05c
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions Shared/Engine/Helpers/FPGN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ static bool parseQuotedString(std::string pgn, unsigned &cursor, std::string &st
}

static void eatWhiteSpace(std::string pgn, unsigned &cursor) {
while (isSpaceOrNewLine(pgn[cursor])) {
while (cursor < pgn.length() && isSpaceOrNewLine(pgn[cursor])) {
cursor++;
}
}
Expand Down Expand Up @@ -589,27 +589,27 @@ bool FPGN::setGame(std::string pgn, ChessGame &game, unsigned & cursor) {
eatWhiteSpace(pgn, cursor);
result = parseQuotedString(pgn, cursor, tagValue);
assert(result);

eatWhiteSpace(pgn, cursor);
assert(pgn[cursor] == ']');
cursor++;

game.tags[tagName] = tagValue;

if (tagName == "FEN") {
result = game.setFEN(tagValue);
assert(result);
}
} else if (c == '{') {
// Indication for a comment
cursor++; // go after the {
std::string comment = "";
auto result = parseUntil(pgn, cursor, comment, '}');
assert(result);
} else if (c >= '0' && c <= '9') {
if (!parseMoveText(pgn, cursor, game, end)) {
return false;
}
parsedMoveText = true; // we are done parsing the move text section
} else {
// Any other character, such as white space or new line are ignored
} else if (c == '*') {
// The game continues (but the PGN representation stops here for that game)
cursor++;
return true;
} else {
eatWhiteSpace(pgn, cursor);
}
}

Expand Down

0 comments on commit ec6a05c

Please sign in to comment.