/* --- Check functions ----------------------------------------------------- */
+STATIC STRLEN indirect_nextline(const char *s, STRLEN len) {
+ STRLEN i;
+
+ for (i = 0; i < len; ++i) {
+ if (s[i] == '\n') {
+ ++i;
+ while (i < len && s[i] == '\r')
+ ++i;
+ break;
+ }
+ }
+
+ return i;
+}
+
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, *r = SvPV_const(sv, len);
+ const char *p, *r, *t, *u;
+ r = SvPV_const(sv, len);
if (len >= 1 && *r == '$') {
++r;
--len;
++p;
}
- *pos = p - SvPVX_const(PL_linestr);
+ t = SvPV_const(PL_linestr, len);
+ u = t;
+ while (t <= p) {
+ STRLEN i = indirect_nextline(t, len);
+ if (i >= len)
+ break;
+ u = t;
+ t += i;
+ len -= i;
+ }
+ *pos = p - u;
return 1;
}
/* When positions are identical, the method and the object must have the
* same name. But it also means that it is an indirect call, as "foo->foo"
* results in different positions. */
- if (moi->pos <= ooi->pos) {
+ if ( moi->line < ooi->line
+ || (moi->line == ooi->line && moi->pos <= ooi->pos)) {
SV *file;
dSP;