1
0
Fork 0

Codechange: replace StrMakeValidInPlace with StrValid

pull/10970/head
Rubidium 2023-06-08 16:58:17 +02:00 committed by rubidium42
parent 4ca23a19b6
commit 2ae7367024
2 changed files with 22 additions and 23 deletions

View File

@ -138,10 +138,11 @@ SQInteger ScriptText::_set(HSQUIRRELVM vm)
if (sq_gettype(vm, 2) == OT_STRING) { if (sq_gettype(vm, 2) == OT_STRING) {
const SQChar *key_string; const SQChar *key_string;
sq_getstring(vm, 2, &key_string); sq_getstring(vm, 2, &key_string);
StrMakeValidInPlace(const_cast<char *>(key_string));
if (strncmp(key_string, "param_", 6) != 0 || strlen(key_string) > 8) return SQ_ERROR; std::string str = StrMakeValid(key_string);
k = atoi(key_string + 6); if (!StrStartsWith(str, "param_") || str.size() > 8) return SQ_ERROR;
k = stoi(str.substr(6));
} else if (sq_gettype(vm, 2) == OT_INTEGER) { } else if (sq_gettype(vm, 2) == OT_INTEGER) {
SQInteger key; SQInteger key;
sq_getinteger(vm, 2, &key); sq_getinteger(vm, 2, &key);

View File

@ -90,11 +90,11 @@ SQInteger ScriptInfo::AddSetting(HSQUIRRELVM vm)
/* Read the table, and find all properties we care about */ /* Read the table, and find all properties we care about */
sq_pushnull(vm); sq_pushnull(vm);
while (SQ_SUCCEEDED(sq_next(vm, -2))) { while (SQ_SUCCEEDED(sq_next(vm, -2))) {
const SQChar *key; const SQChar *key_string;
if (SQ_FAILED(sq_getstring(vm, -2, &key))) return SQ_ERROR; if (SQ_FAILED(sq_getstring(vm, -2, &key_string))) return SQ_ERROR;
StrMakeValidInPlace(const_cast<char *>(key)); std::string key = StrMakeValid(key_string);
if (strcmp(key, "name") == 0) { if (key == "name") {
const SQChar *sqvalue; const SQChar *sqvalue;
if (SQ_FAILED(sq_getstring(vm, -1, &sqvalue))) return SQ_ERROR; if (SQ_FAILED(sq_getstring(vm, -1, &sqvalue))) return SQ_ERROR;
@ -104,51 +104,51 @@ SQInteger ScriptInfo::AddSetting(HSQUIRRELVM vm)
config.name = StrMakeValid(sqvalue); config.name = StrMakeValid(sqvalue);
std::replace_if(config.name.begin(), config.name.end(), replace_with_underscore, '_'); std::replace_if(config.name.begin(), config.name.end(), replace_with_underscore, '_');
items |= 0x001; items |= 0x001;
} else if (strcmp(key, "description") == 0) { } else if (key == "description") {
const SQChar *sqdescription; const SQChar *sqdescription;
if (SQ_FAILED(sq_getstring(vm, -1, &sqdescription))) return SQ_ERROR; if (SQ_FAILED(sq_getstring(vm, -1, &sqdescription))) return SQ_ERROR;
config.description = StrMakeValid(sqdescription); config.description = StrMakeValid(sqdescription);
items |= 0x002; items |= 0x002;
} else if (strcmp(key, "min_value") == 0) { } else if (key == "min_value") {
SQInteger res; SQInteger res;
if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR; if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
config.min_value = ClampTo<int32_t>(res); config.min_value = ClampTo<int32_t>(res);
items |= 0x004; items |= 0x004;
} else if (strcmp(key, "max_value") == 0) { } else if (key == "max_value") {
SQInteger res; SQInteger res;
if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR; if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
config.max_value = ClampTo<int32_t>(res); config.max_value = ClampTo<int32_t>(res);
items |= 0x008; items |= 0x008;
} else if (strcmp(key, "easy_value") == 0) { } else if (key == "easy_value") {
SQInteger res; SQInteger res;
if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR; if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
config.easy_value = ClampTo<int32_t>(res); config.easy_value = ClampTo<int32_t>(res);
items |= 0x010; items |= 0x010;
} else if (strcmp(key, "medium_value") == 0) { } else if (key == "medium_value") {
SQInteger res; SQInteger res;
if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR; if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
config.medium_value = ClampTo<int32_t>(res); config.medium_value = ClampTo<int32_t>(res);
items |= 0x020; items |= 0x020;
} else if (strcmp(key, "hard_value") == 0) { } else if (key == "hard_value") {
SQInteger res; SQInteger res;
if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR; if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
config.hard_value = ClampTo<int32_t>(res); config.hard_value = ClampTo<int32_t>(res);
items |= 0x040; items |= 0x040;
} else if (strcmp(key, "random_deviation") == 0) { } else if (key == "random_deviation") {
SQInteger res; SQInteger res;
if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR; if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
config.random_deviation = ClampTo<int32_t>(abs(res)); config.random_deviation = ClampTo<int32_t>(abs(res));
items |= 0x200; items |= 0x200;
} else if (strcmp(key, "custom_value") == 0) { } else if (key == "custom_value") {
SQInteger res; SQInteger res;
if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR; if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
config.custom_value = ClampTo<int32_t>(res); config.custom_value = ClampTo<int32_t>(res);
items |= 0x080; items |= 0x080;
} else if (strcmp(key, "step_size") == 0) { } else if (key == "step_size") {
SQInteger res; SQInteger res;
if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR; if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
config.step_size = ClampTo<int32_t>(res); config.step_size = ClampTo<int32_t>(res);
} else if (strcmp(key, "flags") == 0) { } else if (key == "flags") {
SQInteger res; SQInteger res;
if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR; if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR;
config.flags = (ScriptConfigFlags)res; config.flags = (ScriptConfigFlags)res;
@ -184,9 +184,9 @@ SQInteger ScriptInfo::AddSetting(HSQUIRRELVM vm)
SQInteger ScriptInfo::AddLabels(HSQUIRRELVM vm) SQInteger ScriptInfo::AddLabels(HSQUIRRELVM vm)
{ {
const SQChar *setting_name; const SQChar *setting_name_str;
if (SQ_FAILED(sq_getstring(vm, -2, &setting_name))) return SQ_ERROR; if (SQ_FAILED(sq_getstring(vm, -2, &setting_name_str))) return SQ_ERROR;
StrMakeValidInPlace(const_cast<char *>(setting_name)); std::string setting_name = StrMakeValid(setting_name_str);
ScriptConfigItem *config = nullptr; ScriptConfigItem *config = nullptr;
for (auto &item : this->config_list) { for (auto &item : this->config_list) {
@ -216,9 +216,7 @@ SQInteger ScriptInfo::AddLabels(HSQUIRRELVM vm)
key_string++; key_string++;
} }
int key = atoi(key_string) * sign; int key = atoi(key_string) * sign;
StrMakeValidInPlace(const_cast<char *>(label)); config->labels[key] = StrMakeValid(label);
config->labels[key] = label;
sq_pop(vm, 2); sq_pop(vm, 2);
} }