X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FMisc.pm;h=9aeff93a683d66173d841057ccc16881ad9a51f7;hb=b37cafd2acd4ab2c38b44bc4d8ebde76936ef6bb;hp=f597058ef0810e24b2406402a1fdeda97aaa8036;hpb=6c284750de8fe49d7d4cdc6a9a4fb618697780e2;p=freeside.git diff --git a/FS/FS/Misc.pm b/FS/FS/Misc.pm index f597058ef..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; @@ -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