summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--Src/LibUwu.h94
2 files changed, 93 insertions, 3 deletions
diff --git a/.gitignore b/.gitignore
index c3fdb70..69dd699 100644
--- a/.gitignore
+++ b/.gitignore
@@ -37,7 +37,7 @@
# *.ipr
# CMake
-*build*/
+build*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
diff --git a/Src/LibUwu.h b/Src/LibUwu.h
index a2b1ea2..51cd9b6 100644
--- a/Src/LibUwu.h
+++ b/Src/LibUwu.h
@@ -226,12 +226,102 @@ static inline std::string MakeUwu(std::string boringString) {
}
);
- // Replace random punctuation with uwwwwu cute symbols <3
+ // 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;
- std::mt19937 rng(std::hash<std::string>()(boringString)); // Seed rng based on string
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 ^.^ ";