ggerganov / ggmorse

Morse code decoding library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

feature request: support for multi-character constants

grkblood13 opened this issue · comments

I tried to update the code to support the full international morse code standard with what I thought were single characters (minus CH) to the unordered map kMorseCode in ggmorse.cpp, but I got multi-character character constant warnings when compiling and bigger problems when running. Perhaps this is why you left these out to begin with. The symbols in question, some which are shared by other non-latin symbols and pose another interesting issue, are:

    { "0101",    'Ä',  },
    { "01101",   'À',  },
    { "1111",    'CH', },
    { "00100",   'É',  },
    { "11011",   'Ñ',  },
    { "1110",    'Ö',  },
    { "0011",    'Ü',  },

I tried converting the unordered map to strings instead of characters, but it just turned into a big mess. I'm thinking that's the way it probably should be though in order to fully support all possibilities.

Multi-byte characters are currently not supported by ggmorse.
I think the simplest solution that you can do is keep the internal map as it is and extend it with a few extra single-byte characters and then perform the mapping to your multi-byte characters outside of ggmorse.

For example:

// in ggmorse.cpp
const TAlphabet kMorseCode = {
    { "0101",    128,  },
    { "01101",   129,  },
    { "1111",    130,  },
    { "00100",   131,  },
    { "11011",   132,  },
    { "1110",    133,  },
    { "0011",    134,  },
    { "01",      'A',  },
    { "1000",    'B',  },
    { "1010",    'C',  },
    { "100",     'D',  },
...
};

```c++
// in your code
// use this map to convert the resulting single-byte text to multi-byte text
const std::unordered_map<char, std::string> {
    { 128,   "Ä",  },
    { 129,   "À",  },
    { 130,   "CH", },
    { 131,   "É",  },
    { 132,   "Ñ",  },
    { 133,   "Ö",  },
    { 134,   "Ü",  },
    { 'A',   "A",  },
    { 'B',   "B",  },
    { 'C',   "C",  },
    { 'D',   "D",  },
...
};

Maybe a flag could be implemented that would output the morse code sequences instead of mapping them to characters. That way, a follow-on program could handle the mapping with whatever characters are needed without having to worry about updating the mapping inside of ggmorse.