# -*- coding: utf-8; -*-

package AVTools;
use warnings;
use strict;
use utf8; # to upgrade utf-8 strings in this file

BEGIN {
    use Exporter ();

    our ($VERSION, @ISA, @EXPORT);
    $VERSION = 1.00;                    # version for version checking
    @ISA = qw(Exporter);
    @EXPORT = qw(tx_add regexptest)
}


sub date2db {
    my ($tx ) = @_;

    $tx && $tx =~ /^\s*(\d+)\.(\d+)\.(\d+)\s*$/ ? "$3-$2-$1" : $tx;
}

sub db2date {
    my ($tx ) = @_;

    $tx && $tx =~ /^\s*(\d+)-(\d+)-(\d+)\s*$/ ? "$3.$2.$1" : $tx;
}


sub name2file {
    my ($tx, $num, $count) = @_;


    defined( $tx ) or $tx = '';
    $tx =~ s/\"//g;
    $tx =~ s/\!//g;

    $tx =~ s/^\s*//;
    $tx =~ s/\s*$//;
    $tx =~ s/\s+/ /sg;

    my $name = cs2asc( $tx );

    $name =~ s/(\S):(\s)/$1 -$2/g;

    if( $count ) {
        $count > 9 and $num < 10 and $num = "0$num";
    }

    $name = $name ? ( $num ? "$num $name" : "$name" ) : "$num";
        
    return $name;
}


sub cs2asc {
    my ($t) = @_;

    $t =~ tr
        [áčďéěíňóřšťúůýžÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]
        [acdeeinorstuuyzACDEEINORSTUUYZ];
    $t;
}

1;
