From a8003a54257c0a59586dda406052f4c44d49b1c3 Mon Sep 17 00:00:00 2001 From: Leonetienne Date: Thu, 10 Feb 2022 11:18:29 +0100 Subject: impwuvd readabiwity by omitting repwacements on some first-lettes of words --- main.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 6433b01..36d2605 100644 --- a/main.cpp +++ b/main.cpp @@ -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'); } ); -- cgit v1.2.3