Исправлен баг в csv файле

pull/11/head
Igor Belitskiy 3 years ago
parent ede3f7b003
commit e214290f27

@ -109,11 +109,11 @@ void MainWindow::fill_in_view() {
this->view_add_colums(*treeViewKernel); this->view_add_colums(*treeViewKernel);
this->view_add_colums(*treeViewIPT); this->view_add_colums(*treeViewIPT);
this->view_add_colums(*treeViewOTT); this->view_add_colums(*treeViewOTT);
// auto iter = list_store_kernel->prepend();
// row_kernel[m_columns.cmd_set_true];
// cout << cmd << endl;
} }
void MainWindow::item_selected_kernel(const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator&) { void MainWindow::item_selected_kernel(const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator&) {
auto selection_IPT = treeViewIPT->get_selection(); auto selection_IPT = treeViewIPT->get_selection();
auto selection_OTT = treeViewOTT->get_selection(); auto selection_OTT = treeViewOTT->get_selection();

@ -1,28 +1,53 @@
#include "util.h" #include "util.h"
std::array<std::vector<std::string>, 5> read_csv(const std::string& filename) {
std::array<std::vector<std::string>, 5> array_vectors; array<vector<string>, 5> read_csv(const string& filename) {
std::vector<std::string> vec_cmd_get; array<vector<string>, 5> array_vectors;
std::vector<std::string> vec_cmd_set_true; vector<string> vec_cmd_get;
std::vector<std::string> vec_cmd_set_false; vector<string> vec_cmd_set_true;
std::vector<std::string> vec_option; vector<string> vec_cmd_set_false;
std::vector<std::string> vec_opcision; vector<string> vec_option;
std::ifstream file(filename); vector<string> vec_opcision;
std::string line; ifstream file(filename);
string line;
char delimiter = ','; char delimiter = ',';
getline(file, line); getline(file, line);
while (std::getline(file, line)) { while (getline(file, line)) {
std::stringstream stream(line); stringstream stream(line);
std::string cmd_get; string cmd_get;
std::string cmd_set_true; string cmd_set_true;
std::string cmd_set_false; string cmd_set_false;
std::string option; string option;
std::string opcision; string opcision;
getline(stream, cmd_get, delimiter); getline(stream, cmd_get, delimiter);
getline(stream, cmd_set_true, delimiter); getline(stream, cmd_set_true, delimiter);
getline(stream, cmd_set_false, delimiter); getline(stream, cmd_set_false, delimiter);
getline(stream, option, delimiter); getline(stream, option, delimiter);
getline(stream, opcision, delimiter); string line_local = stream.str();
if (line_local.find("\"") != string::npos) {
string str_delimiter = "\"";
vector<int> point = find_all(line_local, str_delimiter);
size_t len = point.size();
if (len >= 2) {
int index_start = point[len-2];
int index_end = point[len-1];
opcision = line_local.substr(index_start, index_end);
index_end = opcision.find("\"");
if (opcision.find("\"") != string::npos) {
opcision.replace(index_end, opcision.length(), "");
}
}
else {
opcision = "error";
}
}
else{
getline(stream, opcision, delimiter);
}
vec_cmd_get.push_back(cmd_get); vec_cmd_get.push_back(cmd_get);
vec_cmd_set_true.push_back(cmd_set_true); vec_cmd_set_true.push_back(cmd_set_true);
vec_cmd_set_false.push_back(cmd_set_false); vec_cmd_set_false.push_back(cmd_set_false);
@ -37,7 +62,7 @@ std::array<std::vector<std::string>, 5> read_csv(const std::string& filename) {
return array_vectors; return array_vectors;
} }
std::string call(std::string cmd) { string call(string cmd) {
FILE *fp; FILE *fp;
int status; int status;
char path[PATH_MAX] = {0}; char path[PATH_MAX] = {0};
@ -53,4 +78,13 @@ std::string call(std::string cmd) {
exit(1); exit(1);
} }
return path; return path;
}
vector<int> find_all(string &str_ntp, string substr) {
size_t index = 0;
vector<int> sub_index;
while ((index = str_ntp.find(substr, index)) != std::string::npos) {
index += substr.length();
sub_index.push_back(index);
}
return sub_index;
} }

@ -6,8 +6,10 @@
#include <array> #include <array>
#include <vector> #include <vector>
#include <linux/limits.h> #include <linux/limits.h>
using namespace std;
std::array<std::vector<std::string>, 5> read_csv(const std::string& filename); std::array<std::vector<std::string>, 5> read_csv(const std::string& filename);
std::string call(std::string cmd); std::string call(std::string cmd);
vector<int> find_all(string &str_ntp, string substr);
Loading…
Cancel
Save