(Retracted by #10104.)
authorBarrie Slaymaker <barries@slaysys.com>
Sat, 12 May 2001 01:28:10 +0000 (21:28 -0400)
committerJarkko Hietaniemi <jhi@iki.fi>
Mon, 14 May 2001 12:32:44 +0000 (12:32 +0000)
Subject: [PATCH bleadperl Pod::Text] avoid overquoting [Was: rand(0) is rand(1)]
Message-ID: <20010512012810.B26358@jester.slaysys.com>

p4raw-id: //depot/perl@10094

lib/Pod/Text.pm

index a0dab2d..da21ef5 100644 (file)
@@ -472,7 +472,18 @@ sub seq_b { return $_[0]{alt} ? "``$_[1]''" : $_[1] }
 sub seq_f { return $_[0]{alt} ? "\"$_[1]\"" : $_[1] }
 sub seq_i { return '*' . $_[1] . '*' }
 sub seq_c {
-    return $_[0]{alt} ? "``$_[1]''" : "$_[0]{LQUOTE}$_[1]$_[0]{RQUOTE}"
+    return $_[0]{alt}
+        ? "``$_[1]''"
+       : $_[0]{LQUOTE} eq '"' &&
+         $_[1] =~ /^\s*(?:   # Some heuristics to avoid some overquoting
+           (['`"]).*\1                           # already quoted 
+           |\$+[\^#]?\S(\[.*\]|\{.*\})?          # control or punct var?
+           |[\$#\@%&*]+[:'\w]+(\[.*\]|\{.*\})?   # a "plain" var or func?
+           |[\$#\@%&*]*[:'\w]+(->)?\(\s*[^\s,]\s*\) # a call, 0 or 1 args?
+           |[:'\w]+                              # a word
+           )\s*\z/x
+           ? $_[1]
+           : "$_[0]{LQUOTE}$_[1]$_[0]{RQUOTE}"
 }
 
 # The complicated one.  Handle links.  Since this is plain text, we can't