From 751e4dfef700d04390bc57095ff75128925a4910 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Wed, 28 Feb 2024 13:35:09 +0100 Subject: [PATCH] =?UTF-8?q?=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/morse.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/morse.cpp b/src/morse.cpp index 84b9037..e5a46ef 100644 --- a/src/morse.cpp +++ b/src/morse.cpp @@ -4,7 +4,7 @@ #include "morse.h" -std::map morseCode = { +std::map morseMap = { {'A', ".-"}, {'B', "-..."}, {'C', "-.-."}, @@ -82,7 +82,7 @@ void refurbishMessage(std::string &msg) // Remove all other unknown characters msg.erase(remove_if(msg.begin(), msg.end(), - [](const char &c) { return c != ' ' && morseCode.find(c) == morseCode.end(); }), + [](const char &c) { return c != ' ' && morseMap.find(c) == morseMap.end(); }), msg.end()); // Remove spaces, if there are too many of them @@ -104,20 +104,20 @@ std::string messageToMorse(std::string &msg) } // Ignore and continue with next char, if not found - auto search = morseCode.find(c); - if (search == morseCode.end()) { + auto search = morseMap.find(c); + if (search == morseMap.end()) { continue; } - for (unsigned int j = 0; j < morseCode[c].length(); j++) { - char m = morseCode[c][j]; + for (unsigned int j = 0; j < morseMap[c].length(); j++) { + char m = morseMap[c][j]; if (j == 0 && i > 0 && msg[i - 1] != ' ') { morseString.push_back('c'); } morseString += m; - if (j < morseCode[c].length() - 1) { + if (j < morseMap[c].length() - 1) { morseString.push_back('i'); } } @@ -140,12 +140,12 @@ std::string charToMorse(char ch) return morseString; } - for (unsigned int j = 0; j < morseCode[ch].length(); j++) { - char m = morseCode[ch][j]; + for (unsigned int j = 0; j < morseMap[ch].length(); j++) { + char m = morseMap[ch][j]; morseString += m; - if (j < morseCode[ch].length() - 1) { + if (j < morseMap[ch].length() - 1) { morseString.push_back('i'); } }