Re: [PATCH 2/n] gitweb: Use '&iquot;' instead of '?' in esc_path

From: Jakub Narebski <jnareb@gmail.com>
Date: 2006-11-07 08:58:08
Jakub Narebski wrote:
> 3. Use Character Escape Codes (CEC), using alphabetic and octal
>    backslash sequences like those used in C. Probably need to escape
>    backslash (quoting character) too. Has the advantage of being widely
>    understood in POSIX world. Has the disadvantage of need for escape
>    sequence table/hash. Has the advantage that it works for all
>    characters - simple octal backslash sequence if they have no special
>    escape sequence.

Here is example code for this:

	sub esc_path {
		my $str = shift;

		sub quot {
			my $seq = shift;
			my %es = (
				"\t" => '\t', # tab            (HT, TAB)
				"\n" => '\n', # newline        (NL)
				"\r" => '\r', # return         (CR)
				"\f" => '\f', # form feed      (FF)
				"\b" => '\b', # backspace      (BS)
				"\a" => '\a', # alarm (bell)   (BEL)
				"\e" => '\e', # escape        (ESC)
				"\013" => '\v', # vertical tab (VT)
			);

			if (exists $es{seq}) {
				return $es{$seq};
			}
			return sprintf("\\%03o", ord($seq));
		}
		
		$str = esc_html($str);
		$str =~ s/([[:cntrl:]])/'<span class="cntrl">' . quot($1) . '</span>'/eg;
		return $str;
	}

-- 
Jakub Narebski
Poland
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Received on Tue Nov 07 08:57:43 2006

This archive was generated by hypermail 2.1.8 : 2006-11-07 08:58:46 EST