Re: [PATCH] gitweb: Better chopping in commit search results

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jakub Narebski <jnareb@xxxxxxxxx> writes:

> 	# regexps: ending and beginning with word part up to $add_len
> 	my $endre = qr/.{0,$len}[^ \/\-_:\.@]{0,$add_len}/;
> 	my $begre = qr/[^ \/\-_:\.@]{0,$add_len}.{0,$len}/;

I have no idea what these line noise characters inside [] are.
Did you mean something like "\w"?

I have a suspicion that it may be easier to read and could be
even more efficient to split an overlong line at word boundaries
and to remove elements from the end you are removing from until
it fits.

sub chop_whence {
	my ($line, $max, $slop, $where) = @_;

	my $len = length($line);
	if ($len < $max + $slop) {
		return $line;
	}

	# Cut at word boundaries
	my @split = split(/\b/, $line);
	my $filler = "...";

	while ((2 < @split)) {
		my $removed;
		my $splice_at;
		if ($where eq 'left') {
			$removed = shift @split;
		} elsif ($where eq 'right') {
			$removed = pop @split;
		} else {
			my $splice_at = int($#split / 2);
			$removed = splice(@split, $splice_at, 1);
		}
		$len -= length($removed) + length($filler);
		if ($len < $max + $slop) {
			if ($where eq 'left') {
				unshift @split, $filler;
			} elsif ($where eq 'right') {
				push @split, $filler;
			} else {
				my $splice_at = int($#split / 2);
				splice(@split, $splice_at, 0, $filler);
			}
			return join('', @split);
		}
	}
	# give up
	return $line;
}

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux