forked from jamesrwaugh/VLSI-Project
/
utility.cpp
53 lines (46 loc) · 1.24 KB
/
utility.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "utility.h"
std::vector<std::string> Split(const std::string& target, const std::string& delims)
{
std::vector<std::string> result;
size_t startPos = 0, it = 0;
do {
it = target.find_first_of(delims, startPos);
result.push_back(target.substr(startPos, it - startPos));
startPos = target.find_first_not_of(delims, it+1);
}
while(it != std::string::npos);
return result;
}
void trim(std::string& s)
{
s.erase(0, s.find_first_not_of(" \t"));
s.erase(s.find_last_not_of(" \t")+1, std::string::npos);
}
void removeComments(std::string& s)
{
size_t comment = s.find('#');
if(comment != std::string::npos)
s.erase(comment, std::string::npos);
}
std::istream& getline_fixed_recursive(std::istream& is, std::string& line, bool append)
{
std::string s;
if(std::getline(is, s)) {
removeComments(s);
trim(s);
std::string sa = s.substr(0, s.find('\\'));
if(append) {
line.append(sa);
} else {
line = sa;
}
if(s.back() == '\\') {
getline_fixed_recursive(is, line, true);
}
}
return is;
}
std::istream& getline_fixed(std::istream& is, std::string& line)
{
return getline_fixed_recursive(is, line, false);
}