]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Modules/piglatin.pl
avoid reassigning to temp upon decode_utf8
[infobot.git] / src / Modules / piglatin.pl
index 07d17b8acbff06221789c82ff238bd4581a4cfc6..a995e5707d8a1de8efcce70c58d8b61abdc1431b 100644 (file)
@@ -6,33 +6,46 @@ use warnings;
 
 package piglatin;
 
-sub piglatin
-{
-  my ($text) = @_;
-  my $piglatin;
-  my $suffix = 'ay';
+sub piglatin {
+    my ($text) = @_;
+    my $piglatin;
+    my $suffix = 'ay';
 
-  # FIXME: does not handle:
-  #  punctuation and hyphens
-  #  y as vowel "style" -> "ylestay"
-  #  contractions
-  for my $word (split /\s+/, $text) {
-    my $pigword;
-    if ($word =~ /^(qu)(.*)/ ) {
-      $pigword = "$2$1$suffix";
-    } elsif ($word =~ /^(Qu)(.)(.*)/ ) {
-      $pigword = uc($2) . $3 . lc($1) . $suffix;
-    } elsif ($word =~ /^([bcdfghjklmnpqrstvwxyz]+)(.*)/ ) {
-      $pigword = "$2$1$suffix";
-    } elsif ($word =~ /^([BCDFGHJKLMNPQRSTVWXYZ])([bcdfghjklmnpqrstvwxyz]*)([aeiouy])(.*)/ ) {
-      $pigword = uc($3) . $4 . lc($1) . $2 . $suffix;
-    } else {
-      $pigword = $word . 'w' . $suffix;
+    # FIXME: does not handle:
+    #  non-trailing punctuation and hyphens
+    #  y as vowel 'style' -> 'ylestay'
+    #  contractions
+    for my $word ( split /\s+/, $text ) {
+        my ( $pigword, $postfix );
+
+        #($word,$postfix) = $word =~ s/^([a-z]*)([,.!\?;:'"])?$//i;
+        if ( $word =~ s/([,.!\?;:'"])$//i ) {
+            $postfix = $1;
+        }
+        if ( $word =~ /^(qu)(.*)/ ) {
+            $pigword = "$2$1$suffix";
+        }
+        elsif ( $word =~ /^(Qu)(.)(.*)/ ) {
+            $pigword = uc($2) . $3 . lc($1) . $suffix;
+        }
+        elsif ( $word =~ /^([bcdfghjklmnpqrstvwxyz]+)(.*)/ ) {
+            $pigword = "$2$1$suffix";
+        }
+        elsif ( $word =~
+            /^([BCDFGHJKLMNPQRSTVWXYZ])([bcdfghjklmnpqrstvwxyz]*)([aeiouy])(.*)/
+          )
+        {
+            $pigword = uc($3) . $4 . lc($1) . $2 . $suffix;
+        }
+        else {
+            $pigword = $word . 'w' . $suffix;
+        }
+        $piglatin .= ' ' if $piglatin;
+        $piglatin .= $pigword . $postfix;
     }
-    $piglatin .= ' ' if $piglatin;
-    $piglatin .= $pigword;
-  }
-  &::performStrictReply($piglatin||'failed');
+    &::performStrictReply( $piglatin || 'failed' );
 }
 
 1;
+
+# vim:ts=4:sw=4:expandtab:tw=80