Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 19 additions & 22 deletions siteupdate/cplusplus/classes/Waypoint/Waypoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,34 +430,31 @@ void Waypoint::label_selfref(const char *slash)
{ // looking for the route within the label
// partially complete "references own route" -- too many FP
// first check for number match after a slash, if there is one
if (slash && route->route.back() >= '0' && route->route.back() <= '9')
{ int digit_starts = route->route.size()-1;
while (digit_starts >= 0 && route->route[digit_starts] >= '0' && route->route[digit_starts] <= '9')
digit_starts--;
if (!strcmp(slash+1, route->route.data()+digit_starts+1) || !strcmp(slash+1, route->route.data()))
{ Datacheck::add(route, label, "", "", "LABEL_SELFREF", "");
return;
}
else { const char *underscore = strchr(slash+1, '_');
if (underscore
&& (label.substr(slash-label.data()+1, underscore-slash-1) == route->route.data()+digit_starts+1
|| label.substr(slash-label.data()+1, underscore-slash-1) == route->route.data()))
if (slash)
{ char* digit_starts = isdigit(route->route.back())
? &route->route.back()
: isdigit(route->route[route->route.size()-2]) && isalpha(route->route.back()) ? &route->route.back()-1 : 0;
if (digit_starts)
{ while (digit_starts > route->route.data() && isdigit(digit_starts[-1])) digit_starts--;
if (!strcmp(slash+1, digit_starts) || !strcmp(slash+1, route->route.data()))
{ Datacheck::add(route, label, "", "", "LABEL_SELFREF", "");
return;
}
}
const char *underscore = strchr(slash+1, '_');
if (underscore)
{ std::string postslash(slash+1, underscore-slash-1);
if (postslash == digit_starts || postslash == route->route)
{ Datacheck::add(route, label, "", "", "LABEL_SELFREF", "");
return;
}
}
}
}
// now the remaining checks
std::string rte_ban = route->route + route->banner;
const char *l = label.data();
const char *rb = rte_ban.data();
const char *end = rb+rte_ban.size();
while (rb < end)
{ if (*l != *rb) return;
l++;
rb++;
}
if (*l == 0 || *l == '_' || *l == '/')
if ( strncmp(label.data(), rte_ban.data(), rte_ban.size()) ) return;
const char *c = label.data()+rte_ban.size();
if (*c == 0 || *c == '_' && (c[1] != 'U' || c[2] && !isdigit(c[2])) || *c == '/')
Datacheck::add(route, label, "", "", "LABEL_SELFREF", "");
}

Expand Down
45 changes: 27 additions & 18 deletions siteupdate/python-teresco/siteupdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,32 @@ def label_references_route(self, r, datacheckerrors):
#datacheckerrors.append(DatacheckEntry(route, [self.label], "UNEXPECTED_DESIGNATION", self.label[len(no_abbrev)+len(r.abbrev)+1:]))
return False

def label_selfref(self):
# partially complete "references own route" -- too many FP
# first check for number match after a slash, if there is one
if '/' in self.label:
digit_starts = len(r.route)-1 if r.route[-1].isdigit() else \
len(r.route)-2 if r.route[-2].isdigit() and r.route[-1].isalpha() else 0
if digit_starts:
while digit_starts >= 0 and r.route[digit_starts].isdigit():
digit_starts-=1
digits = r.route[digit_starts+1:]
postslash = self.label[self.label.index('/')+1:]
if postslash == digits or postslash == r.route:
datacheckerrors.append(DatacheckEntry(r,[self.label],'LABEL_SELFREF'))
return
if '_' in postslash:
postslash = postslash[:postslash.index('_')]
if postslash == digits or postslash == r.route:
datacheckerrors.append(DatacheckEntry(r,[self.label],'LABEL_SELFREF'))
return
# now the remaining checks
rte_ban = r.route+r.banner
if self.label.startswith(rte_ban):
c = len(rte_ban)
if c == len(self.label) or self.label[c] == '_' and (self.label[c+1] != 'U' or len(self.label) > c+2 and not self.label[c+2].isdigit()) or self.label[c] == '/':
datacheckerrors.append(DatacheckEntry(r,[self.label],'LABEL_SELFREF'))

class HighwaySegment:
"""This class represents one highway segment: the connection between two
Waypoints connected by one or more routes"""
Expand Down Expand Up @@ -4017,24 +4043,7 @@ def run(self):
visible_distance = 0.0

# looking for the route within the label
# partially complete "references own route" -- too many FP
# first check for number match after a slash, if there is one
selfref_found = False
if '/' in w.label and r.route[-1].isdigit():
digit_starts = len(r.route)-1
while digit_starts >= 0 and r.route[digit_starts].isdigit():
digit_starts-=1
if w.label[w.label.index('/')+1:] == r.route[digit_starts+1:]:
selfref_found = True
if w.label[w.label.index('/')+1:] == r.route:
selfref_found = True
if '_' in w.label[w.label.index('/')+1:] and w.label[w.label.index('/')+1:w.label.rindex('_')] == r.route[digit_starts+1:]:
selfref_found = True
if '_' in w.label[w.label.index('/')+1:] and w.label[w.label.index('/')+1:w.label.rindex('_')] == r.route:
selfref_found = True
# now the remaining checks
if selfref_found or r.route+r.banner == w.label or re.fullmatch(r.route+r.banner+'[_/].*',w.label):
datacheckerrors.append(DatacheckEntry(r,[w.label],'LABEL_SELFREF'))
w.label_selfref()

# look for too many underscores in label
if w.label.count('_') > 1:
Expand Down