From: Florian Ragwitz Date: Sat, 18 Apr 2009 08:42:06 +0000 (+0000) Subject: Allow extracting strings going over multiple lines using scan_str. X-Git-Tag: 0.005000~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=86964fb3f9ba6afc359b1ecb231fe44dae3665ef;p=p5sagit%2FDevel-Declare.git Allow extracting strings going over multiple lines using scan_str. --- diff --git a/Declare.xs b/Declare.xs index d29488d..08bbec6 100644 --- a/Declare.xs +++ b/Declare.xs @@ -187,8 +187,17 @@ int dd_toke_scan_ident(pTHX_ int offset) { } int dd_toke_scan_str(pTHX_ int offset) { + int remaining = sv_len(PL_linestr) - offset; + SV* line_copy = newSVsv(PL_linestr); char* base_s = SvPVX(PL_linestr) + offset; char* s = scan_str(base_s, FALSE, FALSE); + if (s != base_s && sv_len(PL_lex_stuff) > remaining) { + int ret = (s - SvPVX(PL_linestr)) + remaining; + sv_catsv(line_copy, PL_linestr); + dd_set_linestr(aTHX_ SvPV_nolen(line_copy)); + SvREFCNT_dec(line_copy); + return ret; + } return s - base_s; } diff --git a/lib/Devel/Declare/Context/Simple.pm b/lib/Devel/Declare/Context/Simple.pm index 52dd70d..1a47a7f 100644 --- a/lib/Devel/Declare/Context/Simple.pm +++ b/lib/Devel/Declare/Context/Simple.pm @@ -92,14 +92,7 @@ sub strip_proto { my $length = Devel::Declare::toke_scan_str($self->offset); my $proto = Devel::Declare::get_lex_stuff(); Devel::Declare::clear_lex_stuff(); - if( $length < 0 ) { - # Need to scan ahead more - $linestr .= $self->get_linestr(); - $length = rindex($linestr, ")") - $self->offset + 1; - } - else { - $linestr = $self->get_linestr(); - } + $linestr = $self->get_linestr(); substr($linestr, $self->offset, $length) = ''; $self->set_linestr($linestr);