-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetCmd.h
56 lines (55 loc) · 1.67 KB
/
getCmd.h
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
54
55
56
#include <string>
// using namespace std;
std::string filePath(std::string inc, char jd, int n)
{
// for(int i = 0; i < inc.length(); i++)
// {
// cout<<i<<":"<<inc[i]<<endl;
// }
bool isQuotationMarks = false;
int number = 0, i_xb = 0;
char lastCh = 0;
for (int i = 0; i < inc.length(); i++)
{
for (int j = 1; j <= 2; j++)
{
char now_if_ch = (j == 1 ? '\"' : jd);
if (inc[i] == now_if_ch && !isQuotationMarks && i < inc.length() - 1 && ((inc[i + 1] != now_if_ch && inc[i - 1] != now_if_ch) || (inc[i + 1] != now_if_ch && inc[i - 1] == now_if_ch)))
{
lastCh = inc[i];
isQuotationMarks = true;
number++;
i_xb = i + 1;
}
else if (inc[i] == now_if_ch && lastCh == now_if_ch && isQuotationMarks && number == n)
{
return inc.substr(i_xb, i - i_xb);
}
else if (inc[i] == now_if_ch && lastCh == now_if_ch && isQuotationMarks && number != n)
{
if (j == 1)
{
isQuotationMarks = false;
}
else
{
if (inc[i + 1] != jd && inc[i - 1] != jd)
{
isQuotationMarks = true;
number++;
}
else
{
isQuotationMarks = false;
}
i_xb = i + 1;
}
}
}
}
if (number + 1 == n)
{
return inc.substr(i_xb);
}
return "";
}