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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
|
#ifndef UWWWU_LIBUWU_H
#define UWWWU_LIBUWU_H
#include <StringTools.h>
#include <CharTools.h>
#include <string>
#include <sstream>
#include <functional>
#include <random>
#include "Util.h"
// This validator will only replace findings, if they are a complete word, and not just part of a word.
static inline auto ValidatorFindingIsCompleteWord(const std::string& original, const std::string& finding, const std::size_t index) -> bool {
// Quick-accept: Original-string length matches finding-string length
if (original.length() == finding.length())
return true;
bool lastCharBreaksWord = true; // Default is true, because this value stays in case there is no last/next char.
bool nextCharBreaksWord = true; // In this case, "no character" would imply the word to be broken.
// Assign surrounding chars, if possible
if (index > 0)
lastCharBreaksWord = !CharTools::IsLetter(original[index - 1]);
if (index + finding.length() < original.length())
nextCharBreaksWord = !CharTools::IsLetter(original[index + finding.length()]);
// If both the last and the next character are word-breaking, replace.
if (lastCharBreaksWord && nextCharBreaksWord)
return true;
// Else: don't
else
return false;
}
//! Will make a boring string look sooper dooper kawaii and cute :3
static inline std::string MakeUwu(std::string boringString) {
// Easy ones first
// none, lol
// Slightly more complex... Multichar replacements, but we have to keep capitalization...
boringString = Util::ConditionalReplaceButKeepSigns(boringString, "th", "tw");
boringString = Util::ConditionalReplaceButKeepSigns(boringString, "ove", "uv");
boringString = Util::ConditionalReplaceButKeepSigns(boringString, "have", "haf");
boringString = Util::ConditionalReplaceButKeepSigns(boringString, "tr", "tw");
boringString = Util::ConditionalReplaceButKeepSigns(boringString, "up", "uwp");
// Let's do some language adjustments
boringString = Util::ConditionalReplaceButKeepSigns(boringString, "twank you", "you're twe best <3333 xoxo", ValidatorFindingIsCompleteWord);
boringString = Util::ConditionalReplaceButKeepSigns(boringString, "good", "sooper dooper", ValidatorFindingIsCompleteWord);
boringString = Util::ConditionalReplaceButKeepSigns(boringString, "suwper", "sooper dooper", ValidatorFindingIsCompleteWord);
boringString = Util::ConditionalReplaceButKeepSigns(boringString, "well", "sooper dooper", ValidatorFindingIsCompleteWord);
boringString = Util::ConditionalReplaceButKeepSigns(boringString, "emacs", "vim", ValidatorFindingIsCompleteWord);
boringString = Util::ConditionalReplaceButKeepSigns(boringString, "twanks", "you're twe best :33 xoxo", ValidatorFindingIsCompleteWord);
boringString = Util::ConditionalReplaceButKeepSigns(boringString, "hello", "hiiiiiii", ValidatorFindingIsCompleteWord);
boringString = Util::ConditionalReplaceButKeepSigns(boringString, "dear", "hiiiiiii", ValidatorFindingIsCompleteWord);
// Let's extend some phonetics
boringString = Util::ConditionalReplaceButKeepSigns(boringString, "hi", "hiiiiiii");
boringString = Util::ConditionalReplaceButKeepSigns(boringString, "ay", "aaay");
boringString = Util::ConditionalReplaceButKeepSigns(boringString, "ey", "eeey");
// Replace N with Ny, but only if succeeded by a vowel, and not (preceded by an o and succeeded by an "e{nonletter}"): "one" has such a niche pronunciation...
boringString = Util::ConditionalReplaceButKeepSigns(
boringString,
"n",
"ny",
[](const std::string& original, const std::string& finding, const std::size_t index) {
// Don't replace, if we are on the last char
if (index + finding.length() == original.length())
return false;
const char nextChar = CharTools::MakeLower(original[index + finding.length()]);
const bool haveLastchar = index > 0; // Do we even have a last char?
const char lastChar = haveLastchar ? CharTools::MakeLower(original[index - 1]) : '\0';
// Apply the complex "one\b"-rule:
// (don't replace if 'n' is preceded by 'o' and succeeded by 'e', which is succeeded by a word break)
{
bool nextNextCharIsNotLetter = false;
char nextNextChar;
// How much length is left including `nextChar`?
const std::size_t sizeLeft = original.length() - (index + finding.length());
// We have room to pick the nextNext char...
if (sizeLeft > 1)
{
nextNextChar = CharTools::MakeLower(original[index + finding.length() + 1]);
nextNextCharIsNotLetter = !CharTools::IsLetter(nextNextChar);
}
const bool nextNextCharBreaksWord = (sizeLeft == 1) || (nextNextCharIsNotLetter);
// Don't replace if:
// (lastChar == o) && (nextChar == e) && (nextNextCharBreaksWord)
if ((haveLastchar) && (lastChar == 'o') && (nextChar == 'e') && (nextNextCharBreaksWord))
return false;
}
// Is this a vowel?
if (CharTools::IsVowel(nextChar))
return true;
// Else, don't replace
return false;
}
);
// Replace R with W, but only if not succeeded by a non-vowel, and if it's not the first character of a word
boringString = Util::ConditionalReplaceButKeepSigns(
boringString,
"r",
"w",
[](const std::string& original, const std::string& finding, const std::size_t index) {
// Don't replace, if we are on the last char
if (index + finding.length() == original.length())
return false;
// Don't replace if we're at index 0
if (index == 0)
return false;
const char nextChar = CharTools::MakeLower(original[index + finding.length()]);
const char lastChar = CharTools::MakeLower(original[index - 1]);
// Is this a non-vowel?
if (!CharTools::IsVowel(nextChar))
return false;
// Don't replace if the last char is not a letter
if (!CharTools::IsLetter(lastChar))
return false;
// Else, replace
return true;
}
);
// Replace L with W, but only if not followed or preceded by another L, and if it's not the first character of a word
boringString = Util::ConditionalReplaceButKeepSigns(
boringString,
"l",
"w",
[](const std::string& original, const std::string& finding, const std::size_t index) {
// Our segment has to be at least two characters long
if (original.length() < finding.length() + 2)
return false;
// Don't replace if we're at index o
if (index == 0)
return false;
const char lastChar = CharTools::MakeLower(original[index - 1]);
const char nextChar = CharTools::MakeLower(original[index + finding.length()]);
// Don't replace if the last char is not a letter
if (!CharTools::IsLetter(lastChar))
return false;
return (lastChar != 'l') && (nextChar != 'l');
}
);
// Replace LL with WW, but only if followed by a vowel
boringString = Util::ConditionalReplaceButKeepSigns(
boringString,
"ll",
"ww",
[](const std::string& original, const std::string& finding, const std::size_t index) {
// Don't replace, if we are on the last char
if (index + finding.length() == original.length())
return false;
const char nextChar = CharTools::MakeLower(original[index + finding.length()]);
return CharTools::IsVowel(nextChar);
}
);
// Replace ER with A, but only if it's the last two letters of a word
boringString = Util::ConditionalReplaceButKeepSigns(
boringString,
"er",
"a",
[](const std::string& original, const std::string& finding, const std::size_t index) {
// Replace if we're at the end of this line/segment
if (index + finding.length() == original.length())
return true;
// Fetch the next char
const char nextChar = CharTools::MakeLower(original[index + finding.length()]);
// Replace if the next char is not a letter
return !CharTools::IsLetter(nextChar);
}
);
// Replace R with W, but only (if it's preceeded by a vowel,
// or preceeded by another 'r',
// or if it's the first character of a word)
// and if it's not the last character of a word
boringString = Util::ConditionalReplaceButKeepSigns(
boringString,
"r",
"w",
[](const std::string& original, const std::string& finding, const std::size_t index) {
// Don't replace if it's the last character
if (index + finding.length() == original.length())
return false;
// Do blindly replace if it's the first character
if (index == 0)
return true;
// Fetch the last character
const char lastChar = CharTools::MakeLower(original[index - 1]);
// Fetch the next char
const char nextChar = CharTools::MakeLower(original[index + finding.length()]);
// Don't replace, if the last char is not a letter
if (!CharTools::IsLetter(lastChar))
return false;
// Don't replace, if the next char is not a letter
if (!CharTools::IsLetter(nextChar))
return false;
// Replace, if the last character is an 'r' aswell
if (lastChar == 'r')
return true;
// Replace, if the last character is a vowel.
return CharTools::IsVowel(lastChar);
}
);
// Replace y with y-y (imitates shy stuttering), but only sometimes (random change),
// and if it is the first character of a word,
// and if it is followed by a vowel
boringString = Util::ConditionalReplaceButKeepSigns(
boringString,
"y",
"y-y",
[boringString](const std::string& original, const std::string& finding, const std::size_t index) {
// Don't replace, if we're at the end of our string
if (index + finding.length() == original.length())
return false;
// This is a bit tricky, because we can't abort if we're on the first char
// but we can can't not check the previous char either. Running big risk
// of causing a segfault. So we have to not check the previous character,
// if we are on the first char.
// Are we on the first char?
const bool isFirstChar = index == 0;
// Fetch the last character
const char lastChar = isFirstChar ? '\0' : CharTools::MakeLower(original[index - 1]);
// Fetch the next character
const char nextChar = CharTools::MakeLower(original[index + finding.length()]);
// Don't replace, if the last char is a letter
if ((!isFirstChar) && (CharTools::IsLetter(lastChar)))
return false;
// Don't replace, if the next char is not a vowel
if (!CharTools::IsVowel(nextChar))
return false;
// Initialize deterministic prng
// Can't initialize one for all scopes, they don't seem to play
// nicely with being passed to lambda functions...
static std::mt19937 rng(std::hash<std::string>()(boringString)); // Seed rng based on string
// Chance (out of a 100) for the mutation to take place
// if all preconditions are met
constexpr int chance = 25;
// Roll the dice, baby!
return (rng() % 100) < chance;
}
);
// Replace random punctuation with uwwwwu cute symbols
// About evewy fifteenth symbol
std::stringstream ss;
for (const char c : boringString)
{
// Initialize deterministic prng
std::mt19937 rng(std::hash<std::string>()(boringString)); // Seed rng based on string
if ((c == '.') && (rng() % 15 == 0))
{
ss << " <3333 ^.^ ";
}
else if ((c == '!') && (rng() % 15 == 0))
{
ss << "!! Thadws impowtant! <3 ";
}
else if ((c == ',') && (rng() % 15 == 0))
{
ss << " <3 aaaaaand ";
}
else if ((c == '?') && (rng() % 15 == 0))
{
ss << "?? now tell me! >:( ";
}
else
ss << c;
}
boringString = ss.str();
// Also replace some ascii-"emojis'
boringString = StringTools::Replace(boringString, ":)", "UwU :D");
boringString = StringTools::Replace(boringString, ":D", ":3");
boringString = StringTools::Replace(boringString, ":-)", "UwwwU :3");
boringString = StringTools::Replace(boringString, "^^", "^.^ UwU");
// Some language replacement should happen after these more complex rules
boringString = Util::ConditionalReplaceButKeepSigns(boringString, "c++", "c++ (rust is hella cutewr btw ^^)");
return boringString;
}
#endif //UWWWU_LIBUWU_H
|