Skip to content

Commit b9cdf29

Browse files
committed
Updated C++ owoifier
1 parent 16acb5a commit b9cdf29

File tree

1 file changed

+33
-13
lines changed

1 file changed

+33
-13
lines changed

C++/owoify.cpp

+33-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
#include <iostream>
22
#include <random>
3+
#include <regex>
4+
5+
6+
std::wstring regexReplace(std::wstring str, std::wregex regex, std::wstring search, std::wstring replace) {
7+
std::wsmatch m;
8+
std::wstring out;
9+
std::wstring in = str;
10+
while (std::regex_search(in, m, regex)) {
11+
out += m.prefix();
12+
std::wregex re(search);
13+
out += std::regex_replace(m[0].str(), re, replace);
14+
in = m.suffix();
15+
}
16+
return out += in;
17+
}
318

419
//Very bad code
520
std::wstring owoify(std::wstring STR) {
@@ -9,33 +24,38 @@ std::wstring owoify(std::wstring STR) {
924
const wchar_t *prefix[] = {
1025
L"OWO", L"OwO", L"0w0", L"< 3", L"UwU", L"HIIII!", L"H - hewwo??", L"Huohhhh."
1126
};
12-
std::uniform_int_distribution<int> pr(0, 8);
27+
std::uniform_int_distribution<int> pr(0, 7);
1328
std::wstring px = prefix[pr(e1)];
1429

1530
const wchar_t *suffix[] = {
1631
L"..,", L"fwendo", L"Huoh.", L"._.", L";-;", L";_;", L"(;ω;)", L"ÙωÙ", L"UwU", L"(人◕ω◕)", L"(●´ω`●)", L"(✿ ♡‿♡)",
1732
L"(◠‿◠✿)", L"^ - ^", L"^ _ ^", L"> _ <", L"> _ >", L":P", L":3", L";3", L"x3", L":D", L"xD", L"XDDD", L"(^v^)",
1833
L"ㅇㅅㅇ", L"(• o •)", L"ʕ•̫͡•ʔ", L"ʕʘ‿ʘʔ", L"( '◟ ')"
1934
};
20-
std::uniform_int_distribution<int> sr(0, 30);
35+
std::uniform_int_distribution<int> sr(0, 29);
2136
std::wstring sx = suffix[sr(e1)];
2237

23-
if (RSTR.find(L"r") != std::string::npos) { size_t pos; while ((pos = RSTR.find(L"r")) != std::string::npos) { RSTR.replace(pos, 1, L"w"); } }
24-
if (RSTR.find(L"l") != std::string::npos) { size_t pos; while ((pos = RSTR.find(L"l")) != std::string::npos) { RSTR.replace(pos, 1, L"w"); } }
25-
if (RSTR.find(L"R") != std::string::npos) { size_t pos; while ((pos = RSTR.find(L"R")) != std::string::npos) { RSTR.replace(pos, 1, L"W"); } }
26-
if (RSTR.find(L"L") != std::string::npos) { size_t pos; while ((pos = RSTR.find(L"L")) != std::string::npos) { RSTR.replace(pos, 1, L"W"); } }
27-
if (RSTR.find(L"no") != std::string::npos) { size_t pos; while ((pos = RSTR.find(L"no")) != std::string::npos) { RSTR.replace(pos, 2, L"nu"); } }
28-
if (RSTR.find(L"have") != std::string::npos) { size_t pos; while ((pos = RSTR.find(L"have")) != std::string::npos) { RSTR.replace(pos, 4, L"haz"); } }
29-
if (RSTR.find(L"has") != std::string::npos) { size_t pos; while ((pos = RSTR.find(L"has")) != std::string::npos) { RSTR.replace(pos, 3, L"haz"); } }
30-
if (RSTR.find(L"you") != std::string::npos) { size_t pos; while ((pos = RSTR.find(L"you")) != std::string::npos) { RSTR.replace(pos, 3, L"uu"); } }
31-
if (RSTR.find(L"the") != std::string::npos) { size_t pos; while ((pos = RSTR.find(L"the")) != std::string::npos) { RSTR.replace(pos, 3, L"da"); } }
32-
38+
RSTR = std::regex_replace(RSTR, std::wregex(L"r"), L"w");
39+
RSTR = std::regex_replace(RSTR, std::wregex(L"l"), L"w");
40+
RSTR = std::regex_replace(RSTR, std::wregex(L"R"), L"W");
41+
RSTR = std::regex_replace(RSTR, std::wregex(L"L"), L"W");
42+
RSTR = std::regex_replace(RSTR, std::wregex(L"ha(ve|s)", std::regex_constants::icase), L"haz");
43+
RSTR = regexReplace(RSTR, std::wregex(L"n[o]+", std::regex_constants::icase), L"o", L"u");
44+
RSTR = std::regex_replace(RSTR, std::wregex(L"your", std::regex_constants::icase), L"ur");
45+
RSTR = std::regex_replace(RSTR, std::wregex(L"you", std::regex_constants::icase), L"uu");
46+
RSTR = std::regex_replace(RSTR, std::wregex(L"the", std::regex_constants::icase), L"da");
47+
RSTR = std::regex_replace(RSTR, std::wregex(L"with", std::regex_constants::icase), L"wif");
48+
RSTR = std::regex_replace(RSTR, std::wregex(L":D", std::regex_constants::icase), L"UwU");
49+
RSTR = std::regex_replace(RSTR, std::wregex(L":o", std::regex_constants::icase), L"owo");
50+
RSTR = std::regex_replace(RSTR, std::wregex(L":O", std::regex_constants::icase), L"OwO");
51+
RSTR = std::regex_replace(RSTR, std::wregex(L":\\\\", std::regex_constants::icase), L":3");
52+
3353
std::wstring space = L" ";
3454
return px + space + RSTR + space + sx;
3555
}
3656

3757
using namespace std;
38-
int main()
58+
int wmain()
3959
{
4060
const wchar_t string[] = L"String to owoify";
4161
wcout << owoify(string);

0 commit comments

Comments
 (0)