small refactor

This commit is contained in:
lachrymaL 2021-05-16 12:59:18 -04:00
parent 8686ba1a3b
commit 41a169d118
No known key found for this signature in database
GPG key ID: F3640ACFA174B1C1

View file

@ -2,11 +2,25 @@
#include "NVL.h" #include "NVL.h"
namespace { 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<char, char> SCOPER_MAP = { const std::map<char, char> SCOPER_MAP = {
{'{', '}' }, // CURLY {'{', '}' }, // CURLY
{'<', '>'}, // ANGLED {'<', '>'}, // ANGLED
@ -87,6 +101,7 @@ namespace {
return final; return final;
} }
// facilities for parsing
std::string read_sequence_name(std::ifstream& nvl) 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 // 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; return token;
} }
void skip_ws(std::ifstream& stream)
{
stream >> std::ws;
}
void skip_comment_ouside_sequence(std::ifstream& nvl, char& c) void skip_comment_ouside_sequence(std::ifstream& nvl, char& c)
{ {
@ -122,14 +142,6 @@ namespace {
skip_ws(nvl); skip_ws(nvl);
} }
} }
void indent_loop(int indent)
{
for (int i = 0; i < indent; i++)
{
std::cout << "\t";
}
}
} }
namespace NVL namespace NVL
@ -221,16 +233,7 @@ namespace NVL
else else
{ {
// early return if string is empty, this should only happen if calling from an object (not a call) // early return if string is empty, this should only happen if calling from an object (not a call)
bool only_spaces = true; if (str_only_has_ws(std::get<std::string>(content)))
for (auto& c : std::get<std::string>(content))
{
if (!isspace(c))
{
only_spaces = false;
break;
}
}
if (only_spaces)
return; return;
// default case if content does not match keywords // default case if content does not match keywords