|
|
|
@ -51,10 +51,12 @@ sub parse_format_line {
|
|
|
|
|
# formats: |
|
|
|
|
# s - string, use as is |
|
|
|
|
# d - decimal, no-zero pad |
|
|
|
|
# b - boolean, 0 as false, -1 as true |
|
|
|
|
# t - timing, like H:MM:SS.MSEC |
|
|
|
|
# f - float, 6.01 or 6 if no fractional part |
|
|
|
|
# x - hex-number, &H00AABBCC for ASS or decimal number for SSA |
|
|
|
|
# special cases: |
|
|
|
|
# b - boolean, 0 as false, -1 as true (used in styles) |
|
|
|
|
# z - same as decimal, but zero-padded to 4 digits (used in dialigue, for offset in pixels) |
|
|
|
|
sub parse { |
|
|
|
|
my ($self, $line, $format) = @_; |
|
|
|
|
$format //= $self->{_format}; |
|
|
|
@ -78,6 +80,8 @@ sub parse {
|
|
|
|
|
my $value = shift @values; |
|
|
|
|
if ($d->{type} eq 'x' and $value =~ m<&H([0-9a-f]{8})>oi) { |
|
|
|
|
$value = hex($1); |
|
|
|
|
} elsif ($d->{type} eq 'z') { |
|
|
|
|
$value = int($value); |
|
|
|
|
} elsif ($d->{type} eq 't') { |
|
|
|
|
$value = parse_timing($value); |
|
|
|
|
return $self->error("can't parse timing: $value") |
|
|
|
@ -102,6 +106,8 @@ sub to_string {
|
|
|
|
|
$v = sprintf "%.2f", $v; |
|
|
|
|
# hack: make decimal from float if fractional part is zero after round up |
|
|
|
|
$v =~ s{\.00$}{}oi; |
|
|
|
|
} elsif ($d->{type} eq 'z') { |
|
|
|
|
$v = sprintf "%04d", $v; |
|
|
|
|
} elsif ($d->{type} eq 't') { |
|
|
|
|
my ($h, $m, $s, $ms) = make_timing($v); |
|
|
|
|
$v = sprintf("%d:%02d:%02d.%02d", $h, $m, $s, int($ms / 10)); |
|
|
|
|