diff options
author | Nathan Franke <natfra@pm.me> | 2021-12-09 03:42:46 -0600 |
---|---|---|
committer | Nathan Franke <natfra@pm.me> | 2021-12-09 04:48:38 -0600 |
commit | 49403cbfa0399bb4284ea5c36cc90216a0bda6ff (patch) | |
tree | caa6c7249d35d83b288a180a4f5d7e4fd959704f /core/input | |
parent | 31ded7e126b9d71ed8dddab9ffc1ce813f1a8ec2 (diff) |
Replace String comparisons with "", String() to is_empty()
Also:
- Adds two stress tests to test_string.h
- Changes to .empty() on std::strings
Diffstat (limited to 'core/input')
-rw-r--r-- | core/input/input.cpp | 8 | ||||
-rw-r--r-- | core/input/input_event.cpp | 10 | ||||
-rw-r--r-- | core/input/input_map.cpp | 6 |
3 files changed, 12 insertions, 12 deletions
diff --git a/core/input/input.cpp b/core/input/input.cpp index b72d980681..3dfe73ab8e 100644 --- a/core/input/input.cpp +++ b/core/input/input.cpp @@ -403,7 +403,7 @@ void Input::joy_connection_changed(int p_idx, bool p_connected, String p_name, S if (p_connected) { String uidname = p_guid; - if (p_guid == "") { + if (p_guid.is_empty()) { int uidlen = MIN(p_name.length(), 16); for (int i = 0; i < uidlen; i++) { uidname = uidname + _hex_str(p_name[i]); @@ -1249,7 +1249,7 @@ void Input::parse_mapping(String p_mapping) { int idx = 1; while (++idx < entry.size()) { - if (entry[idx] == "") { + if (entry[idx].is_empty()) { continue; } @@ -1420,10 +1420,10 @@ Input::Input() { // If defined, parse SDL_GAMECONTROLLERCONFIG for possible new mappings/overrides. String env_mapping = OS::get_singleton()->get_environment("SDL_GAMECONTROLLERCONFIG"); - if (env_mapping != "") { + if (!env_mapping.is_empty()) { Vector<String> entries = env_mapping.split("\n"); for (int i = 0; i < entries.size(); i++) { - if (entries[i] == "") { + if (entries[i].is_empty()) { continue; } parse_mapping(entries[i]); diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp index ccde8838e1..7c98fa9540 100644 --- a/core/input/input_event.cpp +++ b/core/input/input_event.cpp @@ -360,12 +360,12 @@ String InputEventKey::as_text() const { kc = keycode_get_string(keycode); } - if (kc == String()) { + if (kc.is_empty()) { return kc; } String mods_text = InputEventWithModifiers::as_text(); - return mods_text == "" ? kc : mods_text + "+" + kc; + return mods_text.is_empty() ? kc : mods_text + "+" + kc; } String InputEventKey::to_string() { @@ -382,7 +382,7 @@ String InputEventKey::to_string() { } String mods = InputEventWithModifiers::as_text(); - mods = mods == "" ? TTR("none") : mods; + mods = mods.is_empty() ? TTR("none") : mods; return vformat("InputEventKey: keycode=%s, mods=%s, physical=%s, pressed=%s, echo=%s", kc, mods, physical, p, e); } @@ -634,7 +634,7 @@ static const char *_mouse_button_descriptions[9] = { String InputEventMouseButton::as_text() const { // Modifiers String mods_text = InputEventWithModifiers::as_text(); - String full_string = mods_text == "" ? "" : mods_text + "+"; + String full_string = mods_text.is_empty() ? "" : mods_text + "+"; // Button MouseButton idx = get_button_index(); @@ -687,7 +687,7 @@ String InputEventMouseButton::to_string() { } String mods = InputEventWithModifiers::as_text(); - mods = mods == "" ? TTR("none") : mods; + mods = mods.is_empty() ? TTR("none") : mods; // Work around the fact vformat can only take 5 substitutions but 6 need to be passed. String index_and_mods = vformat("button_index=%s, mods=%s", button_index, mods); diff --git a/core/input/input_map.cpp b/core/input/input_map.cpp index 84e1313756..183a2c3e68 100644 --- a/core/input/input_map.cpp +++ b/core/input/input_map.cpp @@ -718,7 +718,7 @@ const OrderedHashMap<String, List<Ref<InputEvent>>> &InputMap::get_builtins_with String name = split[0]; String override_for = split.size() > 1 ? split[1] : String(); - if (override_for != String() && OS::get_singleton()->has_feature(override_for)) { + if (!override_for.is_empty() && OS::get_singleton()->has_feature(override_for)) { builtins_with_overrides[name].push_back(override_for); } } @@ -730,12 +730,12 @@ const OrderedHashMap<String, List<Ref<InputEvent>>> &InputMap::get_builtins_with String name = split[0]; String override_for = split.size() > 1 ? split[1] : String(); - if (builtins_with_overrides.has(name) && override_for == String()) { + if (builtins_with_overrides.has(name) && override_for.is_empty()) { // Builtin has an override but this particular one is not an override, so skip. continue; } - if (override_for != String() && !OS::get_singleton()->has_feature(override_for)) { + if (!override_for.is_empty() && !OS::get_singleton()->has_feature(override_for)) { // OS does not support this override - skip. continue; } |