-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Currently only possible/viable for symbols stage Other, like german, might follow but there's downsides.
- Loading branch information
Showing
13 changed files
with
370 additions
and
18 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use super::Symbol; | ||
use crate::{scoped::Scoped, Stage}; | ||
|
||
/// Inverts all symbols inserted by [`SymbolsStage`]. | ||
/// | ||
/// This is guaranteed to be the inverse of [`SymbolsStage`], as the replacements and | ||
/// originals form a [bijection](https://en.wikipedia.org/wiki/Bijection). | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] | ||
#[allow(clippy::module_name_repetitions)] | ||
pub struct SymbolsInversionStage {} | ||
|
||
impl Scoped for SymbolsInversionStage {} | ||
|
||
impl Stage for SymbolsInversionStage { | ||
fn substitute(&self, input: &str) -> String { | ||
input | ||
.chars() | ||
.map(|c| match Symbol::try_from(c) { | ||
Ok(s) => match s { | ||
// This is *horrible* as in the current implementation, we cannot | ||
// access these symbols. They are implicitly encoded in the | ||
// `substitute` method of `SymbolsStage`. As such, this inversion | ||
// can get out of sync with the original. There is a property test | ||
// in place to catch this. | ||
Symbol::EmDash => "---", | ||
Symbol::EnDash => "--", | ||
Symbol::ShortRightArrow => "->", | ||
Symbol::ShortLeftArrow => "<-", | ||
Symbol::LongRightArrow => "-->", | ||
Symbol::LongLeftArrow => "<--", | ||
Symbol::LeftRightArrow => "<->", | ||
Symbol::RightDoubleArrow => "=>", | ||
Symbol::NotEqual => "!=", | ||
Symbol::LessThanOrEqual => "<=", | ||
Symbol::GreaterThanOrEqual => ">=", | ||
} | ||
.into(), | ||
Err(_) => c.to_string(), | ||
}) | ||
.collect() | ||
} | ||
} |
Oops, something went wrong.