STATIC int indirect_find(pTHX_ SV *sv, const char *s, STRLEN *pos) {
#define indirect_find(N, S, P) indirect_find(aTHX_ (N), (S), (P))
STRLEN len;
- const char *p = NULL, *r = SvPV_const(sv, len);
+ const char *p, *r = SvPV_const(sv, len);
if (len >= 1 && *r == '$') {
++r;
return 0;
}
- p = strstr(s, r);
- while (p) {
- p += len;
- if (!isALNUM(*p))
+ p = s;
+ while (1) {
+ p = strstr(p, r);
+ if (!p)
+ return 0;
+ if (!isALNUM(p[len]))
break;
- p = strstr(p + 1, r);
+ /* p points to a word that has r as prefix, skip the rest of the word */
+ p += len + 1;
+ while (isALNUM(*p))
+ ++p;
}
- if (!p)
- return 0;
*pos = p - SvPVX_const(PL_linestr);