Crates.io | betacode |
lib.rs | betacode |
version | 1.2.0 |
source | src |
created_at | 2022-08-17 18:28:41.988537 |
updated_at | 2024-01-18 12:20:03.21789 |
description | A rust library for Betacode conversion |
homepage | |
repository | https://github.com/caiogeraldes/betacode-rs |
max_upload_size | |
id | 647705 |
size | 24,389 |
A rust library for Betacode conversion.
Example:
use betacode::converter;
let input = String::from("mh=nin a)/eide qea\\ *phlhi+a/dew *a)xilh=os");
let output = String::from("μῆνιν ἄειδε θεὰ Πηληϊάδεω Ἀχιλῆος");
let result = betacode::converter::convert(input);
assert_eq!(result, output);
Validating a Betacode text consists in validating whether or not it follows the rules:
ValidationError::NotASCII
with the invalid characters;ValidationError::InvalidChars
with the invalid characters;ValidationError::InvalidDiacriticOrder
with the invalid sequences.The later is arguably the more easily recoverable, by means of the function converter::reorder_diacritics
.
The former pair might be recovered by ignoring invalid characters.
Details:
If the text is input in proper ASCII Betacode (and the converter
(super::converter) can convert it), it
returns Ok().
let input = String::from("mh=nin a)/eide qea\\ *phlhi+a/dew *a)xilh=os");
assert!(betacode::validator::validate(input).is_ok());
Otherwise, it specifies what error occurred.
For example, if passed a string with non-ASCII characters such as ἄλγεα,
it stores a list of all characters that break the validation in the enum
ValidationError::NotASCII
.
let input = String::from("ἄλγεα");
let result = betacode::validator::validate(input);
assert!(result.is_err());
match result {
Ok(_) => (),
Err(e) => {
if let betacode::validator::ValidationError::NotASCII(b) = e {
assert_eq!(b, vec!['ἄ', 'λ','γ','ε','α']);
}
}
}
If the string is ASCII, but the proper conversion rule has not been implemented, it stores
the list of characters that are not convertable in the enum ValidationError::InvalidChars
let input = String::from("9");
let result = betacode::validator::validate(input);
assert!(result.is_err());
match result {
Ok(_) => (),
Err(e) => {
if let betacode::validator::ValidationError::InvalidChars(b) = e {
assert_eq!(b, vec!['9']);
}
}
}
If, on other hand, the text contains an order of diacritics that can not
be directly converted, it returns the list of sequences that are not valid.
The converter module still can convert it, but this is implemented to assure
that the corpus is properly built for other tools to operate.
It stores all the patterns that break the BREATH/DIAIRESIS + ACCENT + SUB-IOTA
order in ValidationError::InvalidDiacriticOrder
.
let input = String::from("h\\( a/)ndra");
let result = betacode::validator::validate(input);
assert!(result.is_err());
match result {
Ok(_) => (),
Err(e) => {
if let betacode::validator::ValidationError::InvalidDiacriticOrder(b) = e {
assert_eq!(b, vec!["\\(".to_string(), "/)".to_string()]);
}
}
}