# $Id$ # Common bot backend things. package Util::Common; use warnings; use strict; use Exporter; use base qw(Exporter); use vars qw(@EXPORT_OK); @EXPORT_OK = qw( try_uptime break_into_sentences ); ### Split an utterance into sentences. sub break_into_sentences { my $text = shift; # Remove leading, trailing whitespace. $text =~ s/^\s+//; $text =~ s/\s+$//; # Remove mIRC colors and control characters. $text =~ s/\x03\d+,?\d*//g; $text =~ tr[\x00-\x1f][]d; # Add sentence separators to the text. $text =~ s/(?<=[^\.\?\!][\.\?\!])\s+/\0/g; # Remove sentence separators that are after things that can't end # sentences. $text =~ s/(\b[a-z]\.)\0/$1 /ig; $text =~ s/(Mrs|Mr|Ms|Dr)\.\0/$1. /ig; $text =~ s/\<\?\0/ $precision; # Combine the parts. join(' ', @fields); } 1;