MCPcopy Create free account
hub / github.com/comaps/comaps / FormatRange

Method FormatRange

generator/addresses_collector.cpp:40–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38} // namespace
39
40std::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
83void AddressesHolder::Add(FeatureBuilder const & fb)
84{

Callers 2

UpdateMethod · 0.80
UNIT_TESTFunction · 0.80

Calls 6

ParseHouseNumberFunction · 0.85
MakeUniStringFunction · 0.85
ToUIntFunction · 0.85
ToUtf8Function · 0.50
emptyMethod · 0.45
sizeMethod · 0.45

Tested by 1

UNIT_TESTFunction · 0.64