ass_core/parser/streaming/state/section_kind.rs
1//! Section classification for the streaming parser state machine.
2//!
3//! Defines [`SectionKind`], identifying which ASS script section is currently
4//! being parsed to enable context-aware processing.
5
6/// Section types for state tracking
7///
8/// Identifies which ASS script section is currently being parsed
9/// to enable context-aware processing.
10#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub enum SectionKind {
12 /// [Script Info] section with metadata
13 ScriptInfo,
14 /// [V4+ Styles] or [V4 Styles] section
15 Styles,
16 /// `[Events\]` section with dialogue/timing
17 Events,
18 /// `[Fonts\]` section with embedded fonts
19 Fonts,
20 /// `[Graphics\]` section with embedded images
21 Graphics,
22 /// Unknown or unsupported section
23 Unknown,
24}
25
26impl SectionKind {
27 /// Parse section kind from header text
28 ///
29 /// Returns appropriate `SectionKind` for known section headers,
30 /// Unknown for unrecognized sections.
31 ///
32 /// # Example
33 ///
34 /// ```rust
35 /// # use ass_core::parser::streaming::SectionKind;
36 /// assert_eq!(SectionKind::from_header("Script Info"), SectionKind::ScriptInfo);
37 /// assert_eq!(SectionKind::from_header("V4+ Styles"), SectionKind::Styles);
38 /// assert_eq!(SectionKind::from_header("Unknown"), SectionKind::Unknown);
39 /// ```
40 #[must_use]
41 pub fn from_header(header: &str) -> Self {
42 match header.trim() {
43 "Script Info" => Self::ScriptInfo,
44 "V4+ Styles" | "V4 Styles" => Self::Styles,
45 "Events" => Self::Events,
46 "Fonts" => Self::Fonts,
47 "Graphics" => Self::Graphics,
48 _ => Self::Unknown,
49 }
50 }
51
52 /// Check if section expects format line
53 #[must_use]
54 pub const fn expects_format(&self) -> bool {
55 matches!(self, Self::Styles | Self::Events)
56 }
57
58 /// Check if section contains timed content
59 #[must_use]
60 pub const fn is_timed(&self) -> bool {
61 matches!(self, Self::Events)
62 }
63
64 /// Check if section contains binary data
65 #[must_use]
66 pub const fn is_binary(&self) -> bool {
67 matches!(self, Self::Fonts | Self::Graphics)
68 }
69}