use crate::processors::base::BaseProcessor;
use crate::subripfile::{SubRipFile, SubtitleError};
pub const RTL_LANGUAGES: &[&str] = &["ar", "fa", "he", "ps", "syc", "ug", "ur"];
pub const RTL_CONTROL_CHARS: &[char] = &[
'\u{200e}', '\u{200f}', '\u{202a}', '\u{202b}', '\u{202c}', '\u{202d}', '\u{202e}',
];
pub const RTL_CHAR: char = '\u{202b}';
#[derive(Debug)]
pub struct RTLFixer;
impl RTLFixer {
pub fn new() -> Self {
Self
}
fn correct_subtitles(&self, mut srt: SubRipFile) -> SubRipFile {
for subtitle in srt.iter_mut() {
for &control_char in RTL_CONTROL_CHARS {
subtitle.content = subtitle.content.replace(control_char, "");
}
subtitle.content = format!(
"{}{}",
RTL_CHAR,
subtitle.content.replace('\n', &format!("\n{}", RTL_CHAR))
);
}
srt
}
}
impl Default for RTLFixer {
fn default() -> Self {
Self::new()
}
}
impl BaseProcessor for RTLFixer {
fn process(
&self,
srt: SubRipFile,
_language: Option<&str>,
) -> Result<(SubRipFile, bool), SubtitleError> {
let corrected = self.correct_subtitles(srt);
Ok((corrected, false))
}
}