From ef75681956ae842cbf1b2b357374aa34e3361448 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Thu, 5 Jan 2023 17:15:19 +0100 Subject: Add GotoNextGame() function to skip an entire game --- src/PGN.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/PGN.cpp') diff --git a/src/PGN.cpp b/src/PGN.cpp index bfe58fe..96346e8 100644 --- a/src/PGN.cpp +++ b/src/PGN.cpp @@ -45,6 +45,46 @@ void PGN::FromString(std::string pgn_content) { this->pgn_content.FromString(pgn_content); } +void PGN::GotoNextGame(){ + // Search for new game + if (IS_EOF) { + throw NoGameFound(); + } + loctype loc = GotoNextToken(LastGameEndLoc); + if (IS_EOF) { + throw NoGameFound(); + } + // First skip current game tags + while (!IS_EOF) { + char c = pgn_content[loc]; + if (!IS_BLANK(c)) { + if (c == '[') { + loc = ParseNextTag(loc); // Here we are at ']' after the call to ParseNextTag + } else + break; + } + loc++; + } + // Goto next game '[' by skipping the entire game + while (!IS_EOF) { + char c = pgn_content[loc]; + if (!IS_BLANK(c)) { + if (c == '[') { + LastGameEndLoc=loc; + return; + } else if(c== '{'){ + // We skip the comments as they can contains '[' + while(!IS_EOF && c != '}'){ + loc++; + c = pgn_content[loc]; + } + } + } + loc++; + } + throw NoGameFound(); +} + void PGN::ParseNextGame() { // Clean previous parse if (moves != NULL) { -- cgit v1.2.3