mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-11 16:57:53 -06:00
Const correctness improvements:
removed some unnecessary const_casts that remove const.
This commit is contained in:
parent
30f7a2b8e5
commit
9406b50447
13 changed files with 41 additions and 40 deletions
|
@ -630,39 +630,38 @@ size_t ConfigBase::load_from_gcode_string(const char* str)
|
|||
return 0;
|
||||
|
||||
// Walk line by line in reverse until a non-configuration key appears.
|
||||
char *data_start = const_cast<char*>(str);
|
||||
const char *data_start = str;
|
||||
// boost::nowide::ifstream seems to cook the text data somehow, so less then the 64k of characters may be retrieved.
|
||||
char *end = data_start + strlen(str);
|
||||
const char *end = data_start + strlen(str);
|
||||
size_t num_key_value_pairs = 0;
|
||||
for (;;) {
|
||||
// Extract next line.
|
||||
for (--end; end > data_start && (*end == '\r' || *end == '\n'); --end);
|
||||
if (end == data_start)
|
||||
break;
|
||||
char *start = end;
|
||||
*(++end) = 0;
|
||||
const char *start = end ++;
|
||||
for (; start > data_start && *start != '\r' && *start != '\n'; --start);
|
||||
if (start == data_start)
|
||||
break;
|
||||
// Extracted a line from start to end. Extract the key = value pair.
|
||||
if (end - (++start) < 10 || start[0] != ';' || start[1] != ' ')
|
||||
if (end - (++ start) < 10 || start[0] != ';' || start[1] != ' ')
|
||||
break;
|
||||
char *key = start + 2;
|
||||
const char *key = start + 2;
|
||||
if (!(*key >= 'a' && *key <= 'z') || (*key >= 'A' && *key <= 'Z'))
|
||||
// A key must start with a letter.
|
||||
break;
|
||||
char *sep = strchr(key, '=');
|
||||
if (sep == nullptr || sep[-1] != ' ' || sep[1] != ' ')
|
||||
const char *sep = key;
|
||||
for (; sep != end && *sep != '='; ++ sep) ;
|
||||
if (sep == end || sep[-1] != ' ' || sep[1] != ' ')
|
||||
break;
|
||||
char *value = sep + 2;
|
||||
const char *value = sep + 2;
|
||||
if (value > end)
|
||||
break;
|
||||
char *key_end = sep - 1;
|
||||
const char *key_end = sep - 1;
|
||||
if (key_end - key < 3)
|
||||
break;
|
||||
*key_end = 0;
|
||||
// The key may contain letters, digits and underscores.
|
||||
for (char *c = key; c != key_end; ++c)
|
||||
for (const char *c = key; c != key_end; ++ c)
|
||||
if (!((*c >= 'a' && *c <= 'z') || (*c >= 'A' && *c <= 'Z') || (*c >= '0' && *c <= '9') || *c == '_')) {
|
||||
key = nullptr;
|
||||
break;
|
||||
|
@ -670,7 +669,7 @@ size_t ConfigBase::load_from_gcode_string(const char* str)
|
|||
if (key == nullptr)
|
||||
break;
|
||||
try {
|
||||
this->set_deserialize(key, value);
|
||||
this->set_deserialize(std::string(key, key_end), std::string(value, end));
|
||||
++num_key_value_pairs;
|
||||
}
|
||||
catch (UnknownOptionException & /* e */) {
|
||||
|
@ -760,15 +759,15 @@ ConfigOption* DynamicConfig::optptr(const t_config_option_key &opt_key, bool cre
|
|||
|
||||
void DynamicConfig::read_cli(const std::vector<std::string> &tokens, t_config_option_keys* extra, t_config_option_keys* keys)
|
||||
{
|
||||
std::vector<char*> args;
|
||||
std::vector<const char*> args;
|
||||
// push a bogus executable name (argv[0])
|
||||
args.emplace_back(const_cast<char*>(""));
|
||||
args.emplace_back("");
|
||||
for (size_t i = 0; i < tokens.size(); ++ i)
|
||||
args.emplace_back(const_cast<char *>(tokens[i].c_str()));
|
||||
this->read_cli(int(args.size()), &args[0], extra, keys);
|
||||
args.emplace_back(tokens[i].c_str());
|
||||
this->read_cli(int(args.size()), args.data(), extra, keys);
|
||||
}
|
||||
|
||||
bool DynamicConfig::read_cli(int argc, char** argv, t_config_option_keys* extra, t_config_option_keys* keys)
|
||||
bool DynamicConfig::read_cli(int argc, const char* const argv[], t_config_option_keys* extra, t_config_option_keys* keys)
|
||||
{
|
||||
// cache the CLI option => opt_key mapping
|
||||
std::map<std::string,std::string> opts;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue