package Lingua::Ipa;

require 5.005_62;
use strict;
#use warnings;
no warnings;

require Exporter;

our @ISA = qw(Exporter);

our @EXPORT = qw(
 &sampa2uniipa
 &uniipa2sampa
 &uniipa2latextipa
 &sampa2latextipa
	
);
our $VERSION = '0.01';

use utf8;

sub sampa2latextipa{ uniipa2latextipa(sampa2uniipa(shift))}

sub sampa2uniipa{ my $c=shift;
            $c =~ s/N/\x{14B}/g;
            $c =~ s/9/\x{153}/g;
            $c =~ s/6/\x{250}/g;
            $c =~ s/A/\x{251}/g;
            $c =~ s/Q/\x{252}/g;
            $c =~ s/O/\x{254}/g;
            $c =~ s/d`/\x{256}/g;
            $c =~ s/\@/\x{259}/g;
            $c =~ s/E/\x{25B}/g;
            $c =~ s/3/\x{25C}/g;
            $c =~ s/G/\x{263}/g;
            $c =~ s/7/\x{264}/g;
            $c =~ s/H/\x{265}/g;
            $c =~ s/1/\x{268}/g;
            $c =~ s/I/\x{26A}/g;
            $c =~ s/5/\x{26B}/g;
            $c =~ s/M/\x{26F}/g;
            $c =~ s/F/\x{271}/g;
            $c =~ s/J/\x{272}/g;
            $c =~ s/8/\x{275}/g;
            $c =~ s/\&/\x{276}/g;
            $c =~ s/4/\x{27E}/g;
            $c =~ s/R/\x{281}/g;
            $c =~ s/S/\x{283}/g;   #{
            $c =~ s/\}/\x{289}/g;
            $c =~ s/U/\x{28A}/g;
            $c =~ s/P/\x{28B}/g;
            $c =~ s/V/\x{28C}/g;
            $c =~ s/W/\x{28D}/g;
            $c =~ s/L/\x{28E}/g;
            $c =~ s/Z/\x{292}/g;
            $c =~ s/\?/\x{294}/g;
            $c =~ s/\"/\x{2C8}/g;
            $c =~ s/:/\x{2D0}/g;
            $c =~ s/B/\x{3B2}/g;
            $c =~ s/T/\x{3B8}/g;
#            $c =~ s/ /\x{3BB}/g;  #lambda
            $c =~ s/X/\x{3C7}/g;
            $c =~ s/D/\x{F0}/g;
            $c =~ s/2/\x{F8}/g;
            $c =~ s/\{/\x{E6}/g;   #}
            $c =~ s/C/\x{E7}/g;
         $c}

sub uniipa2sampa { my $c=shift;
            $c =~ s/\x{14B}/N/g;
            $c =~ s/\x{153}/9/g;
            $c =~ s/\x{250}/6/g;
            $c =~ s/\x{251}/A/g;
            $c =~ s/\x{252}/Q/g;
            $c =~ s/\x{254}/O/g;
            $c =~ s/\x{256}/d`/g;
            $c =~ s/\x{259}/\@/g;
            $c =~ s/\x{25B}/E/g;
            $c =~ s/\x{25C}/3/g;
            $c =~ s/\x{263}/G/g;
            $c =~ s/\x{264}/7/g;
            $c =~ s/\x{265}/H/g;
            $c =~ s/\x{268}/1/g;
            $c =~ s/\x{26A}/I/g;
            $c =~ s/\x{26B}/5/g;
            $c =~ s/\x{26F}/M/g;
            $c =~ s/\x{271}/F/g;
            $c =~ s/\x{272}/J/g;
            $c =~ s/\x{275}/8/g;
            $c =~ s/\x{276}/\&/g;
            $c =~ s/\x{27E}/4/g;
            $c =~ s/\x{281}/R/g;
            $c =~ s/\x{283}/S/g;   #{
            $c =~ s/\x{289}/\}/g;
            $c =~ s/\x{28A}/U/g;
            $c =~ s/\x{28B}/P/g;
            $c =~ s/\x{28C}/V/g;
            $c =~ s/\x{28D}/W/g;
            $c =~ s/\x{28E}/L/g;
            $c =~ s/\x{292}/Z/g;
            $c =~ s/\x{294}/?/g;
            $c =~ s/\x{2C8}/"/g;
            $c =~ s/\x{2D0}/:/g;
            $c =~ s/\x{3B2}/B/g;
            $c =~ s/\x{3B8}/T/g;
#            $c =~ s/\x{3BB}/ /g;  #lambda
            $c =~ s/\x{3C7}/X/g;
            $c =~ s/\x{F0}/D/g;
            $c =~ s/\x{F8}/2/g;
            $c =~ s/\x{E6}/\{/g;   #}
            $c =~ s/\x{E7}/C/g;
         $c}

sub uniipa2latextipa { my $c=shift;
            $c =~ s/(.)\~/\\~$1/g;
            $c =~ s/\\\~([ij])/\\\~{\\$1}/g;

            $c =~ s/\x{14B}/N/g;
            $c =~ s/\x{153}/\\oe{}/g;
            $c =~ s/\x{250}/5/g;
            $c =~ s/\x{251}/A/g;
            $c =~ s/\x{252}/6/g;
            $c =~ s/\x{254}/O/g;
            $c =~ s/\x{256}/\\:d/g;
            $c =~ s/\x{259}/\@/g;
            $c =~ s/\x{25B}/E/g;
            $c =~ s/\x{25C}/3/g;
            $c =~ s/\x{263}/G/g;
            $c =~ s/\x{264}/7/g;
            $c =~ s/\x{265}/\\*h/g;
            $c =~ s/\x{268}/1/g;
            $c =~ s/\x{26A}/I/g;
            $c =~ s/\x{26B}/\\textbarl /g;
            $c =~ s/\x{26F}/W/g;
            $c =~ s/\x{271}/M/g;
            $c =~ s/\x{272}/\\textltailn /g;
            $c =~ s/\x{275}/8/g;
            $c =~ s/\x{276}/\\OE{}/g;
            $c =~ s/\x{27E}/R/g;
            $c =~ s/\x{281}/K/g;
            $c =~ s/\x{283}/S/g;
            $c =~ s/\x{289}/0/g;
            $c =~ s/\x{28A}/U/g;
            $c =~ s/\x{28B}/V/g;
            $c =~ s/\x{28C}/2/g;
            $c =~ s/\x{28D}/\\*W/g;
            $c =~ s/\x{28E}/L/g;
            $c =~ s/\x{292}/Z/g;
            $c =~ s/\x{294}/P/g;
            $c =~ s/\x{2C8}/"/g;
            $c =~ s/\x{2D0}/:/g;
            $c =~ s/\x{3B2}/B/g;
            $c =~ s/\x{3B8}/T/g;
            $c =~ s/\x{3BB}/\\textlambda /g;  #lambda
            $c =~ s/\x{3C7}/X/g;
            $c =~ s/\x{F0}/D/g;
            $c =~ s/\x{F8}/\\o /g;
            $c =~ s/\x{E6}/\\ae{}/g;
            $c =~ s/\x{E7}/\\c{c}/g;
            "\\textipa{$c}";
}

1;
__END__

=head1 NAME

Lingua::Ipa - Perl extension for translation between SAMPA, UNICODE e LateX

=head1 SYNOPSIS

  use Lingua::Ipa;
  $a = sampa2uniipa(sampaString)
  $b = uniipa2sampa(unicodeString)
  $c = uniipa2latextipa(unicodeString)
  $d = sampa2latextipa(sampaString)

=head1 DESCRIPTION

=head2 EXPORT
  
sampa2uniipa

 converts SAMPA to unicode

uniipa2sampa

 converts unicode to SAMPA 

uniipa2latextipa

 converts unicode to LateX

sampa2latextipa

 converts SAMPA to LateX

=head1 AUTHOR

Jose Joao Almeida jj@di.uminho.pt

=head1 SEE ALSO

perl(1).
latex tipa.
unicode(7).
SAMPA.

=cut
