L.MorseCodeTranslator
1.0.2.4
See the version list below for details.
dotnet add package L.MorseCodeTranslator --version 1.0.2.4
NuGet\Install-Package L.MorseCodeTranslator -Version 1.0.2.4
<PackageReference Include="L.MorseCodeTranslator" Version="1.0.2.4" />
paket add L.MorseCodeTranslator --version 1.0.2.4
#r "nuget: L.MorseCodeTranslator, 1.0.2.4"
// Install L.MorseCodeTranslator as a Cake Addin #addin nuget:?package=L.MorseCodeTranslator&version=1.0.2.4 // Install L.MorseCodeTranslator as a Cake Tool #tool nuget:?package=L.MorseCodeTranslator&version=1.0.2.4
MorseCode-Translator
A small morsecode translator written in C# for general morsecode translation for a console app.
Description
This is one of the very first versions of my MorseCode-Translator containing simple convertions. It makes use of a flexible MorseCharCollection in which you can chose from plenty of characters to display. You can either start with the whole alphabet, only a few of them or completely new ones that are not defined yet (e.g dollar sign $).
The library offers:
- Basic alphabet convertions from text-to-morse/morse-to-text
- Basic alphabet soundfile creation aswell as output to console
- Custom morsecharacter convertions from text-to-morse/morse-to-text
- Custom morsecharacter soundfile creation aswell as output to console
Whats still in my toDo:
- Morse-soundfile-to-text-conversion (Soundfile → MorseChar)
Installation
To install the library, you can use the NuGet-package market through visual studio or per NuGet package installer:
dotnet add package L.MorseCodeTranslator --version xxx
Or the build in version in Visual Studio:
NuGet\Install-Package L.MorseCodeTranslator -Version xxx
Newest version is listed here: https://www.nuget.org/packages/L.MorseCodeTranslator/
Usage
Depending on what you want to use you can go different routes.
Getting started
To make complete use of the MorseCode-Translator start by creating an instance of a MorseCodeTranslator:
MorseCodeTranslator translator = new MorseCodeTranslator();
The constructor with no parameters initializes all MorseChars from the alphabet inside of a MorseCharCollection. Alternatively you can create only a handful of MorseChars with custom MorseRepresentations:
List<MorseChar> morseList = new List<MorseChar>
{
new MorseChar('n', "..."),
new MorseChar('a',".--"),
new MorseChar('h',".-.-")
};
MorseCharCollection morseCharCollection = new MorseCharCollection(morseList);
MorseCodeTranslator translator = new MorseCodeTranslator(morseCharCollection);
//use translator and or the collection from here on...
Once you've created a collection or a translator, you can now start using their methods for MorseConvertions or SoundFile convertions. Keep in mind that if you chose to use only a handful of MorseChars, the MorseCodeTranslator wont have access to the specific soundfiles of the alphabet.
However, if there are only e.g. 3 chars inside the MorseCodeTranslator and you use any kind of convertion method, the MorseCodeTranslator refers back to the original MorseRepresentations from the alphabet (See examples).
MorseConvertions
First of all, you can convert the whole MorseCharCollection back into its MorseRepresentations and use it for example like so:
string[] morseRepresentations = morseCharCollection.ConvertToMorseCharRepresentation();
for (int i = 0; i < morseRepresentations.Length; i++)
{
Console.WriteLine(morseRepresentations[i]);
}
//Output with example MorseCharCollection from before
//...
//.--
//.-.-
Moreover, you can use the translator to for example read a string input and convert it to the MorseCharRepresentations:
while (true)
{
Console.WriteLine("Type in some text: ");
string input = Console.ReadLine();
try
{
string[] inputToMorse = translator.ConvertStringToMorse(input);
for (int i = 0; i < inputToMorse.Length; i++)
{
Console.WriteLine(inputToMorse[i]);
}
}
catch (MorseCharNotFoundException ex)
{
Console.WriteLine("Wrong input: " + ex.Message);
}
}
//input: hello world
/*output: ....
.
.-..
.-..
---
.--
---
.-.
.-..
-.. */
If we were to type in hello world with any upper case letters we'd get an expected exception. This is because the methods are all case sensitive, meaning you can have a different morse representation for 'a' and 'A' respectively.
//input Hello World
//Wrong input: Error: cannot convert text into morse-representation because there are characters that were not defined yet
More documentation follows later...
Known issues
- Some documentations are not correct/missing.
- Inconsistent use of alphabet lookup/not clear what methods only use the internal MorseCharCollection and what methods also use the alphabet.
- Unit tests done for:
- MorseCodeTranslator
- MorseChar
- MorseCharCollection
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net472 is compatible. net48 was computed. net481 was computed. |
-
.NETFramework 4.7.2
- NAudio (>= 2.2.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Fixed some bugs relating MorseCodeTranslator and convertions