diff options
| author | Leonetienne <leonetienne@hotmail.de> | 2022-02-10 11:18:29 +0100 |
|---|---|---|
| committer | Leonetienne <leonetienne@hotmail.de> | 2022-02-10 11:18:29 +0100 |
| commit | a8003a54257c0a59586dda406052f4c44d49b1c3 (patch) | |
| tree | c9ebe3e2ea1e01c1bb566ee2094f043cd9c75cc4 | |
| parent | 479f0d4d0d43d64ce6f3cb141acb9a91605a064f (diff) | |
impwuvd readabiwity by omitting repwacements on some first-lettes of words
| -rw-r--r-- | main.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
@@ -239,7 +239,7 @@ std::string MakeUwu(std::string boringString) { } ); - // Replace R with W, but only if not succeeded by a non-vowel + // 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 = ReplaceButKeepSigns( boringString, "r", @@ -249,30 +249,48 @@ std::string MakeUwu(std::string boringString) { if (index + found.length() == boringString.length() - 1) return false; + // Don't replace if we're at index 0 + if (index == 0) + return false; + // Only replace if the next char is a vowel const char nextChar = MakeLower(boringString[index + found.length()]); + const char lastChar = MakeLower(boringString[index - 1]); // Is this a non-vowel? if (!IsVowel(nextChar)) return false; + // Don't replace if the last char is not a letter + if (!IsLetter(lastChar)) + return false; + // Else, replace return true; } ); - // Replace L with W, but only if not followed or preceded by another L + // 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 = ReplaceButKeepSigns( boringString, "l", "w", [boringString](const std::string &found, int index) { + // Our segment has to be at least two characters long if (boringString.length() < found.length() + 2) return false; + // Don't replace if we're at index o + if (index == 0) + return false; + const char lastChar = MakeLower(boringString[index - 1]); const char nextChar = MakeLower(boringString[index + found.length()]); + // Don't replace if the last char is not a letter + if (!IsLetter(lastChar)) + return false; + return (lastChar != 'l') && (nextChar != 'l'); } ); |
