diff options
| author | Leonetienne <leonetienne@hotmail.de> | 2022-04-09 15:35:51 +0200 |
|---|---|---|
| committer | Leonetienne <leonetienne@hotmail.de> | 2022-04-09 15:35:51 +0200 |
| commit | 34f8a6104dfcf62f3ea0ee4ac50ad1e06642fdf0 (patch) | |
| tree | 59e7cb5366eec6ae753b0d51488cf0225b80f63d | |
| parent | 3dc939e164aa0e20622c58837d4129e7ba65becd (diff) | |
| parent | 5905ff597c03a56c661ef74240388ff9dbd9d54d (diff) | |
Resolve merge conflict
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | Src/LibUwu.h | 94 |
2 files changed, 93 insertions, 3 deletions
@@ -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 ^.^ "; |
