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:
@ -118,7 +118,7 @@ Dictionary HTTPClient::_get_response_headers_as_dictionary() {
|
||||
continue;
|
||||
}
|
||||
String key = s.substr(0, sp).strip_edges();
|
||||
String value = s.substr(sp + 1, s.length()).strip_edges();
|
||||
String value = s.substr(sp + 1).strip_edges();
|
||||
ret[key] = value;
|
||||
}
|
||||
|
||||
|
||||
@ -50,13 +50,13 @@ Error HTTPClientTCP::connect_to_host(const String &p_host, int p_port, Ref<TLSOp
|
||||
|
||||
String host_lower = conn_host.to_lower();
|
||||
if (host_lower.begins_with("http://")) {
|
||||
conn_host = conn_host.substr(7, conn_host.length() - 7);
|
||||
conn_host = conn_host.substr(7);
|
||||
tls_options.unref();
|
||||
} else if (host_lower.begins_with("https://")) {
|
||||
if (tls_options.is_null()) {
|
||||
tls_options = TLSOptions::client();
|
||||
}
|
||||
conn_host = conn_host.substr(8, conn_host.length() - 8);
|
||||
conn_host = conn_host.substr(8);
|
||||
}
|
||||
|
||||
ERR_FAIL_COND_V(tls_options.is_valid() && tls_options->is_server(), ERR_INVALID_PARAMETER);
|
||||
@ -508,11 +508,11 @@ Error HTTPClientTCP::poll() {
|
||||
continue;
|
||||
}
|
||||
if (s.begins_with("content-length:")) {
|
||||
body_size = s.substr(s.find_char(':') + 1, s.length()).strip_edges().to_int();
|
||||
body_size = s.substr(s.find_char(':') + 1).strip_edges().to_int();
|
||||
body_left = body_size;
|
||||
|
||||
} else if (s.begins_with("transfer-encoding:")) {
|
||||
String encoding = header.substr(header.find_char(':') + 1, header.length()).strip_edges();
|
||||
String encoding = header.substr(header.find_char(':') + 1).strip_edges();
|
||||
if (encoding == "chunked") {
|
||||
chunked = true;
|
||||
}
|
||||
|
||||
@ -148,7 +148,7 @@ void IPAddress::_parse_ipv6(const String &p_string) {
|
||||
void IPAddress::_parse_ipv4(const String &p_string, int p_start, uint8_t *p_ret) {
|
||||
String ip;
|
||||
if (p_start != 0) {
|
||||
ip = p_string.substr(p_start, p_string.length() - p_start);
|
||||
ip = p_string.substr(p_start);
|
||||
} else {
|
||||
ip = p_string;
|
||||
}
|
||||
|
||||
@ -189,7 +189,7 @@ Ref<Resource> TranslationLoaderPO::load_translation(Ref<FileAccess> f, Error *r_
|
||||
}
|
||||
}
|
||||
msg_context = "";
|
||||
l = l.substr(7, l.length()).strip_edges();
|
||||
l = l.substr(7).strip_edges();
|
||||
status = STATUS_READING_CONTEXT;
|
||||
entered_context = true;
|
||||
}
|
||||
@ -202,7 +202,7 @@ Ref<Resource> TranslationLoaderPO::load_translation(Ref<FileAccess> f, Error *r_
|
||||
}
|
||||
// We don't record the message in "msgid_plural" itself as tr_n(), TTRN(), RTRN() interfaces provide the plural string already.
|
||||
// We just have to reset variables related to plurals for "msgstr[]" later on.
|
||||
l = l.substr(12, l.length()).strip_edges();
|
||||
l = l.substr(12).strip_edges();
|
||||
plural_index = -1;
|
||||
msgs_plural.clear();
|
||||
msgs_plural.resize(plural_forms);
|
||||
@ -230,7 +230,7 @@ Ref<Resource> TranslationLoaderPO::load_translation(Ref<FileAccess> f, Error *r_
|
||||
}
|
||||
}
|
||||
|
||||
l = l.substr(5, l.length()).strip_edges();
|
||||
l = l.substr(5).strip_edges();
|
||||
status = STATUS_READING_ID;
|
||||
// If we did not encounter msgctxt, we reset context to empty to reset it.
|
||||
if (!entered_context) {
|
||||
@ -246,10 +246,10 @@ Ref<Resource> TranslationLoaderPO::load_translation(Ref<FileAccess> f, Error *r_
|
||||
if (l.begins_with("msgstr[")) {
|
||||
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));
|
||||
plural_index++; // Increment to add to the next slot in vector msgs_plural.
|
||||
l = l.substr(9, l.length()).strip_edges();
|
||||
l = l.substr(9).strip_edges();
|
||||
} else if (l.begins_with("msgstr")) {
|
||||
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));
|
||||
l = l.substr(6, l.length()).strip_edges();
|
||||
l = l.substr(6).strip_edges();
|
||||
status = STATUS_READING_STRING;
|
||||
}
|
||||
|
||||
@ -263,7 +263,7 @@ Ref<Resource> TranslationLoaderPO::load_translation(Ref<FileAccess> f, Error *r_
|
||||
|
||||
ERR_FAIL_COND_V_MSG(!l.begins_with("\"") || status == STATUS_NONE, Ref<Resource>(), vformat("Invalid line '%s' while parsing: %s:%d.", l, path, line));
|
||||
|
||||
l = l.substr(1, l.length());
|
||||
l = l.substr(1);
|
||||
// Find final quote, ignoring escaped ones (\").
|
||||
// The escape_next logic is necessary to properly parse things like \\"
|
||||
// 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_
|
||||
continue;
|
||||
}
|
||||
String prop = c.substr(0, p).strip_edges();
|
||||
String value = c.substr(p + 1, c.length()).strip_edges();
|
||||
String value = c.substr(p + 1).strip_edges();
|
||||
|
||||
if (prop == "X-Language" || prop == "Language") {
|
||||
translation->set_locale(value);
|
||||
|
||||
Reference in New Issue
Block a user