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

Function FillEmptyNames

libs/map/bookmark_helpers.cpp:381–417  ·  view source on GitHub ↗

Populate empty category & track names based on file name: assign file name to category name, if there is only one unnamed track - assign file name to it, otherwise add numbers 1, 2, 3... to file name to build names for all unnamed tracks

Source from the content-addressed store, hash-verified

379// if there is only one unnamed track - assign file name to it, otherwise add numbers 1, 2, 3...
380// to file name to build names for all unnamed tracks
381void FillEmptyNames(std::unique_ptr<kml::FileData> & kmlData, std::string const & file)
382{
383 auto start = file.find_last_of('/') + 1;
384 auto end = file.find_last_of('.');
385 if (end == std::string::npos)
386 end = file.size();
387 auto const name = file.substr(start, end - start);
388
389 if (kmlData->m_categoryData.m_name.empty())
390 kmlData->m_categoryData.m_name[kml::kDefaultLang] = name;
391
392 if (kmlData->m_tracksData.empty())
393 return;
394
395 auto const emptyNames = std::count_if(kmlData->m_tracksData.begin(), kmlData->m_tracksData.end(),
396 [](kml::TrackData const & t) { return t.m_name.empty(); });
397 if (emptyNames == 0)
398 return;
399
400 auto emptyTrackNum = 1;
401 for (auto & track : kmlData->m_tracksData)
402 {
403 if (track.m_name.empty())
404 {
405 if (emptyNames == 1)
406 {
407 track.m_name[kml::kDefaultLang] = name;
408 return;
409 }
410 else
411 {
412 track.m_name[kml::kDefaultLang] = name + " " + std::to_string(emptyTrackNum);
413 emptyTrackNum++;
414 }
415 }
416 }
417}
418
419std::unique_ptr<kml::FileData> LoadKmlFile(std::string const & file, KmlFileType fileType)
420{

Callers 1

LoadKmlFileFunction · 0.85

Calls 5

to_stringFunction · 0.85
sizeMethod · 0.45
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected