refactoring

This commit is contained in:
2024-12-14 22:15:16 +01:00
parent e7a7ab3cdf
commit dd628868f1
12 changed files with 203 additions and 284 deletions
+4 -23
View File
@@ -1,3 +1,4 @@
#include "../include/useful_funcs.h"
#include <algorithm>
#include <array>
#include <codecvt>
@@ -8,24 +9,6 @@
#include <string>
#include <vector>
std::vector<std::string> splitString(const std::string &str) {
std::vector<std::string> words;
std::string word;
std::istringstream iss(str);
// Use std::getline with ',' as the delimiter
while (std::getline(iss, word, ',')) {
// Trim whitespace from the beginning and end of the word
size_t start = word.find_first_not_of(" \t");
size_t end = word.find_last_not_of(" \t");
if (start != std::string::npos && end != std::string::npos) {
words.push_back(word.substr(start, end - start + 1));
}
}
return words;
}
void MoveElementByIndex(std::vector<int> &vec, int index, int newIndex) {
if (index == newIndex) {
return;
@@ -64,11 +47,9 @@ int main() {
sscanf(line.c_str(), "%d|%d", &RuleTmp[0], &RuleTmp[1]);
rules.push_back(RuleTmp);
} else {
lineSplited = splitString(line);
// transform strings to ints
std::transform(lineSplited.begin(), lineSplited.end(),
std::back_inserter(lineSplitedInt),
[](const std::string &s) { return std::stoi(s); });
lineSplited = splitStringByChar(line, ',');
CastStringVectorToIntVector(lineSplited, lineSplitedInt);
for (int i = 0; i < rules.size(); i++) {
for (int j = 0; j < lineSplitedInt.size(); j++) {
+3 -22
View File
@@ -1,3 +1,4 @@
#include "../include/useful_funcs.h"
#include <algorithm>
#include <array>
#include <codecvt>
@@ -8,24 +9,6 @@
#include <string>
#include <vector>
std::vector<std::string> splitString(const std::string &str) {
std::vector<std::string> words;
std::string word;
std::istringstream iss(str);
// Use std::getline with ',' as the delimiter
while (std::getline(iss, word, ',')) {
// Trim whitespace from the beginning and end of the word
size_t start = word.find_first_not_of(" \t");
size_t end = word.find_last_not_of(" \t");
if (start != std::string::npos && end != std::string::npos) {
words.push_back(word.substr(start, end - start + 1));
}
}
return words;
}
void MoveElementByIndex(std::vector<int> &vec, int index, int newIndex) {
if (index == newIndex) {
return;
@@ -65,10 +48,8 @@ int main() {
rules.push_back(RuleTmp);
} else {
lineSplited = splitString(line);
// transform strings to ints
std::transform(lineSplited.begin(), lineSplited.end(),
std::back_inserter(lineSplitedInt),
[](const std::string &s) { return std::stoi(s); });
CastStringVectorToIntVector(lineSplited, lineSplitedInt);
for (int i = 0; i < rules.size(); i++) {
for (int j = 0; j < lineSplitedInt.size(); j++) {