Skip to content

Waypoint: refactor URL validation #239

Closed
TravelMapping/DataProcessing
#607

Description

@yakra

if (!valid_num_str(URL.data()+latBeg, '&'))
{ size_t ampersand = URL.find('&', latBeg);
std::string lat_string = (ampersand == -1) ? URL.data()+latBeg : URL.substr(latBeg, ampersand-latBeg);
if (lat_string.size() > DBFieldLength::dcErrValue)
{ lat_string = lat_string.substr(0, DBFieldLength::dcErrValue-3);
while (lat_string.back() < 0) lat_string.erase(lat_string.end()-1);
lat_string += "...";
}
Datacheck::add(route, label, "", "", "MALFORMED_LAT", lat_string);
valid_line = 0;
}
if (!valid_num_str(URL.data()+lonBeg, '&'))
{ size_t ampersand = URL.find('&', lonBeg);
std::string lng_string = (ampersand == -1) ? URL.data()+lonBeg : URL.substr(lonBeg, ampersand-lonBeg);
if (lng_string.size() > DBFieldLength::dcErrValue)
{ lng_string = lng_string.substr(0, DBFieldLength::dcErrValue-3);
while (lng_string.back() < 0) lng_string.erase(lng_string.end()-1);
lng_string += "...";
}
Datacheck::add(route, label, "", "", "MALFORMED_LON", lng_string);
valid_line = 0;
}

Verbose and redundant.
Refactor off into its own function.
Rewriting existing valid_num_str would be a PitA, and besides, why lose the ability to use it elsewhere?

This can wait until invalid Waypoints throw rather than set coords to (0,0).
bool valid_line -> unsigned char invalid_line to throw.

Activity

  1. yakra commented on Apr 30, 2023

    @yakra
    OwnerAuthor

    From #198:

    The initial if statements could also be refactored away as part of this, but would result in an extra function call. Would there be a performance hit, however tiny, in practice?

    Ah sure it'll be grand

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions