#!/usr/bin/perl

#the source is utf-8 encoded
use utf8;

#we need locale data
use locale;
#we need to work with romanian utf8 encodings
use POSIX qw(locale_h);

$old_locale = setlocale(LC_ALL);
#setlocale(LC_ALL, "ro_RO.UTF-8");
setlocale(LC_ALL, "ro_RO.ISO-8859-2");

print "\noldlocale was : $old_locale\n";
print "\nnew locale is";
print setlocale(LC_ALL); print "\n";

while (defined($line = <STDIN>)) 
{
	# process $line here
	$line=~s/\b(s)[âî]nt(|em|eţi)\b/\1unt\2/gi;
	
	print "Initial line:\n";
	print $line;
	
	@words = split(/([^[:alpha:]])/,$line);
	foreach $word (@words)
	{
		print "__ $word __";
#		if ( 
#			($word =~ /^((re|ne|de[sz]|(p(re|ost)))?î.*)/i)
#			($word =~ /^reî.*/i)
#			or
#			($word =~ /.*î$/)
#			)
#		{
#			#$word =~ s/î/â/g;
#			#print "\n<<<$word>>>";
#			print "\n!!$word!!";
#		}
#		elsif ( $word =~ /^.+î.+$/)
#		{
#			$word =~ s/î/â/g;
#			print "\n<<<$word>>>";
#		}
			$word = s/\Bî\B/â/ unless /^(re|pre|des|dez)/
			print "\t\t<|$word|>\n";
	}
	

	print "\nJOINED: ";
	print join("",@words);
	
	#$line=~s/\b(!(re|ne|des|dez|pre|post))î\B/\1â/g;
}

setlocale(LC_ALL, "");
setlocale(LC_ALL, $old_locale);


