Name

Encode::Unicode::PerlDecodeJava - Encode a Unicode string in Perl and decode it in Java

Synopsis

use Encode::Unicode::PerlDecodeJava;

ok $_ eq decode93(encode93($_)) for(qw(aaa (𝝰𝝱𝝲) aaa𝝰𝝱𝝲aaa yüz))

Description

encode93($input)

encodes any Perl string given as $input, even one containing Unicode characters, using only the 93 well known ASCII characters below:

abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789 '()[]{}<>~`!@#$%^&*_-+=:;|.,?\

and returns the resulting encoded string.

Such a string can be easily compressed and transported using software restricted to ASCII data and then reconstituted as a Unicode string in Perl by using decode93() or in Java by using the code reproduced further below.

decode93($input)

takes an $input string encoded by encode93() and returns the decoded string.

The following Java code takes a string encoded by encode93() and returns the decoded string to Java:

String decode(String input)                                                   // Decode string
 {final StringBuilder s = new StringBuilder();
  final StringBuilder n = new StringBuilder();
  final int N           = input.length();

  for(int i = 0; i < N; ++i)
   {final char c = input.charAt(i);
    if (Character.isDigit(c)) n.append(c);
    else if (c == ',')
     {final int p = Integer.parseInt(n.toString());
      s.appendCodePoint(p);
      n.setLength(0);
     }
    else s.append(c);
   }

  return s.toString();
 }

Installation

Standard Module::Build process for building and installing modules:

perl Build.PL
./Build
./Build test
./Build install

Author

philiprbrenan@gmail.com

http://www.appaapps.com

Copyright

Copyright (c) 2017 Philip R Brenan.

This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.