- From: Ville Skytta via cvs-syncmail <cvsmail@w3.org>
- Date: Sun, 04 Oct 2009 20:43:32 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/validator/httpd/cgi-bin In directory hutz:/tmp/cvs-serv24139 Modified Files: check Log Message: Simplify error marking code; force marked char to be within shown code excerpt. Index: check =================================================================== RCS file: /sources/public/validator/httpd/cgi-bin/check,v retrieving revision 1.707 retrieving revision 1.708 diff -u -d -r1.707 -r1.708 --- check 4 Oct 2009 20:42:01 -0000 1.707 +++ check 4 Oct 2009 20:43:29 -0000 1.708 @@ -2185,66 +2185,25 @@ # Chop the source line into 3 pieces; the character at which the error # was detected, and everything to the left and right of that position. # That way we can add markup to the relevant char without breaking &ent(). +# Expects 1-based column indexes. sub mark_error ($$) { my $line = shift; my $col = shift; + my $linelen = length($line); - # - # Left side... - my $left; - { - my $offset = 0; # Left side always starts at 0. - my $length; - - if ($col - 1 < 0) { # If error is at start of line... - $length = 0; # ...floor to 0 (no negative offset). - } elsif ($col == length $line) { # If error is at EOL... - $length = $col - 1; # ...leave last char to indicate position. - } else { # Otherwise grab everything up to pos of error. - $length = $col-1; - } - $left = substr $line, $offset, $length; - } - - # - # The character where the error was detected. - my $char; - { - my $offset; - my $length = 1; # Length is always 1; the char where error was found. - - if ($col == length $line) { # If err is at EOL... - $offset = $col - 1; # ...then grab last char on line instead. - } else { - $offset = $col-1; # Otherwise just grab the char. - } - $char = substr $line, $offset, $length; - $char = &ent($char); + # Coerce column into an index valid within the line. + if ($col < 1) { + $col = 1; + } elsif ($col > $linelen) { + $col = $linelen; } + $col--; - # - # The right side up to the end of the line... - my $right; - { - my $offset; - my $length; - - # Offset... - if ($col == length $line) { # If at EOL... - $offset = 0; # Don't bother as there is nothing left to grab. - } else { - $offset = $col; # Otherwise get everything from char-after-error. - } - - # Length... - if ($col == length $line) { # If at end of line... - $length = 0; # ...then don't grab anything. - } else { - $length = length($line) - ($col - 1); # Otherwise get the rest of the line. - } - $right = substr $line, $offset, $length; - } + my $left = substr($line, 0, $col); + my $char = substr($line, $col, 1); + my $right = substr($line, $col + 1); + $char = &ent($char); $char = qq(<strong title="Position where error was detected.">$char</strong>); $line = &ent($left) . $char . &ent($right);
Received on Sunday, 4 October 2009 20:43:35 UTC