2024-06-18 11:51:18 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <regex>
|
|
|
|
#include <string>
|
|
|
|
#include <fstream>
|
2024-06-20 14:11:55 +00:00
|
|
|
#include "clip-lib/clip.h"
|
2024-09-05 00:50:43 +00:00
|
|
|
#include <random>
|
2024-06-18 11:51:18 +00:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
string replacements[6][2] = {
|
|
|
|
{"(?:r|l)", "w"},
|
|
|
|
{"(?:R|L)", "W"},
|
|
|
|
{"n([aeiou])", "ny$1"},
|
|
|
|
{"N([aeiou])", "Ny$1"},
|
|
|
|
{"N([AEIOU])", "Ny$1"},
|
|
|
|
{"ove", "uv"}
|
|
|
|
};
|
|
|
|
|
2024-09-05 00:50:43 +00:00
|
|
|
string random_ending_replacents[11] = {
|
|
|
|
"uwu",
|
|
|
|
"owo",
|
|
|
|
"OwO",
|
|
|
|
"UwU",
|
|
|
|
"uwu",
|
|
|
|
"OwO",
|
|
|
|
">w<",
|
|
|
|
"Owo",
|
|
|
|
"X3",
|
|
|
|
":3",
|
|
|
|
">:3",
|
|
|
|
};
|
|
|
|
|
|
|
|
string full_word_replacents[20][2] = {
|
|
|
|
{"hello", "h-hello there"},
|
|
|
|
{"goodbye", "bai"},
|
|
|
|
{"bye", "bai"},
|
|
|
|
{"please", "p-pwease"},
|
|
|
|
{"thanks", "t-thank u"},
|
|
|
|
{"thank you", "t-thank u"},
|
|
|
|
{"you", "u"},
|
|
|
|
{"your", "ur"},
|
|
|
|
{"you're", "ur"},
|
|
|
|
{"you are", "ur"},
|
|
|
|
{"are", "r"},
|
|
|
|
{"the", "da"},
|
|
|
|
{"this", "dis"},
|
|
|
|
{"that", "dat"},
|
|
|
|
{"there", "dere"},
|
|
|
|
{"they", "dey"},
|
|
|
|
{"their", "dere"},
|
|
|
|
{"them", "dem"},
|
|
|
|
{"those", "dose"},
|
|
|
|
{"these", "deez"},
|
|
|
|
};
|
|
|
|
|
|
|
|
string random_ending(string input) {
|
|
|
|
string output = input;
|
|
|
|
for (int i = 0; i < output.length(); i++) {
|
|
|
|
if (output[i] == '.' || output[i] == '!' || output[i] == '?') {
|
|
|
|
output.insert(i, " " + random_ending_replacents[rand() % 11]);
|
|
|
|
i += random_ending_replacents[rand() % 11].length() + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (output[output.length()-1] != '.' && output[output.length()-1] != '!' && output[output.length()-1] != '?') {
|
|
|
|
output += " " + random_ending_replacents[rand() % 11];
|
|
|
|
}
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
string full_word(string input) {
|
2024-06-18 11:51:18 +00:00
|
|
|
string output = input;
|
2024-09-05 00:50:43 +00:00
|
|
|
for (int i = 0; i < 20; i++) {
|
|
|
|
output = regex_replace(output, regex(full_word_replacents[i][0]), full_word_replacents[i][1]);
|
|
|
|
}
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
string owo(string input, bool no_full_word = false, bool no_random_ending = false) {
|
|
|
|
string output = input;
|
|
|
|
if (!no_full_word){
|
|
|
|
output = full_word(output);
|
|
|
|
}
|
2024-06-18 11:51:18 +00:00
|
|
|
for (int i = 0; i < 6; i++) {
|
|
|
|
output = regex_replace(output, regex(replacements[i][0]), replacements[i][1]);
|
|
|
|
}
|
2024-09-05 00:50:43 +00:00
|
|
|
if (!no_random_ending) {
|
|
|
|
output = random_ending(output);
|
|
|
|
}
|
2024-06-18 11:51:18 +00:00
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
int help() {
|
|
|
|
cout << "Usage: owo [-p] [-h] [-f file] [-o file] [text]" << endl;
|
|
|
|
cout << " owo [text]" << endl;
|
|
|
|
cout << " owo -f [file] -o [file]" << endl;
|
|
|
|
cout << " echo [text] | owo -p" << endl << endl;
|
|
|
|
cout << "Options:" << endl;
|
|
|
|
cout << " -p Read from stdin" << endl;
|
|
|
|
cout << " -h Show this help message" << endl;
|
2024-06-20 14:03:39 +00:00
|
|
|
cout << " -f Read from file" << endl;
|
|
|
|
cout << " -o Write to file" << endl;
|
|
|
|
cout << " -c Copy to clipboard" << endl;
|
2024-09-05 00:50:43 +00:00
|
|
|
cout << " -ne Stops extra stuff from being added to the end of sentences" << endl;
|
|
|
|
cout << " -nf Stops full word replacements" << endl;
|
2024-06-20 14:03:39 +00:00
|
|
|
cout << " text Text to convert" << endl;
|
2024-06-18 11:51:18 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
2024-09-05 00:50:43 +00:00
|
|
|
srand(time(NULL));
|
2024-06-18 11:51:18 +00:00
|
|
|
string input, inputfile, outputfile;
|
2024-09-05 00:50:43 +00:00
|
|
|
bool _stdin = false, clipboard = false, no_full_word = false, no_random_ending = false;
|
2024-06-18 11:51:18 +00:00
|
|
|
|
|
|
|
if (argc < 2) {
|
|
|
|
cout << owo("No text provided") << endl << endl;
|
|
|
|
help();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 1; i < argc; i++) {
|
|
|
|
if (string(argv[i]) == "-f") {
|
|
|
|
inputfile = string(argv[i+1]);
|
|
|
|
i++;
|
|
|
|
} else if (string(argv[i]) == "-o") {
|
|
|
|
outputfile = string(argv[i+1]);
|
|
|
|
i++;
|
|
|
|
} else if (string(argv[i]) == "-p") {
|
2024-06-19 15:15:47 +00:00
|
|
|
_stdin = true;
|
2024-06-18 11:51:18 +00:00
|
|
|
} else if (string(argv[i]) == "-h") {
|
|
|
|
return help();
|
|
|
|
} else if (i == argc-1) {
|
|
|
|
input = string(argv[i]);
|
2024-06-20 14:03:39 +00:00
|
|
|
} else if (string(argv[i]) == "-c") {
|
|
|
|
clipboard = true;
|
2024-09-05 00:50:43 +00:00
|
|
|
} else if (string(argv[i]) == "-ne") {
|
|
|
|
no_random_ending = true;
|
|
|
|
} else if (string(argv[i]) == "-nf") {
|
|
|
|
no_full_word = true;
|
2024-06-18 11:51:18 +00:00
|
|
|
} else {
|
|
|
|
cout << owo("Invalid argument: " + string(argv[i])) << endl << endl;
|
|
|
|
help();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-19 15:15:47 +00:00
|
|
|
if (_stdin && inputfile != "" || _stdin && input != "" || inputfile != "" && input != "") {
|
2024-06-18 11:51:18 +00:00
|
|
|
cout << owo("Cannot use multiple input methods at once") << endl << endl;
|
|
|
|
help();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ostream *output;
|
|
|
|
|
|
|
|
if (outputfile != "") {
|
|
|
|
output = new ofstream(outputfile);
|
|
|
|
if (!output->good()) {
|
|
|
|
cout << owo("Failed to open output file") << endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-19 15:15:47 +00:00
|
|
|
if (_stdin) {
|
2024-06-18 11:51:18 +00:00
|
|
|
while (getline(cin, input)) {
|
|
|
|
if (outputfile != "") {
|
2024-09-05 00:50:43 +00:00
|
|
|
*output << owo(input, no_full_word, no_random_ending) << endl;
|
2024-06-18 11:51:18 +00:00
|
|
|
} else {
|
2024-09-05 00:50:43 +00:00
|
|
|
cout << owo(input, no_full_word, no_random_ending) << endl;
|
2024-06-18 11:51:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (inputfile != "") {
|
|
|
|
ifstream inputstream(inputfile);
|
|
|
|
if (!inputstream.good()) {
|
|
|
|
cout << owo("Failed to open input file") << endl;
|
|
|
|
if (outputfile != "") {
|
|
|
|
((ofstream*)output)->close();
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (getline(inputstream, input)) {
|
|
|
|
if (outputfile != "") {
|
2024-09-05 00:50:43 +00:00
|
|
|
*output << owo(input, no_full_word, no_random_ending) << endl;
|
2024-06-18 11:51:18 +00:00
|
|
|
} else {
|
2024-09-05 00:50:43 +00:00
|
|
|
cout << owo(input, no_full_word, no_random_ending) << endl;
|
2024-06-18 11:51:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
inputstream.close();
|
|
|
|
|
|
|
|
} else if (input != "") {
|
|
|
|
if (outputfile != "") {
|
2024-09-05 00:50:43 +00:00
|
|
|
*output << owo(input, no_full_word, no_random_ending) << endl;
|
2024-06-20 14:03:39 +00:00
|
|
|
} else if (clipboard) {
|
2024-09-05 00:50:43 +00:00
|
|
|
clip::set_text(owo(input, no_full_word, no_random_ending));
|
2024-06-20 14:03:39 +00:00
|
|
|
cout << owo("Copied to clipboard") << endl;
|
2024-06-18 11:51:18 +00:00
|
|
|
} else {
|
2024-09-05 00:50:43 +00:00
|
|
|
cout << owo(input, no_full_word, no_random_ending) << endl;
|
2024-06-18 11:51:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (outputfile != "") {
|
|
|
|
((ofstream*)output)->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|