summaryrefslogtreecommitdiff
path: root/mg.c
diff options
context:
space:
mode:
authorIlya Zakharevich <ilya@math.berkeley.edu>1999-05-24 22:42:23 -0400
committerGurusamy Sarathy <gsar@cpan.org>1999-05-25 09:14:51 +0000
commitcf93c79d660ae36ccc5f83d949c599473fc522ce (patch)
tree990c1003b82a9b439144bee4075daab1ba3d13d9 /mg.c
parenta99f88279527854d73f6b517b869d613f02be3d1 (diff)
downloadperl-cf93c79d660ae36ccc5f83d949c599473fc522ce.tar.gz
REx engine improvements
Message-Id: <199905250642.CAA06208@monk.mps.ohio-state.edu> p4raw-id: //depot/perl@3475
Diffstat (limited to 'mg.c')
-rw-r--r--mg.c48
1 files changed, 27 insertions, 21 deletions
diff --git a/mg.c b/mg.c
index 9183104339..adfad7d4ad 100644
--- a/mg.c
+++ b/mg.c
@@ -341,23 +341,23 @@ magic_regdatum_get(SV *sv, MAGIC *mg)
{
dTHR;
register I32 paren;
- register char *s;
+ register I32 s;
register I32 i;
register REGEXP *rx;
- char *t;
+ I32 t;
if (PL_curpm && (rx = PL_curpm->op_pmregexp)) {
paren = mg->mg_len;
if (paren < 0)
return 0;
if (paren <= rx->nparens &&
- (s = rx->startp[paren]) &&
- (t = rx->endp[paren]))
+ (s = rx->startp[paren]) != -1 &&
+ (t = rx->endp[paren]) != -1)
{
if (mg->mg_obj) /* @+ */
- i = t - rx->subbeg;
+ i = t;
else /* @- */
- i = s - rx->subbeg;
+ i = s;
sv_setiv(sv,i);
}
}
@@ -378,13 +378,15 @@ magic_len(SV *sv, MAGIC *mg)
case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9': case '&':
if (PL_curpm && (rx = PL_curpm->op_pmregexp)) {
+ I32 s1, t1;
+
paren = atoi(mg->mg_ptr);
getparen:
if (paren <= rx->nparens &&
- (s = rx->startp[paren]) &&
- (t = rx->endp[paren]))
+ (s1 = rx->startp[paren]) != -1 &&
+ (t1 = rx->endp[paren]) != -1)
{
- i = t - s;
+ i = t1 - s1;
if (i >= 0)
return i;
}
@@ -399,8 +401,8 @@ magic_len(SV *sv, MAGIC *mg)
return 0;
case '`':
if (PL_curpm && (rx = PL_curpm->op_pmregexp)) {
- if ((s = rx->subbeg) && rx->startp[0]) {
- i = rx->startp[0] - s;
+ if (rx->startp[0] != -1) {
+ i = rx->startp[0];
if (i >= 0)
return i;
}
@@ -408,8 +410,8 @@ magic_len(SV *sv, MAGIC *mg)
return 0;
case '\'':
if (PL_curpm && (rx = PL_curpm->op_pmregexp)) {
- if (rx->subend && (s = rx->endp[0])) {
- i = rx->subend - s;
+ if (rx->endp[0] != -1) {
+ i = rx->sublen - rx->endp[0];
if (i >= 0)
return i;
}
@@ -589,6 +591,8 @@ magic_get(SV *sv, MAGIC *mg)
case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9': case '&':
if (PL_curpm && (rx = PL_curpm->op_pmregexp)) {
+ I32 s1, t1;
+
/*
* Pre-threads, this was paren = atoi(GvENAME((GV*)mg->mg_obj));
* XXX Does the new way break anything?
@@ -596,10 +600,11 @@ magic_get(SV *sv, MAGIC *mg)
paren = atoi(mg->mg_ptr);
getparen:
if (paren <= rx->nparens &&
- (s = rx->startp[paren]) &&
- (t = rx->endp[paren]))
+ (s1 = rx->startp[paren]) != -1 &&
+ (t1 = rx->endp[paren]) != -1)
{
- i = t - s;
+ i = t1 - s1;
+ s = rx->subbeg + s1;
getrx:
if (i >= 0) {
bool was_tainted;
@@ -607,7 +612,7 @@ magic_get(SV *sv, MAGIC *mg)
was_tainted = PL_tainted;
PL_tainted = FALSE;
}
- sv_setpvn(sv,s,i);
+ sv_setpvn(sv, s, i);
if (PL_tainting)
PL_tainted = (was_tainted || RX_MATCH_TAINTED(rx));
break;
@@ -626,8 +631,8 @@ magic_get(SV *sv, MAGIC *mg)
break;
case '`':
if (PL_curpm && (rx = PL_curpm->op_pmregexp)) {
- if ((s = rx->subbeg) && rx->startp[0]) {
- i = rx->startp[0] - s;
+ if ((s = rx->subbeg) && rx->startp[0] != -1) {
+ i = rx->startp[0];
goto getrx;
}
}
@@ -635,8 +640,9 @@ magic_get(SV *sv, MAGIC *mg)
break;
case '\'':
if (PL_curpm && (rx = PL_curpm->op_pmregexp)) {
- if (rx->subend && (s = rx->endp[0])) {
- i = rx->subend - s;
+ if (rx->subbeg && rx->endp[0] != -1) {
+ s = rx->subbeg + rx->endp[0];
+ i = rx->sublen - rx->endp[0];
goto getrx;
}
}