forge
Explore
Log in

Don't you dare go Hollow

S13: ec-ass WrapStyle enum replaces the u8 (only value 2 changes behaviour, as before)

Browse files at this commit

f75aa7dd474ef195ae99a2fc0fdad52cfda9449fAhmet Kaan GümüşParent: 0cbcc3a
crates/ec-ass/src/lib.rsmodified+21 -6
@@ -42,7 +42,7 @@ pub fn parse(bytes: &[u8]) -> Result<SubtitleTrack> {
4242 let mut saw_events = false;
4343 // `WrapStyle` is read once, when its line is seen; scanning the metadata for
4444 // every Dialogue line instead made a long script quadratic.
45- let mut wrap_style = 0u8;
45+ let mut wrap_style = WrapStyle::Auto;
4646 let mut wrap_seen = false;
4747 for line in text.split_inclusive('\n') {
4848 let trimmed = line.trim();
@@ -70,7 +70,7 @@ pub fn parse(bytes: &[u8]) -> Result<SubtitleTrack> {
7070 let key = snake_case(key);
7171 // The first `WrapStyle` line counts, as it always did.
7272 if key == "wrap_style" && !wrap_seen {
73- wrap_style = value.parse::<u8>().unwrap_or(0);
73+ wrap_style = WrapStyle::parse(value);
7474 wrap_seen = true;
7575 }
7676 track.metadata.push((key, value.to_owned()));
@@ -228,7 +228,7 @@ fn parse_color(value: &str) -> Option<(u8, u8, u8, u8)> {
228228 ))
229229 }
230230
231-fn dialogue(format: &[String], row: &str, wrap_style: u8) -> Option<SubtitleCue> {
231+fn dialogue(format: &[String], row: &str, wrap_style: WrapStyle) -> Option<SubtitleCue> {
232232 const DEFAULT: &str = "Layer,Start,End,Style,Name,MarginL,MarginR,MarginV,Effect,Text";
233233 let fallback = fields(DEFAULT);
234234 let format = if format.is_empty() { &fallback } else { format };
@@ -276,7 +276,7 @@ struct Overrides {
276276 }
277277
278278 /// One `Text` field into runs, plus whatever positioning its overrides state.
279-fn body(text: &str, wrap_style: u8) -> (Vec<Segment>, Option<CuePosition>) {
279+fn body(text: &str, wrap_style: WrapStyle) -> (Vec<Segment>, Option<CuePosition>) {
280280 let mut out: Vec<Segment> = Vec::new();
281281 let mut state = Overrides::default();
282282 let mut position = CuePosition::default();
@@ -445,12 +445,27 @@ fn split_tag(tag: &str) -> Option<(&str, &str)> {
445445 }
446446
447447 /// Plain text between override blocks, with the three escapes ASS gives it.
448+#[derive(Clone, Copy, PartialEq, Eq)]
449+enum WrapStyle {
450+ Auto,
451+ Manual,
452+}
453+
454+impl WrapStyle {
455+ fn parse(value: &str) -> WrapStyle {
456+ match value.parse::<u8>() {
457+ Ok(2) => WrapStyle::Manual,
458+ _ => WrapStyle::Auto,
459+ }
460+ }
461+}
462+
448463 fn push_text(
449464 out: &mut Vec<Segment>,
450465 run: &mut String,
451466 text: &str,
452467 state: &Overrides,
453- wrap_style: u8,
468+ wrap_style: WrapStyle,
454469 ) {
455470 let mut chars = text.chars().peekable();
456471 while let Some(c) = chars.next() {
@@ -466,7 +481,7 @@ fn push_text(
466481 flush(out, run, state);
467482 out.push(Segment::LineBreak);
468483 }
469- Some('n') if wrap_style == 2 => {
484+ Some('n') if wrap_style == WrapStyle::Manual => {
470485 flush(out, run, state);
471486 out.push(Segment::LineBreak);
472487 }