From 41a169d118235c21671f29174439298d569aa804 Mon Sep 17 00:00:00 2001 From: lachrymaL Date: Sun, 16 May 2021 12:59:18 -0400 Subject: [PATCH] small refactor --- NouVeL/NVL.cpp | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/NouVeL/NVL.cpp b/NouVeL/NVL.cpp index 0abdf13..dbd121c 100644 --- a/NouVeL/NVL.cpp +++ b/NouVeL/NVL.cpp @@ -2,11 +2,25 @@ #include "NVL.h" namespace { - void skip_ws(std::ifstream& stream) + // general helpers, may move these into a different translation unit + bool str_only_has_ws(std::string str) { - stream >> std::ws; + for (auto& x : str) + { + if (!isspace(x)) + return false; + } + return true; + } + void indent_loop(int indent) + { + for (int i = 0; i < indent; i++) + { + std::cout << "\t"; + } } + // facilities for scopers const std::map SCOPER_MAP = { {'{', '}' }, // CURLY {'<', '>'}, // ANGLED @@ -87,6 +101,7 @@ namespace { return final; } + // facilities for parsing std::string read_sequence_name(std::ifstream& nvl) { // this function will move the reading head of nvl, this is hard to keep track of but simplifies the program @@ -104,6 +119,11 @@ namespace { return token; } + + void skip_ws(std::ifstream& stream) + { + stream >> std::ws; + } void skip_comment_ouside_sequence(std::ifstream& nvl, char& c) { @@ -122,14 +142,6 @@ namespace { skip_ws(nvl); } } - - void indent_loop(int indent) - { - for (int i = 0; i < indent; i++) - { - std::cout << "\t"; - } - } } namespace NVL @@ -221,16 +233,7 @@ namespace NVL else { // early return if string is empty, this should only happen if calling from an object (not a call) - bool only_spaces = true; - for (auto& c : std::get(content)) - { - if (!isspace(c)) - { - only_spaces = false; - break; - } - } - if (only_spaces) + if (str_only_has_ws(std::get(content))) return; // default case if content does not match keywords