psyche_subtitle_toolkit/subtitles/model.rs
1/// A parsed subtitle document containing a flat list of cues.
2#[derive(Debug, Clone, PartialEq, Eq)]
3pub struct SubtitleDocument {
4 /// Ordered list of subtitle cues.
5 pub cues: Vec<SubtitleCue>,
6}
7
8impl SubtitleDocument {
9 /// Replace the text of the cue with the given `id`.
10 ///
11 /// Returns `true` if the cue was found and replaced, `false` if no cue
12 /// with that ID exists.
13 pub fn replace_text(&mut self, id: usize, text: String) -> bool {
14 if let Some(cue) = self.cues.iter_mut().find(|cue| cue.id == id) {
15 cue.text = text;
16 true
17 } else {
18 false
19 }
20 }
21}
22
23/// A single subtitle cue with a sequential ID and decoded text.
24///
25/// IDs are assigned sequentially starting from 1 during ASS parsing.
26/// The `text` field contains decoded text (literal `\n` for newlines,
27/// no ASS `\N` escapes). Override tags like `{\pos(...)}` are stripped
28/// during translation and re-injected afterward.
29#[derive(Debug, Clone, PartialEq, Eq)]
30pub struct SubtitleCue {
31 /// Sequential cue identifier (1-based).
32 pub id: usize,
33 /// Decoded subtitle text.
34 pub text: String,
35}