Skip to content

Instantly share code, notes, and snippets.

@Grinnz
Created September 3, 2015 22:23
Show Gist options
  • Save Grinnz/9d9266da7bc3982b2bab to your computer and use it in GitHub Desktop.
Save Grinnz/9d9266da7bc3982b2bab to your computer and use it in GitHub Desktop.
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