From 4d77036a50e47990d70424c731cf9baa6c43450b Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Mon, 23 Jul 2018 00:52:15 +1000 Subject: [PATCH] * Subtitle::SSA : improve section switching --- lib/Subtitle/SSA.pm | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/Subtitle/SSA.pm b/lib/Subtitle/SSA.pm index 0f52da6..e48c0db 100644 --- a/lib/Subtitle/SSA.pm +++ b/lib/Subtitle/SSA.pm @@ -44,11 +44,11 @@ sub parse { study $line; # check section switch - if ($line =~ m/^\s*\[(.+)\]\s*/o) { - my $name = $1; + if ($line =~ m/^\s*\[\s*([a-z0-9+ ]+)\s*\]\s*$/io) { + my $name = lc($1); if ($name =~ m{script \s+ info}oix) { $section = 'header'; - } elsif ($name =~ m{events}oi) { + } elsif ($name eq 'events') { $section = 'events'; } elsif ($name =~ m{v4(\+)? \s+ styles}oix) { $section = 'styles'; @@ -57,9 +57,10 @@ sub parse { $self->log(warn => "Set type to $self->{type} because of line $linenum (fallback mode)"); } } else { - undef $section; - $self->log(debug => "Unknown section at line $linenum: $line"); + $section = 'unknown'; + $self->log(warn => "Unknown section at line $linenum: $line"); } + $self->log(debug => "section changed to [$section] at line $linenum"); next; } #