[lintian] 01/03: L::Util: Cache the UTF-8 decoder
This is an automated email from the git hooks/post-receive script.
nthykier pushed a commit to branch master
in repository lintian.
commit c2614918da0ba5f23a699309495499666f862b70
Author: Niels Thykier <niels@thykier.net>
Date: Thu Oct 2 22:16:10 2014 +0200
L::Util: Cache the UTF-8 decoder
Signed-off-by: Niels Thykier <niels@thykier.net>
---
lib/Lintian/Util.pm | 29 +++++++++++++++++------------
1 file changed, 17 insertions(+), 12 deletions(-)
diff --git a/lib/Lintian/Util.pm b/lib/Lintian/Util.pm
index f305fe0..a12ac4d 100644
--- a/lib/Lintian/Util.pm
+++ b/lib/Lintian/Util.pm
@@ -765,19 +765,24 @@ Returns a truth value if STRING can be decoded as valid UTF-8.
=cut
-sub is_string_utf8_encoded {
- my ($str) = @_;
- if ($str =~ m,\e[-!"\$%()*+./],) {
- # ISO-2022
- return 0;
- }
- eval {Encode::decode('UTF-8', $str, Encode::FB_CROAK);};
- if ($@) {
- # fail
- return 0;
+{
+ my $decoder = Encode::find_encoding('UTF-8');
+ die('No UTF-8 decoder !?') unless ref($decoder);
+
+ sub is_string_utf8_encoded {
+ my ($str) = @_;
+ if ($str =~ m,\e[-!"\$%()*+./],) {
+ # ISO-2022
+ return 0;
+ }
+ eval {$decoder->decode($str, Encode::FB_CROAK);};
+ if ($@) {
+ # fail
+ return 0;
+ }
+ # pass
+ return 1;
}
- # pass
- return 1;
}
=item file_is_encoded_in_non_utf8 (...)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/lintian/lintian.git
Reply to: