X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FMisc.pm;h=9aeff93a683d66173d841057ccc16881ad9a51f7;hb=ba92d105395292725e293f79a561d22902c13a91;hp=036c32d4ed02ba7d5edec089c5ddde6fcffcd768;hpb=f13c9d8580d02851b150e21ea9beb6fc1dfbd3c8;p=freeside.git diff --git a/FS/FS/Misc.pm b/FS/FS/Misc.pm index 036c32d4e..9aeff93a6 100644 --- a/FS/FS/Misc.pm +++ b/FS/FS/Misc.pm @@ -22,6 +22,7 @@ use Encode; generate_ps generate_pdf do_print csv_from_fixed ocr_image + bytes_substr ); $DEBUG = 0; @@ -255,9 +256,9 @@ sub send_email { push @to, $options{bcc} if defined($options{bcc}); local $@; # just in case -# eval { sendmail($message, { transport => $transport, -# from => $from, -# to => \@to }) }; + eval { sendmail($message, { transport => $transport, + from => $from, + to => \@to }) }; my $error = ''; if(ref($@) and $@->isa('Email::Sender::Failure')) { @@ -961,6 +962,26 @@ sub ocr_image { @lines; } +=item bytes_substr STRING, OFFSET[, LENGTH[, REPLACEMENT] ] + +A replacement for "substr" that counts raw bytes rather than logical +characters. Unlike "bytes::substr", will suppress fragmented UTF-8 characters +rather than output them. Unlike real "substr", is not an lvalue. + +=cut + +sub bytes_substr { + my ($string, $offset, $length, $repl) = @_; + my $bytes = substr( + Encode::encode('utf8', $string), + $offset, + $length, + Encode::encode('utf8', $repl) + ); + my $chk = $DEBUG ? Encode::FB_WARN : Encode::FB_QUIET; + return Encode::decode('utf8', $bytes, $chk); +} + =back =head1 BUGS