add a method for single chars

This commit is contained in:
Martin Brodbeck 2024-02-26 15:19:11 +01:00
parent e420930ce6
commit 4163c9d70f
2 changed files with 27 additions and 2 deletions

View file

@ -78,8 +78,32 @@ std::string messageToMorse(std::string &msg)
// Append word space if last char was not a blank
if (msg.back() != ' ') {
morseString.push_back('w');
//morseString.push_back('w');
}
return morseString;
}
std::string charToMorse(char ch) {
std::string morseString {};
if (ch == ' ') {
morseString.push_back('w');
return morseString;
}
for (unsigned int j = 0; j < morseCode[ch].length(); j++) {
char m = morseCode[ch][j];
morseString += m;
if (j < morseCode[ch].length() - 1) {
morseString.push_back('i');
}
}
//morseString.push_back('c');
return morseString;
}

View file

@ -2,4 +2,5 @@
#include <string>
std::string messageToMorse(std::string &msg);
std::string messageToMorse(std::string &msg);
std::string charToMorse(char ch);