Skip to content

Commit

Permalink
Refactor: removed std::string dependencies, using QString in KML-parser
Browse files Browse the repository at this point in the history
  • Loading branch information
denizdiktas committed Jun 24, 2023
1 parent a7bbef7 commit 4f616f4
Showing 1 changed file with 6 additions and 49 deletions.
55 changes: 6 additions & 49 deletions Arrangement_on_surface_2/demo/earth/Kml_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,6 @@
#include <qfile.h>
#include <qxmlstream.h>

namespace {

std::vector<std::string> split(const std::string& str, const char *delim)
{
std::string sc = str;
char* token = strtok(sc.data(), delim);
char* str_end = token + str.length();

// Keep printing tokens while one of the delimiters present in str[].
std::vector<std::string> results;
while (token != NULL)
{
const auto first = token;
//printf("%s\n", token);
token = strtok(NULL, " ");
results.push_back(std::string(first, token==nullptr ? str_end : token));
}

return results;
}
}

Kml::Placemarks Kml::read(const std::string& file_name)
{
Expand Down Expand Up @@ -64,40 +43,18 @@ Kml::Placemarks Kml::read(const std::string& file_name)
else if (name == "coordinates")
{
xmlReader.readNext();
auto qstr = xmlReader.text().toString();
auto ptr = qstr.data();
auto str = qstr.toUtf8().toStdString();
auto node_strs = split(str, " ");

auto str = xmlReader.text().toString();
auto node_strs = str.split(" ");
for (const auto& node_str : node_strs)
{
if (node_str.empty())
if (node_str.isEmpty())
continue;

auto coord_strs = split(node_str, ",");
const auto lon = std::stod(coord_strs[0]);
const auto lat = std::stod(coord_strs[1]);
auto coord_strs = node_str.split(",");
const auto lon = coord_strs[0].toDouble();
const auto lat = coord_strs[1].toDouble();
lring.nodes.push_back(Node{ lon, lat });
}


//qDebug() << "---------------------------------------";
//for (const auto& node_str : node_strs)
// std::cout << node_str << std::endl;

//qDebug() << qstr;
//auto node_qstrs = qstr.split(" ");
//qDebug() << node_qstrs.size();
//for (const auto& node_str : node_strs)
//{
// if (node_str.isEmpty())
// continue;

// auto coord_strs = node_str.split(",");
// const auto lon = coord_strs[0].toDouble();
// const auto lat = coord_strs[1].toDouble();
// lring.nodes.push_back(Node{ lon, lat });
//}
}
else if (name == "SimpleData")
{
Expand Down

0 comments on commit 4f616f4

Please sign in to comment.