Use Rafael's sick trick of ASCII NUL as a q'' delimiter to save a
Nicholas Clark [Sat, 1 Jan 2005 21:13:53 +0000 (21:13 +0000)]
lot of quoting code

p4raw-id: //depot/perl@23727

toke.c

diff --git a/toke.c b/toke.c
index 448ede1..2e652e4 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -2590,18 +2590,11 @@ Perl_yylex(pTHX)
                              && strchr(PL_splitstr + 1, *PL_splitstr))
                            Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s);", PL_splitstr);
                        else {
-                           char delim;
-                           s = "'~#\200\1'"; /* surely one char is unused...*/
-                           while (s[1] && strchr(PL_splitstr, *s))  s++;
-                           delim = *s;
-                           Perl_sv_catpvf(aTHX_ PL_linestr, "our @F=split(%s%c",
-                                     "q" + (delim == '\''), delim);
-                           for (s = PL_splitstr; *s; s++) {
-                               if (*s == '\\')
-                                   sv_catpvn(PL_linestr, "\\", 1);
-                               sv_catpvn(PL_linestr, s, 1);
-                           }
-                           Perl_sv_catpvf(aTHX_ PL_linestr, "%c);", delim);
+                           /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
+                              bytes can be used as quoting characters.  :-) */
+                           Perl_sv_catpvf(aTHX_ PL_linestr,
+                                          "our @F=split(q%c%s%c);",
+                                          0, PL_splitstr, 0);
                        }
                    }
                    else