From ab5e4ca9c70969720de661c702b4c6955b25173e Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 7 Mar 2021 20:48:51 -0500 Subject: [PATCH] Factors `proceed_to_symbol` upwards. --- Storage/Tape/Parsers/Commodore.cpp | 15 ++------------- Storage/Tape/Parsers/Commodore.hpp | 6 ------ Storage/Tape/Parsers/TapeParser.hpp | 11 +++++++++++ 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/Storage/Tape/Parsers/Commodore.cpp b/Storage/Tape/Parsers/Commodore.cpp index 7e33c1596..ea3bea801 100644 --- a/Storage/Tape/Parsers/Commodore.cpp +++ b/Storage/Tape/Parsers/Commodore.cpp @@ -136,7 +136,7 @@ std::unique_ptr Parser::get_next_data_body(const std::shared_ptris_at_end()) { - SymbolType start_symbol = get_next_symbol(tape); + const SymbolType start_symbol = get_next_symbol(tape); if(start_symbol != SymbolType::Word) break; data->data.push_back(get_next_byte_contents(tape)); } @@ -171,17 +171,6 @@ void Parser::proceed_to_landing_zone(const std::shared_ptr } } -/*! - Swallows symbols until it reaches the first instance of the required symbol, swallows that - and returns. -*/ -void Parser::proceed_to_symbol(const std::shared_ptr &tape, SymbolType required_symbol) { - while(!tape->is_at_end()) { - const SymbolType symbol = get_next_symbol(tape); - if(symbol == required_symbol) return; - } -} - /*! Swallows the next byte; sets the error flag if it is not equal to @c value. */ @@ -211,7 +200,7 @@ uint8_t Parser::get_next_byte_contents(const std::shared_ptr> 1) | (((next_symbol == SymbolType::One) ? 1 : 0) << 8); } diff --git a/Storage/Tape/Parsers/Commodore.hpp b/Storage/Tape/Parsers/Commodore.hpp index b7cc8aecb..8a5040dc7 100644 --- a/Storage/Tape/Parsers/Commodore.hpp +++ b/Storage/Tape/Parsers/Commodore.hpp @@ -88,12 +88,6 @@ class Parser: public Storage::Tape::PulseClassificationParser &tape, bool is_original); - /*! - Swallows symbols until it reaches the first instance of the required symbol, swallows that - and returns. - */ - void proceed_to_symbol(const std::shared_ptr &tape, SymbolType required_symbol); - /*! Swallows the next byte; sets the error flag if it is not equal to @c value. */ diff --git a/Storage/Tape/Parsers/TapeParser.hpp b/Storage/Tape/Parsers/TapeParser.hpp index 478ee21c6..774a87002 100644 --- a/Storage/Tape/Parsers/TapeParser.hpp +++ b/Storage/Tape/Parsers/TapeParser.hpp @@ -56,6 +56,17 @@ template class Parser { return tape->is_at_end() && !has_next_symbol_; } + /*! + Swallows symbols until it reaches the first instance of the required symbol, swallows that + and returns. + */ + void proceed_to_symbol(const std::shared_ptr &tape, SymbolType required_symbol) { + while(!is_at_end(tape)) { + const SymbolType symbol = get_next_symbol(tape); + if(symbol == required_symbol) return; + } + } + protected: /*! Should be implemented by subclasses. Consumes @c pulse.