-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextProcessing.cpp
128 lines (114 loc) · 1.86 KB
/
TextProcessing.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#pragma once
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
vector<string> Split(string input, char delimiter)
{
vector<string>ans;
for(int32_t i = 0; i< input.size(); i++)
{
int32_t j = i;
while(j < input.size() && input[j] != delimiter)
{
j++;
}
string s = input.substr(i, j-i);
if(s.size() > 0)
{
ans.push_back(s);
}
i = j;
}
return ans;
}
bool IsNumber(string s)
{
if(!isdigit(s[0]) && s[0] != '-')
{
return false;
}
for(int32_t i = 1; i < s.size(); i++)
{
if(!isdigit(s[i]))
{
return false;
}
}
return true;
}
int32_t StringToInt(string s)
{
int32_t i = (s[0] == '-');
int32_t ans = 0;
for(int32_t j = i; j < s.size(); j++)
{
if(!isdigit(s[j]))
{
return -1;
}
ans = ans * 10 + s[j] - '0';
}
if(i)
{
ans *= -1;
}
return ans;
}
string IntToString(int32_t n)
{
if(n == 0)
{
return "0";
}
string s;
while(n)
{
s += n%10 + '0';
n /= 10;
}
reverse(s.begin(), s.end());
return s;
}
string BoolToString(bool f)
{
if(f)
{
return "true";
}
return "false";
}
string StringToUpper(string s)
{
string ans;
for(auto i:s)
{
ans+=toupper(i);
}
return ans;
}
bool IsBool(string s)
{
return (s == "0" || s == "1" || s == "true" || s == "false");
}
bool StringToBool(string s)
{
if(s == "true" || s == "1")
{
return true;
}
return false;
}
std::string DividingStr(std::vector<int32_t>sizes)
{
std::string s = "+";
for(auto i : sizes)
{
for(int32_t j = 0; j<i; j++)
{
s+="-";
}
s+="+";
}
return s;
}