Expand description
A library for phonetic codes, such as the NATO phonetic alphabet. This library provides a way to get the phonetic code for a given character, as well as to get the phonetic codes for a given word. The library includes several predefined phonetic alphabets, such as the NATO alphabet, the International alphabet, and the Italian alphabet. It also allows for custom phonetic alphabets to be created by providing a base alphabet and a list of substitutions.
§Examples
§Get the phonetic code for a character
The code function returns the phonetic code for a given character.
If the character is not found in the phonetic alphabet, it returns None.
assert_eq!(spellout::code('a').map(|c| c.code()), Some("Alpha".to_string()));
assert_eq!(spellout::code('b').map(|c| c.code()), Some("Bravo".to_string()));
assert_eq!(spellout::code('c').map(|c| c.code()), Some("Charlie".to_string()));§Get the phonetic codes for a word
use spellout::{CodesBuilder, PhoneticCode};
let codes = CodesBuilder::build(PhoneticCode::Uk);
assert_eq!(codes.code('a').map(|c| c.code()), Some("Able".to_string()));
assert_eq!(codes.code('b').map(|c| c.code()), Some("Baker".to_string()));Structs§
- Code
- Represents a character and its corresponding phonetic code.
The
Codestruct contains two fields:alphabet, which is the character being represented, andcode, which is the phonetic code corresponding to that character. - Codes
- Represents a collection of phonetic codes.
- Codes
Builder
Enums§
- Error
- Phonetic
Code - Predefined phonetic codes.
Functions§
- code
- Returns the phonetic code for a given character.
If the character is not found in the phonetic alphabet, it returns
None. - encode
- Returns an iterator over the characters in the given string and their corresponding phonetic codes.
The iterator yields a tuple of the character and an
Option<&Code>, where theOption<&Code>isSome(&Code)if the character has a corresponding phonetic code, andNoneotherwise. - entries
- Returns an iterator over all the phonetic codes in the NATO alphabet.
- is_
available_ name