-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.cpp
32 lines (30 loc) · 1014 Bytes
/
utils.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
#include "utils.h"
// string을 char형 seperator 기준으로 나누어서 vector에 담는 함수
// https://favtutor.com/blogs/split-string-cpp
void customSplit(vector<string> &strings, string str, char seperator)
{
int startIndex = 0, endIndex = 0;
for (int i = 0; i <= str.size(); i++)
{
// If we reached the end of the word or the end of the input.
if (str[i] == seperator || i == str.size())
{
endIndex = i;
string temp;
temp.append(str, startIndex, endIndex - startIndex);
strings.push_back(temp);
startIndex = endIndex + 1;
}
}
}
void find_str(vector<string> &command_split, string line, string seperator)
{
int endIdx = line.find(seperator);
while (endIdx != -1)
{
command_split.push_back(line.substr(0, endIdx));
line.erase(line.begin(), line.begin() + endIdx + 1);
endIdx = line.find(seperator);
}
command_split.push_back(line.substr(0, endIdx));
}