EBook-Ishmael
view release on metacpan or search on metacpan
#include "ppport.h"
#define DECODE_BUF_SIZE 8192
/* https://wiki.mobileread.com/wiki/PalmDOC#PalmDoc_byte_pair_compression */
int
c_palmdoc_decode(
const unsigned char* input, STRLEN inlen,
unsigned char* output, STRLEN outlen,
STRLEN* decoded
) {
unsigned int b = 0;
unsigned int ld = 0;
unsigned int l, d = 0;
STRLEN outp = 0;
*decoded = 0;
for (STRLEN i = 0; i < inlen;) {
b = input[i++];
/* space + xor byte with 0x80 */
if (b >= 0xc0) {
if (outp >= outlen) {
return -1;
}
output[outp++] = ' ';
if (outp >= outlen) {
} else {
if (outp >= outlen) {
return -1;
}
output[outp++] = '\0';
}
}
assert(outp <= outlen);
*decoded = outp;
return 0;
}
MODULE = EBook::Ishmael PACKAGE = EBook::Ishmael::Decode
PROTOTYPES: DISABLE
SV*
xs_palmdoc_decode(encode)
contrib/512-bigram.pl view on Meta::CPAN
map { [ $_, $bigram->{ $_ } ] }
keys %$bigram;
if (@pairs > $num) {
@pairs = @pairs[0 .. $num-1];
}
say "my %$name = map { \$_ => 1 } (";
my $l = '';
for my $p (@pairs) {
my $decoded = encode($encoding, $p->[0], Encode::FB_CROAK);
my $b1 = ord(substr $decoded, 0, 1);
my $b2 = ord(substr $decoded, 1, 1);
my $s = sprintf q{"\x%02x\x%02x",}, $b1, $b2;
if (length($l) + length($s) > 80) {
say $l;
$l = '';
}
$l .= $s;
}
if ($l ne '') {
say $l;
}
lib/EBook/Ishmael/Decode.pm view on Meta::CPAN
B<EBook::Ishmael::Decode> is a module that provides subroutines for decoding
various kinds of encoded ebook text. For L<ishmael> user documentation, you
should consult its manual (this is developer documentation).
=head1 SUBROUTINES
B<EBook::Ishmael::Decode> does not export any subroutines by default.
=head2 $d = palmdoc_decode($data)
Decodes PalmDoc lz77-encoded C<$data>, returning the decoded data.
=head1 AUTHOR
Written by Samuel Young, E<lt>samyoung12788@gmail.comE<gt>.
This project's source can be found on its
L<Codeberg Page|https://codeberg.org/1-1sam/ishmael>. Comments and pull
requests are welcome!
=head1 COPYRIGHT
( run in 2.212 seconds using v1.01-cache-2.11-cpan-98e64b0badf )