From 34d0d048cd0eb1a50bff7f845c166f36ec0c081c Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Mon, 23 Jul 2018 20:37:58 +1000 Subject: [PATCH] * Subtitle::SSA : minor optimizations --- lib/Subtitle/SSA.pm | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/Subtitle/SSA.pm b/lib/Subtitle/SSA.pm index 362d572..17efa76 100644 --- a/lib/Subtitle/SSA.pm +++ b/lib/Subtitle/SSA.pm @@ -36,7 +36,7 @@ sub new_event { ... } sub parse { my ($self, $lines) = @_; my $linenum = 0; - my $section; + my ($section, $font); foreach my $line (@$lines) { $linenum++; @@ -46,7 +46,7 @@ sub parse { study $line; # check section switch - if ($line =~ m/^\s*\[\s*([a-z0-9+ ]+)\s*\]\s*$/io) { + if (index($line, '[') >= 0 and $line =~ m/^\[([a-zA-Z0-9+ ]+)\]\s*$/o) { my $name = lc($1); if ($name =~ m{script \s+ info}oix) { $section = 'header'; @@ -67,25 +67,25 @@ sub parse { $self->log(debug => "section changed to [$section] at line $linenum"); next; } - # - unless ($section) { - $self->log(warn => "Line $linenum outside any section, skip"); - next; - } + # parse fonts data if ($section eq 'fonts') { - if ($line =~ m/^fontname:\s*(.*)/i) { - my $font = Subtitle::SSA::File->new; + if (index($line, 'fontname:') == 0) { + $line =~ m/^fontname:\s*(.*)/o; + $font = Subtitle::SSA::File->new; $font->type('font'); $font->name($1); push @{ $self->{fonts} }, $font; next; - } - my $curr = $self->{fonts}->[-1] - or next; # missing 'fontname' line? - $curr->add_uue_line($line); + } elsif ($font) { + $font->add_uue_line($line); + } # else: missing 'fontname' line, skip next; } # TODO: graphics section + unless ($section) { + $self->log(warn => "Line $linenum outside any section, skip"); + next; + } # skip comments next if $line =~ m{^ \s* ;}xo; if ($section eq 'header') {