Skip to content

Commit

Permalink
Use (r)find_char instead of (r)find for single characters
Browse files Browse the repository at this point in the history
  • Loading branch information
AThousandShips committed Nov 17, 2024
1 parent 5efd124 commit 68f638c
Show file tree
Hide file tree
Showing 70 changed files with 169 additions and 169 deletions.
8 changes: 4 additions & 4 deletions core/config/project_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ String ProjectSettings::localize_path(const String &p_path) const {

return cwd.replace_first(res_path, "res://");
} else {
int sep = path.rfind("/");
int sep = path.rfind_char('/');
if (sep == -1) {
return "res://" + path;
}
Expand Down Expand Up @@ -300,7 +300,7 @@ bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) {
}

{ // Feature overrides.
int dot = p_name.operator String().find(".");
int dot = p_name.operator String().find_char('.');
if (dot != -1) {
Vector<String> s = p_name.operator String().split(".");

Expand Down Expand Up @@ -435,7 +435,7 @@ void ProjectSettings::_get_property_list(List<PropertyInfo> *p_list) const {

for (const _VCSort &E : vclist) {
String prop_info_name = E.name;
int dot = prop_info_name.find(".");
int dot = prop_info_name.find_char('.');
if (dot != -1 && !custom_prop_info.has(prop_info_name)) {
prop_info_name = prop_info_name.substr(0, dot);
}
Expand Down Expand Up @@ -1092,7 +1092,7 @@ Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_cust
String category = E.name;
String name = E.name;

int div = category.find("/");
int div = category.find_char('/');

if (div < 0) {
category = "";
Expand Down
2 changes: 1 addition & 1 deletion core/debugger/engine_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void EngineDebugger::initialize(const String &p_uri, bool p_skip_breakpoints, co

for (int i = 0; i < p_breakpoints.size(); i++) {
const String &bp = p_breakpoints[i];
int sp = bp.rfind(":");
int sp = bp.rfind_char(':');
ERR_CONTINUE_MSG(sp == -1, vformat("Invalid breakpoint: '%s', expected file:line format.", bp));

singleton_script_debugger->insert_breakpoint(bp.substr(sp + 1, bp.length()).to_int(), bp.substr(0, sp));
Expand Down
4 changes: 2 additions & 2 deletions core/debugger/local_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {

} else {
String key_value = line.get_slicec(' ', 1);
int value_pos = key_value.find("=");
int value_pos = key_value.find_char('=');

if (value_pos < 0) {
print_line("Error: Invalid set format. Use: set key=value");
Expand Down Expand Up @@ -344,7 +344,7 @@ Pair<String, int> LocalDebugger::to_breakpoint(const String &p_line) {
String breakpoint_part = p_line.get_slicec(' ', 1);
Pair<String, int> breakpoint;

int last_colon = breakpoint_part.rfind(":");
int last_colon = breakpoint_part.rfind_char(':');
if (last_colon < 0) {
print_line("Error: Invalid breakpoint format. Expected [source:line]");
return breakpoint;
Expand Down
4 changes: 2 additions & 2 deletions core/debugger/remote_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ void RemoteDebugger::_send_stack_vars(List<String> &p_names, List<Variant> &p_va
}

Error RemoteDebugger::_try_capture(const String &p_msg, const Array &p_data, bool &r_captured) {
const int idx = p_msg.find(":");
const int idx = p_msg.find_char(':');
r_captured = false;
if (idx < 0) { // No prefix, unknown message.
return OK;
Expand Down Expand Up @@ -610,7 +610,7 @@ void RemoteDebugger::poll_events(bool p_is_idle) {
ERR_CONTINUE(arr[1].get_type() != Variant::ARRAY);

const String cmd = arr[0];
const int idx = cmd.find(":");
const int idx = cmd.find_char(':');
bool parsed = false;
if (idx < 0) { // Not prefix, use scripts capture.
capture_parse("core", cmd, arr[1], parsed);
Expand Down
2 changes: 1 addition & 1 deletion core/debugger/remote_debugger_peer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ RemoteDebuggerPeer *RemoteDebuggerPeerTCP::create(const String &p_uri) {
uint16_t debug_port = 6007;

if (debug_host.contains(":")) {
int sep_pos = debug_host.rfind(":");
int sep_pos = debug_host.rfind_char(':');
debug_port = debug_host.substr(sep_pos + 1).to_int();
debug_host = debug_host.substr(0, sep_pos);
}
Expand Down
2 changes: 1 addition & 1 deletion core/input/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ void Input::get_argument_options(const StringName &p_function, int p_idx, List<S
continue;
}

String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length());
String name = pi.name.substr(pi.name.find_char('/') + 1, pi.name.length());
r_options->push_back(name.quote());
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/input/input_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void InputMap::get_argument_options(const StringName &p_function, int p_idx, Lis
continue;
}

String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length());
String name = pi.name.substr(pi.name.find_char('/') + 1, pi.name.length());
r_options->push_back(name.quote());
}
}
Expand Down Expand Up @@ -302,7 +302,7 @@ void InputMap::load_from_project_settings() {
continue;
}

String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length());
String name = pi.name.substr(pi.name.find_char('/') + 1, pi.name.length());

Dictionary action = GLOBAL_GET(pi.name);
float deadzone = action.has("deadzone") ? (float)action["deadzone"] : DEFAULT_DEADZONE;
Expand Down
4 changes: 2 additions & 2 deletions core/io/dir_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ Error DirAccess::make_dir_recursive(const String &p_dir) {
} else if (full_dir.begins_with("user://")) {
base = "user://";
} else if (full_dir.is_network_share_path()) {
int pos = full_dir.find("/", 2);
int pos = full_dir.find_char('/', 2);
ERR_FAIL_COND_V(pos < 0, ERR_INVALID_PARAMETER);
pos = full_dir.find("/", pos + 1);
pos = full_dir.find_char('/', pos + 1);
ERR_FAIL_COND_V(pos < 0, ERR_INVALID_PARAMETER);
base = full_dir.substr(0, pos + 1);
} else if (full_dir.begins_with("/")) {
Expand Down
4 changes: 2 additions & 2 deletions core/io/http_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Error HTTPClient::verify_headers(const Vector<String> &p_headers) {
for (int i = 0; i < p_headers.size(); i++) {
String sanitized = p_headers[i].strip_edges();
ERR_FAIL_COND_V_MSG(sanitized.is_empty(), ERR_INVALID_PARAMETER, vformat("Invalid HTTP header at index %d: empty.", i));
ERR_FAIL_COND_V_MSG(sanitized.find(":") < 1, ERR_INVALID_PARAMETER,
ERR_FAIL_COND_V_MSG(sanitized.find_char(':') < 1, ERR_INVALID_PARAMETER,
vformat("Invalid HTTP header at index %d: String must contain header-value pair, delimited by ':', but was: '%s'.", i, p_headers[i]));
}

Expand All @@ -113,7 +113,7 @@ Dictionary HTTPClient::_get_response_headers_as_dictionary() {
get_response_headers(&rh);
Dictionary ret;
for (const String &s : rh) {
int sp = s.find(":");
int sp = s.find_char(':');
if (sp == -1) {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions core/io/http_client_tcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,11 +508,11 @@ Error HTTPClientTCP::poll() {
continue;
}
if (s.begins_with("content-length:")) {
body_size = s.substr(s.find(":") + 1, s.length()).strip_edges().to_int();
body_size = s.substr(s.find_char(':') + 1, s.length()).strip_edges().to_int();
body_left = body_size;

} else if (s.begins_with("transfer-encoding:")) {
String encoding = header.substr(header.find(":") + 1, header.length()).strip_edges();
String encoding = header.substr(header.find_char(':') + 1, header.length()).strip_edges();
if (encoding == "chunked") {
chunked = true;
}
Expand Down
8 changes: 4 additions & 4 deletions core/io/plist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,12 +661,12 @@ bool PList::load_string(const String &p_string, String &r_err_out) {
List<Ref<PListNode>> stack;
String key;
while (pos >= 0) {
int open_token_s = p_string.find("<", pos);
int open_token_s = p_string.find_char('<', pos);
if (open_token_s == -1) {
r_err_out = "Unexpected end of data. No tags found.";
return false;
}
int open_token_e = p_string.find(">", open_token_s);
int open_token_e = p_string.find_char('>', open_token_s);
pos = open_token_e;

String token = p_string.substr(open_token_s + 1, open_token_e - open_token_s - 1);
Expand All @@ -676,7 +676,7 @@ bool PList::load_string(const String &p_string, String &r_err_out) {
}
String value;
if (token[0] == '?' || token[0] == '!') { // Skip <?xml ... ?> and <!DOCTYPE ... >
int end_token_e = p_string.find(">", open_token_s);
int end_token_e = p_string.find_char('>', open_token_s);
pos = end_token_e;
continue;
}
Expand Down Expand Up @@ -769,7 +769,7 @@ bool PList::load_string(const String &p_string, String &r_err_out) {
r_err_out = vformat("Mismatched <%s> tag.", token);
return false;
}
int end_token_e = p_string.find(">", end_token_s);
int end_token_e = p_string.find_char('>', end_token_s);
pos = end_token_e;
String end_token = p_string.substr(end_token_s + 2, end_token_e - end_token_s - 2);
if (end_token != token) {
Expand Down
6 changes: 3 additions & 3 deletions core/io/resource_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_rem

int best_score = 0;
for (int i = 0; i < res_remaps.size(); i++) {
int split = res_remaps[i].rfind(":");
int split = res_remaps[i].rfind_char(':');
if (split == -1) {
continue;
}
Expand Down Expand Up @@ -1498,11 +1498,11 @@ Vector<String> ResourceLoader::list_directory(const String &p_directory) {
}
} else {
if (d.ends_with(".import") || d.ends_with(".remap") || d.ends_with(".uid")) {
d = d.substr(0, d.rfind("."));
d = d.substr(0, d.rfind_char('.'));
}

if (d.ends_with(".gdc")) {
d = d.substr(0, d.rfind("."));
d = d.substr(0, d.rfind_char('.'));
d += ".gd";
}

Expand Down
6 changes: 3 additions & 3 deletions core/io/translation_loader_po.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Ref<Resource> TranslationLoaderPO::load_translation(Ref<FileAccess> f, Error *r_
// Record plural rule.
int p_start = config.find("Plural-Forms");
if (p_start != -1) {
int p_end = config.find("\n", p_start);
int p_end = config.find_char('\n', p_start);
translation->set_plural_rule(config.substr(p_start, p_end - p_start));
}
} else {
Expand Down Expand Up @@ -224,7 +224,7 @@ Ref<Resource> TranslationLoaderPO::load_translation(Ref<FileAccess> f, Error *r_
// Record plural rule.
int p_start = config.find("Plural-Forms");
if (p_start != -1) {
int p_end = config.find("\n", p_start);
int p_end = config.find_char('\n', p_start);
translation->set_plural_rule(config.substr(p_start, p_end - p_start));
plural_forms = translation->get_plural_forms();
}
Expand Down Expand Up @@ -324,7 +324,7 @@ Ref<Resource> TranslationLoaderPO::load_translation(Ref<FileAccess> f, Error *r_
Vector<String> configs = config.split("\n");
for (int i = 0; i < configs.size(); i++) {
String c = configs[i].strip_edges();
int p = c.find(":");
int p = c.find_char(':');
if (p == -1) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion core/string/node_path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ NodePath::NodePath(const String &p_path) {
bool absolute = (path[0] == '/');
bool last_is_slash = true;
int slices = 0;
int subpath_pos = path.find(":");
int subpath_pos = path.find_char(':');

if (subpath_pos != -1) {
int from = subpath_pos + 1;
Expand Down
8 changes: 4 additions & 4 deletions core/string/translation_po.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,11 @@ void TranslationPO::set_plural_rule(const String &p_plural_rule) {
// Set plural_forms and plural_rule.
// p_plural_rule passed in has the form "Plural-Forms: nplurals=2; plural=(n >= 2);".

int first_semi_col = p_plural_rule.find(";");
plural_forms = p_plural_rule.substr(p_plural_rule.find("=") + 1, first_semi_col - (p_plural_rule.find("=") + 1)).to_int();
int first_semi_col = p_plural_rule.find_char(';');
plural_forms = p_plural_rule.substr(p_plural_rule.find_char('=') + 1, first_semi_col - (p_plural_rule.find_char('=') + 1)).to_int();

int expression_start = p_plural_rule.find("=", first_semi_col) + 1;
int second_semi_col = p_plural_rule.rfind(";");
int expression_start = p_plural_rule.find_char('=', first_semi_col) + 1;
int second_semi_col = p_plural_rule.rfind_char(';');
plural_rule = p_plural_rule.substr(expression_start, second_semi_col - expression_start).strip_edges();

// Setup the cache to make evaluating plural rule faster later on.
Expand Down
Loading

0 comments on commit 68f638c

Please sign in to comment.