Expand description
§Morsify
Morsify is a Rust crate for encoding and decoding Morse code. It provides a flexible and efficient way to convert text into Morse code and vice versa, with customizable options for different Morse code representations and character sets.
§Features
- Encoding: Convert plain text into Morse code with customizable symbols for dots, dashes, spaces, and separators.
- Decoding: Convert Morse code back into readable text using the provided configuration.
- Customizable Character Sets: Support for various character sets including Latin, Greek, Cyrillic, Arabic, and others, with customizable order and specific set customizations.
- Configurable Options: Define how Morse code should be represented with options for symbols, handling invalid characters, and the order of character sets for encoding/decoding.
§Usage
To use Morsify, include it in your Cargo.toml:
[dependencies]
morsify = "0.2.0"Then, use the MorseCode struct to encode and decode text. Here’s a basic example:
use morsify::{MorseCode, Options, MorseCharacterSet};
// Create a new `MorseCode` instance with customizable options
let options = Options {
dash: '-',
dot: '.',
space: '/',
separator: ' ',
character_set_order: vec![
MorseCharacterSet::Latin,
MorseCharacterSet::Numbers,
MorseCharacterSet::Punctuation,
MorseCharacterSet::Greek,
],
};
let morse_code = MorseCode::new(options);
// Encode a text message to Morse code
let encoded = morse_code.encode("Hello World");
println!("Encoded: {}", encoded);
// Decode a Morse code message to text
let decoded = morse_code.decode(".... . .-.. .-.. --- / .-- --- .-. .-.. -..");
println!("Decoded: {}", decoded);§Customizing the Character Set Order
Morsify allows you to customize the order in which character sets are used for encoding and decoding. You can specify the character sets in the Options struct by setting the character_set_order field.
For example, the following code specifies the order for Latin, Numbers, and Punctuation character sets:
use morsify::{MorseCharacterSet, Options};
let options = Options {
character_set_order: vec![
MorseCharacterSet::Latin,
MorseCharacterSet::Numbers,
MorseCharacterSet::Punctuation,
],
..Options::default()
// Other options can be set here
};The get_characters function will then respect this order when encoding/decoding the message. Customizations can also be made for specific sets, such as adding separators or mapping specific characters differently for each set.
§License
Morsify is licensed under the MIT License. See the LICENSE file for more details.
Structs§
- Morse
Code - A struct to manage Morse code operations including encoding and decoding.
- Options
- Contains options for encoding and decoding Morse code.
Enums§
- Morse
Character Set - Enumerates the different character sets used in Morse code.