From fd78f92863361a3b25808f2ca988f820f2d35618 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Sun, 23 Jan 2022 20:57:28 +0100 Subject: Create project --- src/pgnp.cpp | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/pgnp.cpp (limited to 'src/pgnp.cpp') diff --git a/src/pgnp.cpp b/src/pgnp.cpp new file mode 100644 index 0000000..391e6ee --- /dev/null +++ b/src/pgnp.cpp @@ -0,0 +1,81 @@ + +#include "pgnp.hpp" +#include + +#define IS_BLANK(c) (c==' ' || c=='\n' || c=='\t') +#define IS_EOF(loc) (loc>=pgn_content.size()) +#define EOF_CHECK(loc) {if(IS_EOF(loc)) throw UnexpectedEOF();} + +namespace pgnp { + + void PGN::FromFile(std::string filepath){ + std::ifstream file(filepath); + + std::string content((std::istreambuf_iterator(file)), + std::istreambuf_iterator()); + FromString(content); + } + + + void PGN::FromString(std::string pgn_content){ + this->pgn_content=pgn_content; + int loc=0; + while(!IS_EOF(loc)) { + char c=pgn_content[loc]; + if(!IS_BLANK(c)){ + switch (c) { + case '[': + loc=ParseNextTag(loc); + break; + } + } + loc++; + } + + /*for (auto const& [key, val] : tags){ + std::cout << key <<"="<