Created
September 3, 2015 22:23
-
-
Save Grinnz/9d9266da7bc3982b2bab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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