1 package # This is JSON::backportPP
9 $JSON::PP5005::VERSION = '1.10';
14 0; # It is considered that UTF8 flag off for Perl 5.005.
21 1; # must always return true.
30 *JSON::PP::JSON_PP_encode_ascii = \&_encode_ascii;
31 *JSON::PP::JSON_PP_encode_latin1 = \&_encode_latin1;
32 *JSON::PP::JSON_PP_decode_surrogates = \&_decode_surrogates;
33 *JSON::PP::JSON_PP_decode_unicode = \&_decode_unicode;
35 # missing in B module.
36 sub B::SVp_IOK () { 0x01000000; }
37 sub B::SVp_NOK () { 0x02000000; }
38 sub B::SVp_POK () { 0x04000000; }
40 $INC{'bytes.pm'} = 1; # dummy
46 join('', map { $_ <= 127 ? chr($_) : sprintf('\u%04x', $_) } unpack('C*', $_[0]) );
51 join('', map { chr($_) } unpack('C*', $_[0]) );
55 sub _decode_surrogates { # from http://homepage1.nifty.com/nomenclator/unicode/ucs_utf.htm
56 my $uni = 0x10000 + (hex($_[0]) - 0xD800) * 0x400 + (hex($_[1]) - 0xDC00); # from perlunicode
57 my $bit = unpack('B32', pack('N', $uni));
59 if ( $bit =~ /^00000000000(...)(......)(......)(......)$/ ) {
60 my ($w, $x, $y, $z) = ($1, $2, $3, $4);
61 return pack('B*', sprintf('11110%s10%s10%s10%s', $w, $x, $y, $z));
64 Carp::croak("Invalid surrogate pair");
73 if ( $u =~ /^00([89a-f][0-9a-f])$/i ) { # 0x80-0xff
74 return pack( 'H2', $1 );
77 my $bit = unpack("B*", pack("H*", $u));
79 if ( $bit =~ /^00000(.....)(......)$/ ) {
80 $utf8bit = sprintf('110%s10%s', $1, $2);
82 elsif ( $bit =~ /^(....)(......)(......)$/ ) {
83 $utf8bit = sprintf('1110%s10%s10%s', $1, $2, $3);
86 Carp::croak("Invalid escaped unicode");
89 return pack('B*', $utf8bit);
93 sub JSON::PP::incr_text {
94 $_[0]->{_incr_parser} ||= JSON::PP::IncrParser->new;
96 if ( $_[0]->{_incr_parser}->{incr_parsing} ) {
97 Carp::croak("incr_text can not be called when the incremental parser already started parsing");
100 $_[0]->{_incr_parser}->{incr_text} = $_[1] if ( @_ > 1 );
101 $_[0]->{_incr_parser}->{incr_text};
112 JSON::PP5005 - Helper module in using JSON::PP in Perl 5.005
116 JSON::PP calls internally.
120 Makamaka Hannyaharamitu, E<lt>makamaka[at]cpan.orgE<gt>
123 =head1 COPYRIGHT AND LICENSE
125 Copyright 2007-2010 by Makamaka Hannyaharamitu
127 This library is free software; you can redistribute it and/or modify
128 it under the same terms as Perl itself.