Skip to content

Commit 5113022

Browse files
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.
1 parent f2cc3f1 commit 5113022

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+123
-123
lines changed

core/config/project_settings.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ String ProjectSettings::localize_path(const String &p_path) const {
208208
if (plocal[plocal.length() - 1] == '/') {
209209
sep += 1;
210210
}
211-
return plocal + path.substr(sep, path.size() - sep);
211+
return plocal + path.substr(sep);
212212
}
213213
}
214214

@@ -1129,7 +1129,7 @@ Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_cust
11291129
category = "";
11301130
} else {
11311131
category = category.substr(0, div);
1132-
name = name.substr(div + 1, name.size());
1132+
name = name.substr(div + 1);
11331133
}
11341134
save_props[category].push_back(name);
11351135
}

core/debugger/engine_debugger.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ void EngineDebugger::initialize(const String &p_uri, bool p_skip_breakpoints, co
166166
int sp = bp.rfind_char(':');
167167
ERR_CONTINUE_MSG(sp == -1, vformat("Invalid breakpoint: '%s', expected file:line format.", bp));
168168

169-
singleton_script_debugger->insert_breakpoint(bp.substr(sp + 1, bp.length()).to_int(), bp.substr(0, sp));
169+
singleton_script_debugger->insert_breakpoint(bp.substr(sp + 1).to_int(), bp.substr(0, sp));
170170
}
171171

172172
allow_focus_steal_fn = p_allow_focus_steal_fn;

core/doc_data.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void DocData::return_doc_from_retinfo(DocData::MethodDoc &p_method, const Proper
5151
} else if (p_retinfo.type == Variant::INT && p_retinfo.usage & (PROPERTY_USAGE_CLASS_IS_ENUM | PROPERTY_USAGE_CLASS_IS_BITFIELD)) {
5252
p_method.return_enum = p_retinfo.class_name;
5353
if (p_method.return_enum.begins_with("_")) { //proxy class
54-
p_method.return_enum = p_method.return_enum.substr(1, p_method.return_enum.length());
54+
p_method.return_enum = p_method.return_enum.substr(1);
5555
}
5656
p_method.return_is_bitfield = p_retinfo.usage & PROPERTY_USAGE_CLASS_IS_BITFIELD;
5757
p_method.return_type = "int";
@@ -85,7 +85,7 @@ void DocData::argument_doc_from_arginfo(DocData::ArgumentDoc &p_argument, const
8585
} else if (p_arginfo.type == Variant::INT && p_arginfo.usage & (PROPERTY_USAGE_CLASS_IS_ENUM | PROPERTY_USAGE_CLASS_IS_BITFIELD)) {
8686
p_argument.enumeration = p_arginfo.class_name;
8787
if (p_argument.enumeration.begins_with("_")) { //proxy class
88-
p_argument.enumeration = p_argument.enumeration.substr(1, p_argument.enumeration.length());
88+
p_argument.enumeration = p_argument.enumeration.substr(1);
8989
}
9090
p_argument.is_bitfield = p_arginfo.usage & PROPERTY_USAGE_CLASS_IS_BITFIELD;
9191
p_argument.type = "int";

core/extension/extension_api_dump.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,25 +1420,25 @@ static bool compare_dict_array(const Dictionary &p_old_api, const Dictionary &p_
14201420
bool optional = field.begins_with("*");
14211421
if (optional) {
14221422
// This is an optional field, but if exists it has to exist in both.
1423-
field = field.substr(1, field.length());
1423+
field = field.substr(1);
14241424
}
14251425

14261426
bool added = field.begins_with("+");
14271427
if (added) {
14281428
// Meaning this field must either exist or contents may not exist.
1429-
field = field.substr(1, field.length());
1429+
field = field.substr(1);
14301430
}
14311431

14321432
bool enum_values = field.begins_with("$");
14331433
if (enum_values) {
14341434
// Meaning this field is a list of enum values.
1435-
field = field.substr(1, field.length());
1435+
field = field.substr(1);
14361436
}
14371437

14381438
bool allow_name_change = field.begins_with("@");
14391439
if (allow_name_change) {
14401440
// Meaning that when structurally comparing the old and new value, the dictionary entry 'name' may change.
1441-
field = field.substr(1, field.length());
1441+
field = field.substr(1);
14421442
}
14431443

14441444
Variant old_value;

core/input/input.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ void Input::get_argument_options(const StringName &p_function, int p_idx, List<S
219219
continue;
220220
}
221221

222-
String name = pi.name.substr(pi.name.find_char('/') + 1, pi.name.length());
222+
String name = pi.name.substr(pi.name.find_char('/') + 1);
223223
r_options->push_back(name.quote());
224224
}
225225
}

core/input/input_map.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void InputMap::get_argument_options(const StringName &p_function, int p_idx, Lis
106106
continue;
107107
}
108108

109-
String name = pi.name.substr(pi.name.find_char('/') + 1, pi.name.length());
109+
String name = pi.name.substr(pi.name.find_char('/') + 1);
110110
r_options->push_back(name.quote());
111111
}
112112
}
@@ -304,7 +304,7 @@ void InputMap::load_from_project_settings() {
304304
continue;
305305
}
306306

307-
String name = pi.name.substr(pi.name.find_char('/') + 1, pi.name.length());
307+
String name = pi.name.substr(pi.name.find_char('/') + 1);
308308

309309
Dictionary action = GLOBAL_GET(pi.name);
310310
float deadzone = action.has("deadzone") ? (float)action["deadzone"] : DEFAULT_DEADZONE;

core/io/http_client.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ Dictionary HTTPClient::_get_response_headers_as_dictionary() {
118118
continue;
119119
}
120120
String key = s.substr(0, sp).strip_edges();
121-
String value = s.substr(sp + 1, s.length()).strip_edges();
121+
String value = s.substr(sp + 1).strip_edges();
122122
ret[key] = value;
123123
}
124124

core/io/http_client_tcp.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ Error HTTPClientTCP::connect_to_host(const String &p_host, int p_port, Ref<TLSOp
5050

5151
String host_lower = conn_host.to_lower();
5252
if (host_lower.begins_with("http://")) {
53-
conn_host = conn_host.substr(7, conn_host.length() - 7);
53+
conn_host = conn_host.substr(7);
5454
tls_options.unref();
5555
} else if (host_lower.begins_with("https://")) {
5656
if (tls_options.is_null()) {
5757
tls_options = TLSOptions::client();
5858
}
59-
conn_host = conn_host.substr(8, conn_host.length() - 8);
59+
conn_host = conn_host.substr(8);
6060
}
6161

6262
ERR_FAIL_COND_V(tls_options.is_valid() && tls_options->is_server(), ERR_INVALID_PARAMETER);
@@ -508,11 +508,11 @@ Error HTTPClientTCP::poll() {
508508
continue;
509509
}
510510
if (s.begins_with("content-length:")) {
511-
body_size = s.substr(s.find_char(':') + 1, s.length()).strip_edges().to_int();
511+
body_size = s.substr(s.find_char(':') + 1).strip_edges().to_int();
512512
body_left = body_size;
513513

514514
} else if (s.begins_with("transfer-encoding:")) {
515-
String encoding = header.substr(header.find_char(':') + 1, header.length()).strip_edges();
515+
String encoding = header.substr(header.find_char(':') + 1).strip_edges();
516516
if (encoding == "chunked") {
517517
chunked = true;
518518
}

core/io/ip_address.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ void IPAddress::_parse_ipv6(const String &p_string) {
148148
void IPAddress::_parse_ipv4(const String &p_string, int p_start, uint8_t *p_ret) {
149149
String ip;
150150
if (p_start != 0) {
151-
ip = p_string.substr(p_start, p_string.length() - p_start);
151+
ip = p_string.substr(p_start);
152152
} else {
153153
ip = p_string;
154154
}

core/io/translation_loader_po.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ Ref<Resource> TranslationLoaderPO::load_translation(Ref<FileAccess> f, Error *r_
189189
}
190190
}
191191
msg_context = "";
192-
l = l.substr(7, l.length()).strip_edges();
192+
l = l.substr(7).strip_edges();
193193
status = STATUS_READING_CONTEXT;
194194
entered_context = true;
195195
}
@@ -202,7 +202,7 @@ Ref<Resource> TranslationLoaderPO::load_translation(Ref<FileAccess> f, Error *r_
202202
}
203203
// We don't record the message in "msgid_plural" itself as tr_n(), TTRN(), RTRN() interfaces provide the plural string already.
204204
// We just have to reset variables related to plurals for "msgstr[]" later on.
205-
l = l.substr(12, l.length()).strip_edges();
205+
l = l.substr(12).strip_edges();
206206
plural_index = -1;
207207
msgs_plural.clear();
208208
msgs_plural.resize(plural_forms);
@@ -230,7 +230,7 @@ Ref<Resource> TranslationLoaderPO::load_translation(Ref<FileAccess> f, Error *r_
230230
}
231231
}
232232

233-
l = l.substr(5, l.length()).strip_edges();
233+
l = l.substr(5).strip_edges();
234234
status = STATUS_READING_ID;
235235
// If we did not encounter msgctxt, we reset context to empty to reset it.
236236
if (!entered_context) {
@@ -246,10 +246,10 @@ Ref<Resource> TranslationLoaderPO::load_translation(Ref<FileAccess> f, Error *r_
246246
if (l.begins_with("msgstr[")) {
247247
ERR_FAIL_COND_V_MSG(status != STATUS_READING_PLURAL, Ref<Resource>(), vformat("Unexpected 'msgstr[]', was expecting 'msgid_plural' before 'msgstr[]' while parsing: %s:%d.", path, line));
248248
plural_index++; // Increment to add to the next slot in vector msgs_plural.
249-
l = l.substr(9, l.length()).strip_edges();
249+
l = l.substr(9).strip_edges();
250250
} else if (l.begins_with("msgstr")) {
251251
ERR_FAIL_COND_V_MSG(status != STATUS_READING_ID, Ref<Resource>(), vformat("Unexpected 'msgstr', was expecting 'msgid' before 'msgstr' while parsing: %s:%d.", path, line));
252-
l = l.substr(6, l.length()).strip_edges();
252+
l = l.substr(6).strip_edges();
253253
status = STATUS_READING_STRING;
254254
}
255255

@@ -263,7 +263,7 @@ Ref<Resource> TranslationLoaderPO::load_translation(Ref<FileAccess> f, Error *r_
263263

264264
ERR_FAIL_COND_V_MSG(!l.begins_with("\"") || status == STATUS_NONE, Ref<Resource>(), vformat("Invalid line '%s' while parsing: %s:%d.", l, path, line));
265265

266-
l = l.substr(1, l.length());
266+
l = l.substr(1);
267267
// Find final quote, ignoring escaped ones (\").
268268
// The escape_next logic is necessary to properly parse things like \\"
269269
// where the backslash is the one being escaped, not the quote.
@@ -329,7 +329,7 @@ Ref<Resource> TranslationLoaderPO::load_translation(Ref<FileAccess> f, Error *r_
329329
continue;
330330
}
331331
String prop = c.substr(0, p).strip_edges();
332-
String value = c.substr(p + 1, c.length()).strip_edges();
332+
String value = c.substr(p + 1).strip_edges();
333333

334334
if (prop == "X-Language" || prop == "Language") {
335335
translation->set_locale(value);

0 commit comments

Comments
 (0)