From f75aa7dd474ef195ae99a2fc0fdad52cfda9449f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 2 Dec 2026 15:14:00 +0300 Subject: [PATCH] S13: ec-ass WrapStyle enum replaces the u8 (only value 2 changes behaviour, as before) --- crates/ec-ass/src/lib.rs | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/crates/ec-ass/src/lib.rs b/crates/ec-ass/src/lib.rs index cfa54674..070116ab 100644 --- a/crates/ec-ass/src/lib.rs +++ b/crates/ec-ass/src/lib.rs @@ -42,7 +42,7 @@ pub fn parse(bytes: &[u8]) -> Result { let mut saw_events = false; // `WrapStyle` is read once, when its line is seen; scanning the metadata for // every Dialogue line instead made a long script quadratic. - let mut wrap_style = 0u8; + let mut wrap_style = WrapStyle::Auto; let mut wrap_seen = false; for line in text.split_inclusive('\n') { let trimmed = line.trim(); @@ -70,7 +70,7 @@ pub fn parse(bytes: &[u8]) -> Result { let key = snake_case(key); // The first `WrapStyle` line counts, as it always did. if key == "wrap_style" && !wrap_seen { - wrap_style = value.parse::().unwrap_or(0); + wrap_style = WrapStyle::parse(value); wrap_seen = true; } track.metadata.push((key, value.to_owned())); @@ -228,7 +228,7 @@ fn parse_color(value: &str) -> Option<(u8, u8, u8, u8)> { )) } -fn dialogue(format: &[String], row: &str, wrap_style: u8) -> Option { +fn dialogue(format: &[String], row: &str, wrap_style: WrapStyle) -> Option { const DEFAULT: &str = "Layer,Start,End,Style,Name,MarginL,MarginR,MarginV,Effect,Text"; let fallback = fields(DEFAULT); let format = if format.is_empty() { &fallback } else { format }; @@ -276,7 +276,7 @@ struct Overrides { } /// One `Text` field into runs, plus whatever positioning its overrides state. -fn body(text: &str, wrap_style: u8) -> (Vec, Option) { +fn body(text: &str, wrap_style: WrapStyle) -> (Vec, Option) { let mut out: Vec = Vec::new(); let mut state = Overrides::default(); let mut position = CuePosition::default(); @@ -445,12 +445,27 @@ fn split_tag(tag: &str) -> Option<(&str, &str)> { } /// Plain text between override blocks, with the three escapes ASS gives it. +#[derive(Clone, Copy, PartialEq, Eq)] +enum WrapStyle { + Auto, + Manual, +} + +impl WrapStyle { + fn parse(value: &str) -> WrapStyle { + match value.parse::() { + Ok(2) => WrapStyle::Manual, + _ => WrapStyle::Auto, + } + } +} + fn push_text( out: &mut Vec, run: &mut String, text: &str, state: &Overrides, - wrap_style: u8, + wrap_style: WrapStyle, ) { let mut chars = text.chars().peekable(); while let Some(c) = chars.next() { @@ -466,7 +481,7 @@ fn push_text( flush(out, run, state); out.push(Segment::LineBreak); } - Some('n') if wrap_style == 2 => { + Some('n') if wrap_style == WrapStyle::Manual => { flush(out, run, state); out.push(Segment::LineBreak); }