CPANPLUS
view release on metacpan or search on metacpan
inc/bundle/JSON/PP.pm view on Meta::CPAN
use constant P_ALLOW_TAGS => 19;
use constant USE_B => $ENV{PERL_JSON_PP_USE_B} || 0;
use constant CORE_BOOL => defined &builtin::is_bool;
my $invalid_char_re;
BEGIN {
$invalid_char_re = "[";
for my $i (0 .. 0x01F, 0x22, 0x5c) { # '/' is ok
$invalid_char_re .= quotemeta chr utf8::unicode_to_native($i);
}
$invalid_char_re = qr/$invalid_char_re]/;
}
BEGIN {
if (USE_B) {
require B;
}
}
inc/bundle/JSON/PP.pm view on Meta::CPAN
map {
$_ <= 255 ?
chr($_) :
$_ <= 65535 ?
sprintf('\u%04x', $_) : sprintf('\u%x\u%x', _encode_surrogates($_));
} unpack('U*', $_[0])
);
}
sub _encode_surrogates { # from perlunicode
my $uni = $_[0] - 0x10000;
return ($uni / 0x400 + 0xD800, $uni % 0x400 + 0xDC00);
}
sub _is_bignum {
$_[0]->isa('Math::BigInt') or $_[0]->isa('Math::BigFloat');
}
inc/bundle/JSON/PP.pm view on Meta::CPAN
$utf16 = undef;
}
else {
if (defined $utf16) {
decode_error("surrogate pair expected");
}
my $hex = hex( $u );
if ( chr $u =~ /[[:^ascii:]]/ ) {
$is_utf8 = 1;
$s .= _decode_unicode($u) || next;
}
else {
$s .= chr $hex;
}
}
}
else{
unless ($loose) {
$at -= 2;
inc/bundle/JSON/PP.pm view on Meta::CPAN
return "$v";
}
}
}
return $is_dec ? $v/1.0 : 0+$v;
}
# Compute how many bytes are in the longest legal official Unicode
# character
my $max_unicode_length = do {
no warnings 'utf8';
chr 0x10FFFF;
};
utf8::encode($max_unicode_length);
$max_unicode_length = length $max_unicode_length;
sub is_valid_utf8 {
# Returns undef (setting $utf8_len to 0) unless the next bytes in $text
# comprise a well-formed UTF-8 encoded character, in which case,
# return those bytes, setting $utf8_len to their count.
my $start_point = substr($text, $at - 1);
# Look no further than the maximum number of bytes in a single
# character
my $limit = $max_unicode_length;
$limit = length($start_point) if $limit > length($start_point);
# Find the number of bytes comprising the first character in $text
# (without having to know the details of its internal representation).
# This loop will iterate just once on well-formed input.
while ($limit > 0) { # Until we succeed or exhaust the input
my $copy = substr($start_point, 0, $limit);
# decode() will return true if all bytes are valid; false
# if any aren't.
inc/bundle/JSON/PP.pm view on Meta::CPAN
len => $len,
depth => $depth,
encoding => $encoding,
is_valid_utf8 => $is_valid_utf8,
};
}
} # PARSE
sub _decode_surrogates { # from perlunicode
my $uni = 0x10000 + (hex($_[0]) - 0xD800) * 0x400 + (hex($_[1]) - 0xDC00);
my $un = pack('U*', $uni);
utf8::encode( $un );
return $un;
}
sub _decode_unicode {
my $un = pack('U', hex shift);
utf8::encode( $un );
return $un;
}
sub incr_parse {
local $Carp::CarpLevel = 1;
( $_[0]->{_incr_parser} ||= JSON::PP::IncrParser->new )->incr_parse( @_ );
}
inc/bundle/JSON/PP/Compat5006.pm view on Meta::CPAN
if ( _is_valid_utf8( $_[0] ) ) {
utf8::downgrade( $_[0] );
$_[0] = pack( "U*", unpack( "U*", $_[0] ) );
}
}
*JSON::PP::JSON_PP_encode_ascii = \&_encode_ascii;
*JSON::PP::JSON_PP_encode_latin1 = \&_encode_latin1;
*JSON::PP::JSON_PP_decode_surrogates = \&JSON::PP::_decode_surrogates;
*JSON::PP::JSON_PP_decode_unicode = \&JSON::PP::_decode_unicode;
unless ( defined &B::SVp_NOK ) { # missing in B module.
eval q{ sub B::SVp_NOK () { 0x02000000; } };
}
}
sub _encode_ascii {
inc/bundle/Locale/Maketext/Simple.pm view on Meta::CPAN
}
More sophisticated example:
package Foo::Bar;
use Locale::Maketext::Simple (
Class => 'Foo', # search in auto/Foo/
Style => 'gettext', # %1 instead of [_1]
Export => 'maketext', # maketext() instead of loc()
Subclass => 'L10N', # Foo::L10N instead of Foo::I18N
Decode => 1, # decode entries to unicode-strings
Encoding => 'locale', # but encode lexicons in current locale
# (needs Locale::Maketext::Lexicon 0.36)
);
sub japh {
print maketext("Just another %1 hacker", "Perl");
}
=head1 DESCRIPTION
This module is a simple wrapper around B<Locale::Maketext::Lexicon>,
( run in 0.421 second using v1.01-cache-2.11-cpan-88abd93f124 )