Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Inline parse_characters and _try_encoding_guess

This is called for every line we parse, so each µs counts.
  • Loading branch information...
commit 0f9a3e848f50140511cce453629a86b8aad21551 1 parent 6b6c9d6
@ilmari ilmari authored
Showing with 14 additions and 24 deletions.
  1. +14 −24 lib/Pod/Simple/BlackBox.pm
View
38 lib/Pod/Simple/BlackBox.pm
@@ -123,8 +123,20 @@ sub parse_lines { # Usage: $parser->parse_lines(@lines)
}
}
- if(!$self->parse_characters && !$self->{'encoding'}) {
- $self->_try_encoding_guess($line)
+ if(!$self->{'parse_characters'} && !$self->{'encoding'}
+ && ($self->{'in_pod'} || $line =~ /^=/s)
+ && $line =~ /[^\x00-\x7f]/
+ ) {
+ my $encoding = $line =~ /^[\x00-\x7f]*[\xC0-\xFD][\x80-\xBF]/ ? 'UTF-8' : 'ISO8859-1';
+ $self->_handle_encoding_line( "=encoding $encoding" );
+ $self->{'_transcoder'} && $self->{'_transcoder'}->($line);
+
+ my ($word) = $line =~ /(\S*[^\x00-\x7f]\S*)/;
+
+ $self->whine(
+ $self->{'line_count'},
+ "Non-ASCII character seen before =encoding in '$word'. Assuming $encoding"
+ );
}
DEBUG > 5 and print "# Parsing line: [$line]\n";
@@ -401,28 +413,6 @@ sub _handle_encoding_second_level {
return;
}
-sub _try_encoding_guess {
- my ($self,$line) = @_;
-
- if(!$self->{'in_pod'} and $line !~ /^=/m) {
- return; # don't whine about non-ASCII bytes in code/comments
- }
-
- return unless $line =~ /[^\x00-\x7f]/; # Look for non-ASCII byte
-
- my $encoding = $line =~ /^[\x00-\x7f]*[\xC0-\xFD][\x80-\xBF]/ ? 'UTF-8' : 'ISO8859-1';
- $self->_handle_encoding_line( "=encoding $encoding" );
- $self->{'_transcoder'} && $self->{'_transcoder'}->($line);
-
- my ($word) = $line =~ /(\S*[^\x00-\x7f]\S*)/;
-
- $self->whine(
- $self->{'line_count'},
- "Non-ASCII character seen before =encoding in '$word'. Assuming $encoding"
- );
-
-}
-
#~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`~`
{
Please sign in to comment.
Something went wrong with that request. Please try again.