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') {