mirror of
https://gitlab.com/manzerbredes/chess-move-interface.git
synced 2025-06-07 14:57:39 +00:00
Add GotoNextGame() function to skip an entire game
This commit is contained in:
parent
bebbc79824
commit
ef75681956
4 changed files with 78 additions and 2 deletions
40
src/PGN.cpp
40
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) {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue