From 851f31e7ae3c090e6769099128e7adae931286d0 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Sun, 30 Jan 2022 07:44:55 +0100 Subject: Improve FEN parser --- src/Fen.hpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/Fen.hpp') diff --git a/src/Fen.hpp b/src/Fen.hpp index a477bb0..06ca338 100644 --- a/src/Fen.hpp +++ b/src/Fen.hpp @@ -2,10 +2,11 @@ #include #include -#define IS_DIGIT(c) \ +#define FEN__IS_DIGIT(c) \ (c == '0' || c == '1' || c == '2' || c == '3' || c == '4' || c == '5' || \ c == '6' || c == '7' || c == '8' || c == '9') -#define IS_BLANK(c) (c == ' ' || c == '\n' || c == '\t' || c == '\r') +#define FEN__IS_BLANK(c) (c == ' ' || c == '\n' || c == '\t' || c == '\r') +#define FEN__CHECK_LOC() {if(loc>=fen.size()){throw InvalidFEN();}} namespace chessarbiter { @@ -33,9 +34,13 @@ private: static char NextRank(std::string fen, char loc); public: - /// @brief Parse a FEN from a string + /// @brief Parse a FEN from a string (can throw InvalidFEN) static FEN Parse(std::string); /// @brief Generate a fen string from the FEN object static std::string Serialize(FEN fen); }; + +struct InvalidFEN : public std::exception { + const char *what() const throw() { return "No piece found"; } +}; } // namespace chessarbiter -- cgit v1.2.3