| 45 | using ZipIndexValue = std::pair<strings::UniString, Uint64IndexValue>; |
| 46 | |
| 47 | void GetPostcodes(std::string const & filename, storage::CountryId const & countryId, FieldIndices const & fieldIndices, |
| 48 | char const * separator, bool hasHeader, storage::CountryInfoGetter const & infoGetter, |
| 49 | std::vector<m2::PointD> & valueMapping, std::vector<ZipIndexValue> & keyValuePairs) |
| 50 | { |
| 51 | ASSERT(!filename.empty(), ()); |
| 52 | std::ifstream data(filename); |
| 53 | if (!data.is_open()) |
| 54 | { |
| 55 | LOG(LERROR, ("Can't open postcodes file:", filename)); |
| 56 | return; |
| 57 | } |
| 58 | |
| 59 | std::string line; |
| 60 | |
| 61 | if (hasHeader && !std::getline(data, line)) |
| 62 | return; |
| 63 | |
| 64 | while (std::getline(data, line)) |
| 65 | { |
| 66 | std::vector<std::string_view> fields; |
| 67 | strings::Tokenize(std::string_view(line), separator, [&fields](std::string_view v) |
| 68 | { |
| 69 | strings::Trim(v, "\" "); |
| 70 | // Maybe empty, checks below should work for actual values. |
| 71 | fields.push_back(v); |
| 72 | }); |
| 73 | CHECK_GREATER_OR_EQUAL(fields.size(), fieldIndices.m_datasetCount, (line)); |
| 74 | |
| 75 | double lat; |
| 76 | CHECK(strings::to_double(fields[fieldIndices.m_latIndex], lat), (line)); |
| 77 | |
| 78 | double lon; |
| 79 | CHECK(strings::to_double(fields[fieldIndices.m_longIndex], lon), (line)); |
| 80 | |
| 81 | auto const p = mercator::FromLatLon(lat, lon); |
| 82 | |
| 83 | std::vector<storage::CountryId> countries; |
| 84 | infoGetter.GetRegionsCountryId(p, countries, 200.0 /* lookupRadiusM */); |
| 85 | if (std::find(countries.begin(), countries.end(), countryId) == countries.end()) |
| 86 | continue; |
| 87 | |
| 88 | keyValuePairs.emplace_back(search::NormalizeAndSimplifyString(fields[fieldIndices.m_postcodeIndex]), |
| 89 | valueMapping.size()); |
| 90 | valueMapping.push_back(p); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | void GetUKPostcodes(std::string const & filename, storage::CountryId const & countryId, |
| 95 | storage::CountryInfoGetter const & infoGetter, std::vector<m2::PointD> & valueMapping, |
no test coverage detected