## Enter a short description of the script
package Util;

require Exporter;
@ISA    = qw(Exporter);
@EXPORT = qw(
	runOnDirectoryShallow
	    );

# use Memoize;
use strict;
use warnings;

# Accept a directory name and a function reference
# and a set of arguments to be passed to function
# Apply the function to each file in the directory
sub runOnDirectoryShallow{
	my $dir = shift;
	my $funcRef = shift;
	my @arguments = @_;
	die('runOnDirectoryShallow : First argument not a directory !\n') unless(-d $dir);
	
	my $fcount = 0;
	opendir(FDIR,$dir) or die("Couldn't open $dir dir !");
	while(defined(my $file = readdir(FDIR))){
		next if($file =~ /^\.\.?$/);
		next if(-d "$input/$file"); # skip the directories
		$funcRef->($file, @arguments);
		$fcount++;
		print "=" if($fcount % 100 == 0);
	}
}

# Accept a directory name and a function reference
# and a set of arguments to be passed to function
# Apply the function to each file in the directory
sub runOnDirectoryDeep{
	my $prefix = shift;
	my $dir = shift;
	my $funcRef = shift;
	my @arguments = @_;
	die('runOnDirectoryDeep : First argument not a directory !\n') unless(-d $dir);
	
	my $fcount = 0;
	opendir(FDIR,$dir) or die("Couldn't open $dir dir !");
	while(defined(my $file = readdir(FDIR))){
		next if($file =~ /^\.\.?$/);
		if(-d "$input/$file"){
			print "$prefix ->\n"
			runOnDirectoryDeep("$prefix\t","$input/$file", $funcRef, @arguments); # recurse into the directories
			next;
		}
		$funcRef->($file,@arguments);
		$fcount++;
		print "$prefix=" if($fcount % 100 == 0);
	}
	print "\n";
}

# Converts the urdu punctuation to English punctuation
sub convertUrduPunctuations{
	my $string = shift;
	
	$string =~ s/\x{060C}/,/g; #Arabic Comma
	$string =~ s/\x{060D}/-/g; #Arabic Date separater
	$string =~ s/\x{061B}/;/g;
	$string =~ s/\x{061F}/?/g;
	$string =~ s/\x{0640}//g; # tatweel (used to elongate characters for justification)
	$string =~ s/\x{066A}/%/g;
	$string =~ s/\x{066B}/./g; # decimal seperater
	$string =~ s/\x{066C}/,/g; # thousands seperater
	$string =~ s/\x{066D}/*/g; # five point star
	$string =~ s/\x{06D4}/./g; # full stop
	
	return $string;
}

# Converts the urdu punctuation to English punctuation
sub convertUrduNumbers{
	my $string = shift;
	
	$string =~ s/[\x{06F0}\x{0660}]/0/g;
	$string =~ s/[\x{06F1}\x{0661}]/1/g;
	$string =~ s/[\x{06F2}\x{0662}]/2/g;
	$string =~ s/[\x{06F3}\x{0663}]/3/g;
	$string =~ s/[\x{06F4}\x{0664}]/4/g;
	$string =~ s/[\x{06F5}\x{0665}]/5/g;
	$string =~ s/[\x{06F6}\x{0666}]/6/g;
	$string =~ s/[\x{06F7}\x{0667}]/7/g;
	$string =~ s/[\x{06F8}\x{0668}]/8/g;
	$string =~ s/[\x{06F9}\x{0669}]/9/g;
	
	return $string;
}