From: Vincent Pit Date: Mon, 23 Aug 2010 09:53:50 +0000 (+0200) Subject: Refine indirect_find X-Git-Tag: v0.23~5 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2Findirect.git;a=commitdiff_plain;h=cd3bb52166ed9f6b823c9218ea73edc027dfe1c8 Refine indirect_find --- diff --git a/indirect.xs b/indirect.xs index f22ecb3..9a2b6c0 100644 --- a/indirect.xs +++ b/indirect.xs @@ -450,7 +450,7 @@ STATIC void indirect_map_delete(pTHX_ const OP *o) { 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; @@ -460,15 +460,18 @@ STATIC int indirect_find(pTHX_ SV *sv, const char *s, STRLEN *pos) { 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);