-
-
Notifications
You must be signed in to change notification settings - Fork 477
Expand file tree
/
Copy pathdomain-matcher.hpp
More file actions
50 lines (42 loc) · 1.33 KB
/
domain-matcher.hpp
File metadata and controls
50 lines (42 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef OSM2PGSQL_DOMAIN_MATCHER_HPP
#define OSM2PGSQL_DOMAIN_MATCHER_HPP
/**
* SPDX-License-Identifier: GPL-2.0-or-later
*
* This file is part of osm2pgsql (https://osm2pgsql.org/).
*
* Copyright (C) 2006-2025 by the osm2pgsql developer community.
* For a full list of authors see the git log.
*/
#include <osmium/osm/tag.hpp>
#include <cstring>
/**
* Returns the tag specific name, if applicable.
*
* OSM tags may contain name tags that refer to one of the other tags
* in the tag set. For example, the name of a bridge is tagged as
* bridge:name=Foo to not confuse it with the name of the highway
* going over the bridge. This matcher checks if a tag is such a name tag
* for the given tag key and returns the name key without the prefix
* if it matches.
*/
class DomainMatcher
{
public:
explicit DomainMatcher(char const *cls) noexcept
: m_domain(cls), m_len(std::strlen(cls))
{}
char const *operator()(osmium::Tag const &t) const noexcept
{
if (std::strncmp(t.key(), m_domain, m_len) == 0 &&
std::strncmp(t.key() + m_len, ":name", 5) == 0 &&
(t.key()[m_len + 5] == '\0' || t.key()[m_len + 5] == ':')) {
return t.key() + m_len + 1;
}
return nullptr;
}
private:
char const *m_domain;
size_t m_len;
};
#endif // OSM2PGSQL_DOMAIN_MATCHER_HPP