-
Notifications
You must be signed in to change notification settings - Fork 2
/
zalgo.cc
194 lines (165 loc) · 5.34 KB
/
zalgo.cc
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#include "zalgo.h"
#include <stdlib.h>
#include <string>
#include <ctime>
#include <regex>
#include <iostream>
Zalgo::Zalgo()
{
}
Zalgo::~Zalgo()
{
}
std::string Zalgo::getDiacritic(int position)
{
std::string glyphWithDiacritic = "";
if (position == 0)
{
glyphWithDiacritic = this->ABOVE_DIACRITICS[rand() % ABOVE_DIACRITICS_SIZE];
}
else if (position == 1)
{
glyphWithDiacritic = this->MIDDLE_DIACRITICS[rand() % MIDDLE_DIACRITICS_SIZE];
}
else if (position == 3)
{
glyphWithDiacritic = this->BELOW_DIACRITICS[rand() % BELOW_DIACRITICS_SIZE];
}
return glyphWithDiacritic;
}
std::string Zalgo::generateLine(std::string input, int &aboveCount, int &middleCount, int &belowCount, int &flag)
{
if (flag < 0)
{
aboveCount = Zalgo::randomCountGenerator(aboveCount);
middleCount = Zalgo::randomCountGenerator(middleCount);
belowCount = Zalgo::randomCountGenerator(belowCount);
}
else
{
if (aboveCount == -1)
aboveCount = Zalgo::randomCountGenerator(aboveCount);
if (middleCount == -1)
middleCount = Zalgo::randomCountGenerator(middleCount);
if (belowCount == -1)
belowCount = Zalgo::randomCountGenerator(belowCount);
}
std::string zalgoLine = "";
for (int i = 0; (unsigned)i < input.length(); i++)
{
zalgoLine += input[i];
if (!isspace(input[i]) && !ispunct(input[i]))
{
for (int i = 0; i < aboveCount; i++)
zalgoLine += getDiacritic(0);
for (int i = 0; i < middleCount; i++)
zalgoLine += getDiacritic(1);
for (int i = 0; i < belowCount; i++)
zalgoLine += getDiacritic(3);
}
}
return zalgoLine;
}
std::vector<int> Zalgo::argumentParser(std::string input)
{
std::vector<int> argumentVector;
std::string tempString = "";
if (input == "--random" || input == "-r")
{
argumentVector.push_back(-1);
return argumentVector;
}
for (int i = 0; (unsigned)i < input.length(); i++)
{
if (input[i] == '-')
{
if (tempString == "random")
{
argumentVector.push_back(-1);
}
else
{
argumentVector.push_back(stoi(tempString));
}
tempString = "";
continue;
}
tempString += input[i];
}
if (tempString == "random")
{
argumentVector.push_back(-1);
}
else
{
argumentVector.push_back(stoi(tempString));
}
return argumentVector;
}
int Zalgo::randomCountGenerator(int &input)
{
if (input == -1)
return (rand() % 100 + 1);
if (input == -10)
return (rand() % 10 + 1);
if (input == -100)
return (rand() % 1000 + 1);
return 0;
}
int main(int argc, char **argv)
{
std::ios::sync_with_stdio(0);
std::cin.tie(NULL);
std::cout.tie(NULL);
srand(time(NULL));
if (argc > 2)
{
std::cout << "Wrong usage" << std::endl;
std::cout << "zalgo [-h | --help HELP] [-r | --random RANDOM] [PATTERN]" << std::endl;
std::cout << "\nWhere PATTERN is (in regex) ^\\d{1,}|(random)-\\d{1,}|(random)-\\d{1,}|(random) corresponding to diacritical concatenation locations of ABOVE-MIDDLE-BELOW" << std::endl;
return -1;
}
int aboveCount = 0;
int middleCount = 0;
int belowCount = 0;
int flag = -1;
Zalgo zalgo;
if (argc == 1)
{
aboveCount = middleCount = belowCount = flag = -10;
}
else if (std::regex_match(argv[1], std::regex("(^(\\d{1,}|(random))-(\\d{1,}|(random))-(\\d{1,}|(random)))|(^--random)|(^-r)|(^-h)|(^--help)")))
{
if (std::regex_match(argv[1], std::regex("^(\\d{1,}|(random))-(\\d{1,}|(random))-(\\d{1,}|(random))")))
{
std::vector<int> arguments = zalgo.argumentParser(argv[1]);
aboveCount = arguments[0];
middleCount = arguments[1];
belowCount = arguments[2];
flag = 0;
}
else if (std::regex_match(argv[1], std::regex("(^--random)|(^-r)")))
{
aboveCount = middleCount = belowCount = flag = -100;
}
else if (std::regex_match(argv[1], std::regex("(^-h)|(^--help)")))
{
std::cout << "zalgo [-h | --help HELP] [-r | --random RANDOM] [PATTERN]" << std::endl;
std::cout << "\nWhere PATTERN is (in regex) ^\\d{1,}|(random)-\\d{1,}|(random)-\\d{1,}|(random) corresponding to diacritical concatenation locations of ABOVE-MIDDLE-BELOW" << std::endl;
return 0;
}
}
else
{
std::cout << "Wrong usage" << std::endl;
std::cout << "zalgo [-h | --help HELP] [-r | --random RANDOM] [PATTERN]" << std::endl;
std::cout << "\nWhere PATTERN is (in regex) ^\\d{1,}|(random)-\\d{1,}|(random)-\\d{1,}|(random) corresponding to diacritical concatenation locations of ABOVE-MIDDLE-BELOW" << std::endl;
return 1;
}
std::string inputLine;
while (getline(std::cin, inputLine))
{
std::cout << zalgo.generateLine(inputLine, aboveCount, middleCount, belowCount, flag);
}
return 0;
}