Files
riscv-emulator/emulator/CommandParser.cpp
2025-07-06 11:01:35 +02:00

31 lines
865 B
C++

//
// Created by black on 12.06.25.
//
#include "CommandParser.h"
#include <sstream>
CommandParser & CommandParser::getInstance() {
static CommandParser instance;
return instance;
}
std::vector<std::string> CommandParser::parseLine(const std::string &input) {
std::vector<std::string> output{};
/// Konvertiere den Input String in einen IStringStream, damit dieser bei Leerzeichen gesplittet werden kann
std::istringstream iss(input);
std::string out;
do {
/// Trenne den IStringStream bei jedem Leerzeichen und füge die Befehl(e)/-sargumente dem Output hinzu
std::getline(iss, out, ' ');
/// Stoppe, sobald ein Kommentar im Source Code vorkommt
if (out.at(0) != '#') {
output.push_back(out);
} else {
break;
}
} while (!out.empty());
return output;
}