| 1 | package MARC::File::Utils; | ||
| 2 | |||
| 3 | =head1 Functions | ||
| 4 | |||
| 5 | =head2 byte_substr( $str, $pos, $len ) | ||
| 6 | |||
| 7 | A utf8-safe version of C<substr()>. | ||
| 8 | |||
| 9 | =cut | ||
| 10 | |||
| 11 | sub byte_substr { | ||
| 12 | 30 | ▶ | use Encode; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | 30 | ▶ | use bytes; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 14 | 0 | ▶ | my ( $str, $pos, $len ) = @_; |
|
Subroutine
byte_substr: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 15 | 0 | my $utf8 = substr( $str, $pos, $len ); | |
| 16 | 0 | return decode( 'utf8', $utf8 ); | |
| 17 | } | ||
| 18 | |||
| 19 | =head2 byte_length | ||
| 20 | |||
| 21 | A utf8-safe version of C<length()>. | ||
| 22 | |||
| 23 | =cut | ||
| 24 | |||
| 25 | sub byte_length { | ||
| 26 | 30 | ▶ | use bytes; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 27 | 0 | ▶ | my $str = shift; |
|
Subroutine
byte_length: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 28 | 0 | return length( $str ); | |
| 29 | } | ||
| 30 | |||
| 31 | 30 | 1; | |