Encode
view release on metacpan or search on metacpan
# UTF-8 encode long hand - only covers part of perl's range
## my $uv = shift;
# chr() works in native space so convert value from table
# into that space before using chr().
my $ch = chr(utf8::unicode_to_native($_[0]));
# Now get core perl to encode that the way it likes.
utf8::encode($ch);
return $ch;
}
sub encode_S
{
# encode single byte
## my ($ch,$page) = @_; return chr($ch);
return chr $_[0];
}
sub encode_D
{
# encode double byte MS byte first
## my ($ch,$page) = @_; return chr($page).chr($ch);
return chr ($_[1]) . chr $_[0];
}
sub encode_M
{
# encode Multi-byte - single for 0..255 otherwise double
## my ($ch,$page) = @_;
## return &encode_D if $page;
## return &encode_S;
return chr ($_[1]) . chr $_[0] if $_[1];
return chr $_[0];
}
my %encode_types = (U => \&encode_U,
S => \&encode_S,
D => \&encode_D,
M => \&encode_M,
);
# Win32 does not expand globs on command line
if ($^O eq 'MSWin32' and !$ENV{PERL_CORE}) {
eval "\@ARGV = map(glob(\$_),\@ARGV)";
@ARGV = @orig_ARGV unless @ARGV;
}
my %opt;
# I think these are:
# -Q to disable the duplicate codepoint test
# -S make mapping errors fatal
# -q to remove comments written to output files
# -O to enable the (brute force) substring optimiser
# -o <output> to specify the output file name (else it's the first arg)
# -f <inlist> to give a file with a list of input files (else use the args)
# -n <name> to name the encoding (else use the basename of the input file.
#Getopt::Long::Configure("bundling");
#GetOptions(\%opt, qw(C M=s S Q q O o=s f=s n=s v));
getopts('CM:SQqOo:f:n:v',\%opt);
$opt{M} and make_makefile_pl($opt{M}, @ARGV);
$opt{C} and make_configlocal_pm($opt{C}, @ARGV);
$opt{v} ||= $ENV{ENC2XS_VERBOSE};
$opt{q} ||= $ENV{ENC2XS_NO_COMMENTS};
sub verbose {
print STDERR @_ if $opt{v};
}
sub verbosef {
printf STDERR @_ if $opt{v};
}
# ($cpp, $static, $sized) = compiler_info($declaration)
#
# return some information about the compiler and compile options we're using:
#
# $declaration - true if we're doing a declaration rather than a definition.
#
# $cpp - we're using C++
# $static - ok to declare the arrays as static
# $sized - the array declarations should be sized
sub compiler_info {
my ($declaration) = @_;
my $ccflags = $Config{ccflags};
if (defined $Config{ccwarnflags}) {
$ccflags .= " " . $Config{ccwarnflags};
}
my $compat = $ccflags =~ /\Q-Wc++-compat/;
my $pedantic = $ccflags =~ /-pedantic/;
my $cpp = ($Config{d_cplusplus} || '') eq 'define';
# The encpage_t tables contain recursive and mutually recursive
# references. To allow them to compile under C++ and some restrictive
# cc options, it may be necessary to make the tables non-static/const
# (thus moving them from the text to the data segment) and/or not
# include the size in the declaration.
my $static = !(
$cpp
|| ($compat && $pedantic)
|| ($^O eq 'MacOS' && $declaration)
);
# -Wc++-compat on its own warns if the array declaration is sized.
# The easiest way to avoid this warning is simply not to include
# the size in the declaration.
# With -pedantic as well, the issue doesn't arise because $static
# above becomes false.
my $sized = $declaration && !($compat && !$pedantic);
return ($cpp, $static, $sized);
}
# This really should go first, else the die here causes empty (non-erroneous)
# output files to be written.
my @encfiles;
if (exists $opt{f}) {
( run in 2.889 seconds using v1.01-cache-2.11-cpan-d8267643d1d )