From 4a3dc6bd63dd9a29f6a1f9b400a46e44f8511f17 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Fri, 23 Feb 2024 09:09:40 +0100 Subject: [PATCH] code cleanup --- src/morse.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/morse.cpp b/src/morse.cpp index 819a26a..9b8a5ec 100644 --- a/src/morse.cpp +++ b/src/morse.cpp @@ -22,26 +22,26 @@ std::map morseCode = { std::string refurbishMessage(const std::string &msg) { - std::string msgUpper; - msgUpper.resize(msg.length()); + std::string msgRefurb; + msgRefurb.resize(msg.length()); // Make the message all upper case - std::transform(msg.cbegin(), msg.cend(), msgUpper.begin(), [](unsigned char c) { return std::toupper(c); }); + std::transform(msg.cbegin(), msg.cend(), msgRefurb.begin(), [](unsigned char c) { return std::toupper(c); }); // Encode the special characters as we like it - msgUpper = std::regex_replace(msgUpper, std::regex(""), "="); - msgUpper = std::regex_replace(msgUpper, std::regex(""), "k"); - msgUpper = std::regex_replace(msgUpper, std::regex(""), "s"); - msgUpper = std::regex_replace(msgUpper, std::regex(""), "+"); - msgUpper = std::regex_replace(msgUpper, std::regex(""), "a"); + msgRefurb = std::regex_replace(msgRefurb, std::regex(""), "="); + msgRefurb = std::regex_replace(msgRefurb, std::regex(""), "k"); + msgRefurb = std::regex_replace(msgRefurb, std::regex(""), "s"); + msgRefurb = std::regex_replace(msgRefurb, std::regex(""), "+"); + msgRefurb = std::regex_replace(msgRefurb, std::regex(""), "a"); // Remove all other unknown characters - msgUpper.erase(remove_if(msgUpper.begin(), msgUpper.end(), + msgRefurb.erase(remove_if(msgRefurb.begin(), msgRefurb.end(), [](const char &c) { return c != ' ' && morseCode.find(c) == morseCode.end(); }), - msgUpper.end()); + msgRefurb.end()); // Remove spaces, if there are too many of them - msgUpper = std::regex_replace(msgUpper, std::regex("(\\s+)"), " "); + msgRefurb = std::regex_replace(msgRefurb, std::regex("(\\s+)"), " "); - return msgUpper; + return msgRefurb; } \ No newline at end of file