| 38 | } // namespace |
| 39 | |
| 40 | std::string AddressesHolder::AddressInfo::FormatRange() const |
| 41 | { |
| 42 | if (m_house.empty() || m_house2.empty()) |
| 43 | return {}; |
| 44 | |
| 45 | using namespace search::house_numbers; |
| 46 | |
| 47 | std::vector<TokensT> left, right; |
| 48 | ParseHouseNumber(MakeUniString(m_house), left); |
| 49 | ParseHouseNumber(MakeUniString(m_house2), right); |
| 50 | |
| 51 | /// @todo Or try to take min/max range. See example here: |
| 52 | /// https://www.openstreetmap.org/way/1118117172 |
| 53 | if (left.size() != 1 || right.size() != 1) |
| 54 | return {}; |
| 55 | |
| 56 | CHECK(!left[0].empty() && !right[0].empty(), (m_house, m_house2)); |
| 57 | auto & l = left[0][0]; |
| 58 | auto & r = right[0][0]; |
| 59 | if (l.m_type != Token::TYPE_NUMBER || r.m_type != Token::TYPE_NUMBER) |
| 60 | return {}; |
| 61 | |
| 62 | uint64_t const li = ToUInt(l.m_value); |
| 63 | uint64_t const ri = ToUInt(r.m_value); |
| 64 | // Zero is a valid HN. |
| 65 | if (li == ri) |
| 66 | return {}; |
| 67 | |
| 68 | UniString sep(1, ':'); |
| 69 | if (li < ri) |
| 70 | { |
| 71 | l.m_value += sep; |
| 72 | l.m_value += r.m_value; |
| 73 | return ToUtf8(l.m_value); |
| 74 | } |
| 75 | else |
| 76 | { |
| 77 | r.m_value += sep; |
| 78 | r.m_value += l.m_value; |
| 79 | return ToUtf8(r.m_value); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | void AddressesHolder::Add(FeatureBuilder const & fb) |
| 84 | { |