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

Function ParseMapCSS

generator/utils.cpp:160–233  ·  view source on GitHub ↗

The data/mapcss-mapping.csv format is described inside the file itself.

Source from the content-addressed store, hash-verified

158
159// The data/mapcss-mapping.csv format is described inside the file itself.
160MapcssRules ParseMapCSS(std::unique_ptr<Reader> reader)
161{
162 ReaderStreamBuf buffer(std::move(reader));
163 std::istream data(&buffer);
164 data.exceptions(std::fstream::badbit);
165
166 MapcssRules rules;
167
168 auto const processShort = [&rules](std::string const & typeString)
169 {
170 auto typeTokens = strings::Tokenize<std::string>(typeString, "|");
171 CHECK(typeTokens.size() == 2, (typeString));
172 MapcssRule rule;
173 rule.m_tags = {{typeTokens[0], typeTokens[1]}};
174 rules.emplace_back(std::move(typeTokens), std::move(rule));
175 };
176
177 auto const processFull = [&rules](std::string const & typeString, std::string const & selectorsString)
178 {
179 ASSERT(!typeString.empty(), ());
180 ASSERT(!selectorsString.empty(), ());
181
182 auto const typeTokens = strings::Tokenize<std::string>(typeString, "|");
183 strings::Tokenize(selectorsString, ",", [&typeTokens, &rules](std::string_view selector)
184 {
185 ASSERT_EQUAL(selector.front(), '[', ());
186 ASSERT_EQUAL(selector.back(), ']', ());
187
188 MapcssRule rule;
189 strings::Tokenize(selector, "[]", [&rule](std::string_view kv)
190 {
191 auto const tag = strings::Tokenize(kv, "=");
192 if (tag.size() == 1)
193 {
194 auto const forbidden = (tag[0][0] == '!');
195
196 std::string v(tag[0]);
197 strings::Trim(v, "?!");
198 if (forbidden)
199 rule.m_forbiddenKeys.push_back(std::move(v));
200 else
201 rule.m_mandatoryKeys.push_back(std::move(v));
202 }
203 else
204 {
205 ASSERT_EQUAL(tag.size(), 2, (tag));
206 rule.m_tags.emplace_back(tag[0], tag[1]);
207 }
208 });
209
210 rules.emplace_back(typeTokens, std::move(rule));
211 });
212 };
213
214 std::string line;
215 while (std::getline(data, line))
216 {
217 if (line.empty() || line.front() == '#')

Callers 1

MatchTypesFunction · 0.85

Calls 10

ASSERTFunction · 0.85
TrimFunction · 0.85
ParseCSVRowFunction · 0.85
frontMethod · 0.80
backMethod · 0.80
TokenizeFunction · 0.50
sizeMethod · 0.45
emplace_backMethod · 0.45
emptyMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected