Clean up some uses of String::substr

Cases where the end position is either equvalent to the default or past
the end of the string.
This commit is contained in:
A Thousand Ships 2025-02-26 11:41:11 +01:00
parent f2cc3f1275
commit 5113022dfe
No known key found for this signature in database
GPG key ID: DEFC5A5B1306947D
54 changed files with 123 additions and 123 deletions

View file

@ -1096,7 +1096,7 @@ bool ShaderPreprocessor::expand_macros_once(const String &p_line, int p_line_num
int arg_index_start = 0;
int arg_index = 0;
while (find_match(body, arg_name, arg_index, arg_index_start)) {
body = body.substr(0, arg_index) + args[i] + body.substr(arg_index + arg_name.length(), body.length() - (arg_index + arg_name.length()));
body = body.substr(0, arg_index) + args[i] + body.substr(arg_index + arg_name.length());
// Manually reset arg_index_start to where the arg value of the define finishes.
// This ensures we don't skip the other args of this macro in the string.
arg_index_start = arg_index + args[i].length() + 1;
@ -1105,11 +1105,11 @@ bool ShaderPreprocessor::expand_macros_once(const String &p_line, int p_line_num
concatenate_macro_body(body);
result = result.substr(0, index) + " " + body + " " + result.substr(args_end + 1, result.length());
result = result.substr(0, index) + " " + body + " " + result.substr(args_end + 1);
} else {
concatenate_macro_body(body);
result = result.substr(0, index) + " " + body + " " + result.substr(index + key.length(), result.length() - (index + key.length()));
result = result.substr(0, index) + " " + body + " " + result.substr(index + key.length());
}
r_expanded = result;
@ -1176,7 +1176,7 @@ void ShaderPreprocessor::concatenate_macro_body(String &r_body) {
index_start--;
}
r_body = r_body.substr(0, index_start) + r_body.substr(index_end, r_body.length() - index_end);
r_body = r_body.substr(0, index_start) + r_body.substr(index_end);
index_start = r_body.find("##", index_start);
}