| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | #!/usr/bin/perl | 
| 2 |  |  |  |  |  |  | #------------------------------------------------------------------------------- | 
| 3 |  |  |  |  |  |  | # Encode a Unicode string in Perl and decode it in Java | 
| 4 |  |  |  |  |  |  | # Philip R Brenan at gmail dot com, Appa Apps Ltd, 2017 | 
| 5 |  |  |  |  |  |  | #------------------------------------------------------------------------------- | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | package Encode::Unicode::PerlDecodeJava; | 
| 8 |  |  |  |  |  |  | require v5.16.0; | 
| 9 | 1 |  |  | 1 |  | 411 | use warnings FATAL => qw(all); | 
|  | 1 |  |  |  |  | 7 |  | 
|  | 1 |  |  |  |  | 29 |  | 
| 10 | 1 |  |  | 1 |  | 4 | use strict; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 22 |  | 
| 11 | 1 |  |  | 1 |  | 5 | use Carp; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 58 |  | 
| 12 | 1 |  |  | 1 |  | 485 | use utf8; | 
|  | 1 |  |  |  |  | 11 |  | 
|  | 1 |  |  |  |  | 4 |  | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | our $VERSION = '20171127'; | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | sub encode93($)                                                                 # Return the encoded version of a string | 
| 17 | 22 |  |  | 22 | 0 | 4628 | {my ($i) = @_;                                                                 # String to encode | 
| 18 | 22 |  |  |  |  | 34 | my $s = ''; | 
| 19 | 22 |  |  |  |  | 33 | my $n = length($i); | 
| 20 | 22 |  |  |  |  | 55 | for(split //, $i)                                                             # Letters are passed straight through | 
| 21 | 90 | 100 |  |  |  | 215 | {$s .=  /[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ '\(\)\[\]\{\}<>`!@#\$%^&*_\-+=,;:|.?\/]/ ? $_ : ord($_).'~'; | 
| 22 |  |  |  |  |  |  | } | 
| 23 | 22 |  |  |  |  | 144 | $s =~ s/([0123456789])(~)([^0123456789]|\Z)/$1$3/gsr;                         # Remove redundant ~ | 
| 24 |  |  |  |  |  |  | } | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | sub decode93($)                                                                 # Return the decode version of an encoded string | 
| 27 | 11 |  |  | 11 | 0 | 18 | {my ($i) = @_;                                                                 # String to decode | 
| 28 | 11 |  |  |  |  | 18 | my $s = ''; | 
| 29 | 11 |  |  |  |  | 13 | my $n = ''; | 
| 30 | 11 |  |  |  |  | 26 | for(split //, $i)                                                             # Letters are passed straight through | 
| 31 | 124 | 100 |  |  |  | 254 | {if (   /[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ '\(\)\[\]\{\}<>`!@#\$%^&*_\-+=,;:|.?\/]/) | 
|  |  | 100 |  |  |  |  |  | 
| 32 | 22 | 100 |  |  |  | 35 | {if (length($n)) {$s .= pack('U', $n); $n = ''}                            # Number terminated by letter not ~ | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 6 |  | 
| 33 | 22 |  |  |  |  | 32 | $s .= $_ | 
| 34 |  |  |  |  |  |  | } | 
| 35 | 15 |  |  |  |  | 44 | elsif (/~/i)      {$s .= pack('U', $n); $n = ''}                            # Decompress number | 
|  | 15 |  |  |  |  | 21 |  | 
| 36 | 87 |  |  |  |  | 131 | else              {$n .= $_} | 
| 37 |  |  |  |  |  |  | } | 
| 38 | 11 | 100 |  |  |  | 26 | if     (length($n)) {$s .= pack('U', $n)}                                     # Trailing number | 
|  | 5 |  |  |  |  | 15 |  | 
| 39 |  |  |  |  |  |  | $s | 
| 40 | 11 |  |  |  |  | 33 | } | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | #------------------------------------------------------------------------------- | 
| 43 |  |  |  |  |  |  | # Export | 
| 44 |  |  |  |  |  |  | #------------------------------------------------------------------------------- | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | require Exporter; | 
| 47 |  |  |  |  |  |  |  | 
| 48 | 1 |  |  | 1 |  | 323 | use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 196 |  | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | @ISA          = qw(Exporter); | 
| 51 |  |  |  |  |  |  | @EXPORT       = qw(decode93 encode93); | 
| 52 |  |  |  |  |  |  | @EXPORT_OK    = qw(); | 
| 53 |  |  |  |  |  |  | %EXPORT_TAGS  = (all=>[@EXPORT, @EXPORT_OK]); | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | # podDocumentation | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | =pod | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | =encoding utf-8 | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | =head1 Name | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | Encode::Unicode::PerlDecodeJava - Encode a Unicode string in Perl and decode it in Java | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | =head1 Synopsis | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | use Encode::Unicode::PerlDecodeJava; | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | ok $_ eq decode93(encode93($_)) for(qw(aaa (𝝰𝝱𝝲) aaa𝝰𝝱𝝲aaa yüz)) | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | =head1 Description | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | =head1 Index | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | =head1 Installation | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | This module is written in 100% Pure Perl and, thus, it is easy to read, use, | 
| 80 |  |  |  |  |  |  | modify and install. | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | Standard Module::Build process for building and installing modules: | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | perl Build.PL | 
| 85 |  |  |  |  |  |  | ./Build | 
| 86 |  |  |  |  |  |  | ./Build test | 
| 87 |  |  |  |  |  |  | ./Build install | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | =head1 Author | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | L | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | L | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | =head1 Copyright | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | Copyright (c) 2016-2017 Philip R Brenan. | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | This module is free software. It may be used, redistributed and/or modified | 
| 100 |  |  |  |  |  |  | under the same terms as Perl itself. | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  | =cut | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | # Tests and documentation | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | sub test | 
| 108 | 1 |  |  | 1 | 0 | 9 | {my $p = __PACKAGE__; | 
| 109 | 1 | 50 |  |  |  | 51 | return if eval "eof(${p}::DATA)"; | 
| 110 | 1 |  |  |  |  | 61 | my $s = eval "join('', <${p}::DATA>)"; | 
| 111 | 1 | 50 |  |  |  | 7 | $@ and die $@; | 
| 112 | 1 |  |  | 1 |  | 499 | eval $s; | 
|  | 1 |  |  |  |  | 49763 |  | 
|  | 1 |  |  |  |  | 7 |  | 
|  | 1 |  |  |  |  | 60 |  | 
| 113 | 1 | 50 |  |  |  | 111 | $@ and die $@; | 
| 114 |  |  |  |  |  |  | } | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | test unless caller; | 
| 117 |  |  |  |  |  |  |  | 
| 118 |  |  |  |  |  |  | 1; | 
| 119 |  |  |  |  |  |  | __DATA__ |