mirror of
https://github.com/avinal/The-VM-to-HACK-Translator.git
synced 2026-01-09 22:58:33 +05:30
utility file
This commit is contained in:
27
vutility.cpp
Normal file
27
vutility.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "vutility.hpp"
|
||||
|
||||
std::vector<std::string> vutility::split(std::string str, char delimit)
|
||||
{
|
||||
std::vector<std::string> tokens;
|
||||
std::stringstream tokenizer(str);
|
||||
std::string intermediate;
|
||||
while (std::getline(tokenizer, intermediate, delimit))
|
||||
{
|
||||
tokens.push_back(intermediate);
|
||||
}
|
||||
return tokens;
|
||||
}
|
||||
|
||||
std::string vutility::trim(std::string str)
|
||||
{
|
||||
if (str.substr(0, 2) == "//")
|
||||
{
|
||||
str.erase();
|
||||
}
|
||||
else
|
||||
{
|
||||
str.erase(0, str.find_first_not_of(" \r\t\v\n")); //prefixing
|
||||
str.erase(str.find_last_not_of(" \r\t\v\n") + 1); //surfixing}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
13
vutility.hpp
Normal file
13
vutility.hpp
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include<sstream>
|
||||
class vutility
|
||||
{
|
||||
private:
|
||||
vutility() {}
|
||||
|
||||
public:
|
||||
static std::vector<std::string> split(std::string str, char delimit);
|
||||
static std::string trim(std::string str);
|
||||
};
|
||||
Reference in New Issue
Block a user