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"
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 = {
{'{', '}' }, // 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
@ -105,6 +120,11 @@ namespace {
return token;
}
void skip_ws(std::ifstream& stream)
{
stream >> std::ws;
}
void skip_comment_ouside_sequence(std::ifstream& nvl, char& c)
{
if (nvl.peek() == ';')
@ -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<std::string>(content))
{
if (!isspace(c))
{
only_spaces = false;
break;
}
}
if (only_spaces)
if (str_only_has_ws(std::get<std::string>(content)))
return;
// default case if content does not match keywords