diff --git a/QSim.cpp b/QSim.cpp index 1bdc5d6..26405a9 100644 --- a/QSim.cpp +++ b/QSim.cpp @@ -36,7 +36,7 @@ std::vector explode(std::string const &s, char delim) for (std::string token; std::getline(iss, token, delim);) { - result.push_back(std::move(token)); + result.push_back(std::move(trim(token))); } return result; @@ -237,6 +237,7 @@ int read_cmd_line(char *filename) while (fin) { getline(fin, line); + line = trim(line); if (line[0] == '#' || line.empty()) { ++line_no; diff --git a/utils/include/util.h b/utils/include/util.h index 45ede2c..ed4c8e3 100644 --- a/utils/include/util.h +++ b/utils/include/util.h @@ -8,6 +8,9 @@ #ifndef UTILS_UTIL_H_ #define UTILS_UTIL_H_ +#include +#include + // LOG LEVELS #define LOG_LEVEL_VERBOSE 0 #define LOG_LEVEL_INFO 1 @@ -19,5 +22,6 @@ extern int LOG_LEVEL; extern void printdebug(unsigned short int, const char *); extern char getLevel(unsigned short int); +extern std::string trim(const std::string &); #endif /* UTILS_UTIL_H_ */ diff --git a/utils/util.cpp b/utils/util.cpp index 848dd57..6097203 100644 --- a/utils/util.cpp +++ b/utils/util.cpp @@ -6,7 +6,6 @@ */ #include -#include char getLevel(unsigned short int level) { @@ -47,3 +46,20 @@ void printdebug(unsigned short int level, const char *message) std::cout << type << ": " << message << "\n"; // TODO add debugging options } + + +std::string trim(const std::string &s) +{ + auto start = s.begin(); + while (start != s.end() && std::isspace(*start)) { + start++; + } + + auto end = s.end(); + do { + end--; + } while (std::distance(start, end) > 0 && std::isspace(*end)); + + return std::string(start, end + 1); +} + diff --git a/web/main.html b/web/main.html index f1f5d9a..e8b1eb9 100644 --- a/web/main.html +++ b/web/main.html @@ -238,6 +238,7 @@