mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-07-14 13:41:49 +08:00
Fix loading data from metadata
This commit is contained in:
parent
8792331516
commit
cbd0a27f13
@ -45,13 +45,6 @@ std::string TextConfigurationSerialization::serialize(const TextConfiguration &t
|
|||||||
|
|
||||||
std::optional<TextConfiguration> TextConfigurationSerialization::deserialize(const std::string &data)
|
std::optional<TextConfiguration> TextConfigurationSerialization::deserialize(const std::string &data)
|
||||||
{
|
{
|
||||||
// IMPROVE: make general and move to string utils
|
|
||||||
auto find_separator = [&data](std::string::size_type pos) {
|
|
||||||
pos = data.find(separator, pos);
|
|
||||||
while (pos != data.npos && data[pos + 1] == separator)
|
|
||||||
pos = data.find(separator, pos + 2);
|
|
||||||
return pos;
|
|
||||||
};
|
|
||||||
// IMPROVE: make general and move to string utils
|
// IMPROVE: make general and move to string utils
|
||||||
auto reduce_separator = [](const std::string& item) {
|
auto reduce_separator = [](const std::string& item) {
|
||||||
std::string::size_type pos = item.find(separator);
|
std::string::size_type pos = item.find(separator);
|
||||||
@ -67,33 +60,39 @@ std::optional<TextConfiguration> TextConfigurationSerialization::deserialize(con
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::string::size_type start = 0;
|
std::string::size_type start = 0;
|
||||||
std::string::size_type size = find_separator(start);
|
auto get_column_and_move = [&data, &start](){
|
||||||
auto reduce_and_move = [&data, &start, &size, &reduce_separator, &find_separator]() {
|
// IMPROVE: make function general and move to string utils
|
||||||
|
auto find_separator = [&data](std::string::size_type pos) {
|
||||||
|
pos = data.find(separator, pos);
|
||||||
|
while (pos != data.npos && data[pos + 1] == separator)
|
||||||
|
pos = data.find(separator, pos + 2);
|
||||||
|
return pos;
|
||||||
|
};
|
||||||
|
|
||||||
if (start == data.npos) return std::string();
|
if (start == data.npos) return std::string();
|
||||||
std::string res = reduce_separator(data.substr(start, size));
|
std::string::size_type size = find_separator(start) - start;
|
||||||
start = size + 1;
|
if (size == 0) return std::string();
|
||||||
size = find_separator(start) - start;
|
std::string result = data.substr(start, size);
|
||||||
return res;
|
// move start column to next position
|
||||||
};
|
start += size + 1;
|
||||||
auto get_float_and_move = [&data, &start, &size, &find_separator]() {
|
return result;
|
||||||
if (start == data.npos) return 0.f;
|
|
||||||
float res = std::atof(data.substr(start, size).c_str());
|
|
||||||
start = size + 1;
|
|
||||||
size = find_separator(start) - start;
|
|
||||||
return res;
|
|
||||||
};
|
|
||||||
auto get_int_and_move = [&data, &start, &size, &find_separator]() {
|
|
||||||
if (start == data.npos) return 0;
|
|
||||||
int res = std::atoi(data.substr(start, size).c_str());
|
|
||||||
start = size + 1;
|
|
||||||
size = find_separator(start) - start;
|
|
||||||
return res;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string text = reduce_and_move();
|
auto get_float_and_move = [&get_column_and_move]() {
|
||||||
std::string name = reduce_and_move();
|
std::string column = get_column_and_move();
|
||||||
std::string path = reduce_and_move();
|
if (column.empty()) return 0.f;
|
||||||
std::string type = reduce_and_move();
|
return static_cast<float>(std::atof(column.c_str()));
|
||||||
|
};
|
||||||
|
auto get_int_and_move = [&get_column_and_move]() {
|
||||||
|
std::string column = get_column_and_move();
|
||||||
|
if (column.empty()) return 0;
|
||||||
|
return std::atoi(column.c_str());
|
||||||
|
};
|
||||||
|
|
||||||
|
std::string text = reduce_separator(get_column_and_move());
|
||||||
|
std::string name = reduce_separator(get_column_and_move());
|
||||||
|
std::string path = reduce_separator(get_column_and_move());
|
||||||
|
std::string type = reduce_separator(get_column_and_move());
|
||||||
auto it = to_type.find(type);
|
auto it = to_type.find(type);
|
||||||
if (it == to_type.end()) return {}; // no valid type
|
if (it == to_type.end()) return {}; // no valid type
|
||||||
FontItem font_item(name,path,it->second);
|
FontItem font_item(name,path,it->second);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user