Closed yakra closed 2 years ago
If switching over & adding the right qualifications is too much of a PitA, at least save the substring object & reuse.
That's cleaner; that's a start.
Neither strcmp nor strncmp work. Why exactly, again?
Not looking at the code & results (how did I try what again?); just doing this as a thought experiment:
_
instead.NY5
in NY50
; need to check char after match.Checking for an underscore is unnecessary.
Repeating the digit_starts
& route
comparisons is redundant.
Instead, compare once and check for _
or \0
.
Adding 1 new line can get rid of 8 (or 9 if counting new bleeding-edge if (!colocated || !coloc_same_designation())
) -- the first check expands to:
if ( !strncmp(slash+1, digit_starts, &*route->route.end() - digit_starts) && strchr("_", slash[&*route->route.end()-digit_starts+1])
|| !strncmp(slash+1, route->route.data(), route->route.size()) && strchr("_", slash[route->route.size()+1])
) { if (!colocated || !coloc_same_designation())
Datacheck::add(route, label, "", "", "LABEL_SELFREF", "");
return;
}
...A bit ugly though.
Keep it relatively clean & readable:
if (!strdcmp(slash+1, digit_starts, '_') || !strdcmp(slash+1, route->route.data(), '_'))
{ if (!colocated || !coloc_same_designation())
Datacheck::add(route, label, "", "", "LABEL_SELFREF", "");
return;
}
A compact little function facilitates this:
inline int strdcmp(const char* a, const char* b, const char& d)
{ do if (!*b) return *a == d ? 0 : *a-*b;
while (*a++ == *b++);
return *--a - *--b;
}
Advantages:
num
on each iteration. Checking whether we're at the delimiter is one quick branch before returning.Waypoint::label_selfref
itself, avoid:
strchr
strncmp
calls:Tagged pending
but not closed.
Did I just forget about this, and it got addressed in https://github.com/TravelMapping/DataProcessing/pull/497?
A reminder that that's what I wanna check out when I have the attention span.
This all got done. Seemed to forget about it in #497, only linking the Pending issues in TravelMapping/DataProcessing.
https://github.com/yakra/DataProcessing/blob/79af5333b8ee089245e24365459c334e2451a168/siteupdate/cplusplus/classes/Waypoint/Waypoint.cpp#L443-L444
Neither strcmp nor strncmp work. Why exactly, again?
If switching over & adding the right qualifications is too much of a PitA, at least save the substring object & reuse.