Skip to content

Instantly share code, notes, and snippets.

@Grinnz Grinnz/no-uutf8.pm
Created Sep 3, 2015

Embed
What would you like to do?
package MojoUtil;
use constant ('UUTF8', $ENV{'MOJO_NO_UUTF8'} ? 0 : eval 'use Unicode::UTF8 0.58 (); 1');
sub decode {
my($encoding, $bytes) = @_;
my $fallback = sub {
die;
}
;
return undef unless eval {
do {
$bytes = _encoding($encoding)->decode("$bytes", 1);
1
}
};
return $bytes;
}
sub encode {
_encoding($_[0])->encode("$_[1]");
}
'???';
package MojoUtil;
sub _encoding ;
package MojoUtil;
use constant ('UUTF8', $ENV{'MOJO_NO_UUTF8'} ? 0 : eval 'use Unicode::UTF8 0.58 (); 1');
sub decode {
my($encoding, $bytes) = @_;
my $fallback = sub {
die;
}
;
return undef unless $encoding eq 'UTF-8' ? eval {
do {
$bytes = Unicode::UTF8::decode_utf8($bytes, $fallback);
1
}
} : eval {
do {
$bytes = _encoding($encoding)->decode("$bytes", 1);
1
}
};
return $bytes;
}
sub encode {
$_[0] eq 'UTF-8' ? Unicode::UTF8::encode_utf8($_[1]) : _encoding($_[0])->encode("$_[1]");
}
'???';
package MojoUtil;
sub _encoding ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.