C
ccc31807
This is copied from Text:arseWords. It appears in the function
parse_line(delimiter, boolean, string). I understand most of this, but
need some help understanding some if it. This appears in a loop:
while (length($line)) {
and parses a line with this call:
my ($f, $m, $l) = parse_line(/,/, 0, $line)
where line will be like this:
"Barack","Hussein","Obama"
I have numbered the lines for reference.
<quote>
# This pattern is optimised to be stack conservative on older perls.
# Do not refactor without being careful and testing it on very long
strings.
# See Perl bug #42980 for an example of a stack busting input.
1 $line =~ s/^
2 (?:
# double quoted string
3 (") # $quote
4 ((?>[^\\"]*(?:\\.[^\\"]*)*))" # $quoted
5 | # --OR--
# singe quoted string
6 (') # $quote
7 ((?>[^\\']*(?:\\.[^\\']*)*))' # $quoted
8 | # --OR--
# unquoted string
9 ( # $unquoted
10 (?:\\.|[^\\"'])*?
11 )
# followed by
12 ( # $delim
13 \Z(?!\n) # EOL
14 | # --OR--
15 (?-x:$delimiter) # delimiter
16 | # --OR--
17 (?!^)(?=["']) # a quote
18 )
)//xs or return; # extended layout
my ($quote, $quoted, $unquoted, $delim) = (($1 ? ($1,$2) : ($3,$4)),
$5, $6);
</quote>
Thanks, CC.
parse_line(delimiter, boolean, string). I understand most of this, but
need some help understanding some if it. This appears in a loop:
while (length($line)) {
and parses a line with this call:
my ($f, $m, $l) = parse_line(/,/, 0, $line)
where line will be like this:
"Barack","Hussein","Obama"
I have numbered the lines for reference.
<quote>
# This pattern is optimised to be stack conservative on older perls.
# Do not refactor without being careful and testing it on very long
strings.
# See Perl bug #42980 for an example of a stack busting input.
1 $line =~ s/^
2 (?:
# double quoted string
3 (") # $quote
4 ((?>[^\\"]*(?:\\.[^\\"]*)*))" # $quoted
5 | # --OR--
# singe quoted string
6 (') # $quote
7 ((?>[^\\']*(?:\\.[^\\']*)*))' # $quoted
8 | # --OR--
# unquoted string
9 ( # $unquoted
10 (?:\\.|[^\\"'])*?
11 )
# followed by
12 ( # $delim
13 \Z(?!\n) # EOL
14 | # --OR--
15 (?-x:$delimiter) # delimiter
16 | # --OR--
17 (?!^)(?=["']) # a quote
18 )
)//xs or return; # extended layout
my ($quote, $quoted, $unquoted, $delim) = (($1 ? ($1,$2) : ($3,$4)),
$5, $6);
</quote>
Thanks, CC.