Skip to content

Commit 3eb91f0

Browse files
committed
Fix testcase
1 parent ba09622 commit 3eb91f0

28 files changed

Lines changed: 1460 additions & 175 deletions

libs/braillify/src/encoder.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ impl Encoder {
8484
token_engine.register(Box::new(
8585
rules::token_rules::middle_korean_detector::MiddleKoreanDetectorRule,
8686
));
87+
token_engine.register(Box::new(
88+
rules::token_rules::historical_gloss_spacing::HistoricalGlossSpacingRule,
89+
));
8790
token_engine.register(Box::new(rules::token_rules::normalize::NormalizeEllipsis));
8891
token_engine.register(Box::new(rules::token_rules::latex_math::LatexMergeRule));
8992
token_engine.register(Box::new(
@@ -105,6 +108,9 @@ impl Encoder {
105108
token_engine.register(Box::new(
106109
rules::token_rules::roman_numeral::RomanNumeralRule,
107110
));
111+
token_engine.register(Box::new(
112+
rules::token_rules::digital_notation::DigitalNotationRule,
113+
));
108114
token_engine.register(Box::new(
109115
rules::token_rules::uppercase_passage::UppercasePassageRule,
110116
));
@@ -157,7 +163,9 @@ impl Encoder {
157163

158164
let state_before_token_rules = ir.state.clone();
159165
self.token_engine.apply_all(&mut ir.tokens, &mut ir.state)?;
166+
let mode_stack_after_token_rules = ir.state.mode_stack.clone();
160167
ir.state = state_before_token_rules;
168+
ir.state.mode_stack = mode_stack_after_token_rules;
161169
transform(text, &mut ir.tokens)?;
162170

163171
let output = rules::emit::emit(&mut ir, &mut self.rule_engine)?;

libs/braillify/src/english_logic.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,22 @@ pub(crate) fn is_english_symbol(symbol: char) -> bool {
6969
/// 단일 소문자 단어가 연속될 때 연속표가 필요한지 판단한다.
7070
/// [통일 영어 점자 - 5.2 1급 점자 기호표(⠰)] : 글자 a, i, o 앞에는 1급 점자 기호표가 필요하지 않다.
7171
pub(crate) fn requires_single_letter_continuation(letter: char) -> bool {
72-
letter.is_ascii_lowercase() && !matches!(letter, 'a' | 'i' | 'o')
72+
letter.is_ascii_alphabetic() && !matches!(letter.to_ascii_lowercase(), 'a' | 'i' | 'o')
7373
}
7474

7575
fn is_ascii_letter_or_digit(ch: Option<char>) -> bool {
7676
ch.is_some_and(|c| c.is_ascii_alphanumeric())
7777
}
7878

79+
fn is_digital_notation_symbol(symbol: char) -> bool {
80+
matches!(symbol, '/' | '@' | '#' | '.' | '_' | ':')
81+
}
82+
83+
fn has_digital_notation_signature(word_chars: &[char]) -> bool {
84+
let text: String = word_chars.iter().collect();
85+
text.contains("//") || text.contains('@') || text.contains('#') || text.contains('_')
86+
}
87+
7988
pub(crate) fn prev_ascii_letter_or_digit(word_chars: &[char], index: usize) -> bool {
8089
let mut j = index;
8190
while j > 0 {
@@ -167,10 +176,31 @@ pub(crate) fn should_render_symbol_as_english(
167176

168177
prev_ascii && next_ascii
169178
}
179+
'/' | '@' | '#' | '.' | '_' | ':' | '-' => {
180+
let prev_ascii = prev_ascii_letter_or_digit(word_chars, index);
181+
let next_ascii = next_ascii_letter_or_digit(word_chars, index, remaining_words);
182+
183+
(prev_ascii && next_ascii)
184+
|| (symbol == '/' && prev_char == Some('/') && next_ascii)
185+
|| (symbol == '/' && next_char == Some('/') && prev_ascii)
186+
}
170187
_ => false,
171188
}
172189
}
173190

191+
pub(crate) fn should_keep_english_mode_for_symbol(
192+
symbol: char,
193+
word_chars: &[char],
194+
index: usize,
195+
remaining_words: &[&str],
196+
) -> bool {
197+
if !is_digital_notation_symbol(symbol) || !has_digital_notation_signature(word_chars) {
198+
return false;
199+
}
200+
201+
should_render_symbol_as_english(true, true, &[], symbol, word_chars, index, remaining_words)
202+
}
203+
174204
#[cfg(test)]
175205
mod tests {
176206
use super::*;

0 commit comments

Comments
 (0)