aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2023-01-05 17:15:19 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2023-01-05 17:15:19 +0100
commitef75681956ae842cbf1b2b357374aa34e3361448 (patch)
treebfffc2171fc242a35b105fafd2198bc7bdd1fc04 /src
parentbebbc7982482a2271096ef53c778cd93a4bbff7a (diff)
Add GotoNextGame() function to skip an entire game
Diffstat (limited to 'src')
-rw-r--r--src/PGN.cpp40
-rw-r--r--src/PGN.hpp2
2 files changed, 42 insertions, 0 deletions
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) {
diff --git a/src/PGN.hpp b/src/PGN.hpp
index 15629af..d313f91 100644
--- a/src/PGN.hpp
+++ b/src/PGN.hpp
@@ -37,6 +37,8 @@ public:
* last parsed game data. Be careful.
*/
void ParseNextGame();
+ /// @brief Goto the next game while avoiding to parse entire game moves
+ void GotoNextGame();
/// @brief Check if PGN contains a specific tag
bool HasTag(std::string);
/// @brief Perform a Seven Tag Roster compliance check