Skip to content

Commit

Permalink
Merge pull request #43181 from nathanfranke/string-empty
Browse files Browse the repository at this point in the history
Replace String comparisons with "", String() to is_empty()
  • Loading branch information
akien-mga authored Dec 10, 2021
2 parents 5ad9d8b + 49403cb commit bdf8340
Show file tree
Hide file tree
Showing 226 changed files with 1,051 additions and 1,034 deletions.
38 changes: 19 additions & 19 deletions core/config/project_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ String ProjectSettings::localize_path(const String &p_path) const {
String parent = path.substr(0, sep);

String plocal = localize_path(parent);
if (plocal == "") {
if (plocal.is_empty()) {
return "";
}
// Only strip the starting '/' from 'path' if its parent ('plocal') ends with '/'
Expand Down Expand Up @@ -228,13 +228,13 @@ bool ProjectSettings::get_ignore_value_in_docs(const String &p_name) const {

String ProjectSettings::globalize_path(const String &p_path) const {
if (p_path.begins_with("res://")) {
if (resource_path != "") {
if (!resource_path.is_empty()) {
return p_path.replace("res:/", resource_path);
}
return p_path.replace("res://", "");
} else if (p_path.begins_with("user://")) {
String data_dir = OS::get_singleton()->get_user_data_dir();
if (data_dir != "") {
if (!data_dir.is_empty()) {
return p_path.replace("user:/", data_dir);
}
return p_path.replace("user://", "");
Expand Down Expand Up @@ -456,7 +456,7 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b

// Attempt with a user-defined main pack first

if (p_main_pack != "") {
if (!p_main_pack.is_empty()) {
bool ok = _load_resource_pack(p_main_pack);
ERR_FAIL_COND_V_MSG(!ok, ERR_CANT_OPEN, "Cannot open resource pack '" + p_main_pack + "'.");

Expand All @@ -471,7 +471,7 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b

String exec_path = OS::get_singleton()->get_executable_path();

if (exec_path != "") {
if (!exec_path.is_empty()) {
// We do several tests sequentially until one succeeds to find a PCK,
// and if so, we attempt loading it at the end.

Expand Down Expand Up @@ -523,11 +523,11 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b
// Try to use the filesystem for files, according to OS.
// (Only Android -when reading from pck- and iOS use this.)

if (OS::get_singleton()->get_resource_dir() != "") {
if (!OS::get_singleton()->get_resource_dir().is_empty()) {
// OS will call ProjectSettings->get_resource_path which will be empty if not overridden!
// If the OS would rather use a specific location, then it will not be empty.
resource_path = OS::get_singleton()->get_resource_dir().replace("\\", "/");
if (resource_path != "" && resource_path[resource_path.length() - 1] == '/') {
if (!resource_path.is_empty() && resource_path[resource_path.length() - 1] == '/') {
resource_path = resource_path.substr(0, resource_path.length() - 1); // Chop end.
}

Expand Down Expand Up @@ -591,7 +591,7 @@ Error ProjectSettings::setup(const String &p_path, const String &p_main_pack, bo
Error err = _setup(p_path, p_main_pack, p_upwards, p_ignore_override);
if (err == OK) {
String custom_settings = GLOBAL_DEF("application/config/project_settings_override", "");
if (custom_settings != "") {
if (!custom_settings.is_empty()) {
_load_settings_text(custom_settings);
}
}
Expand Down Expand Up @@ -699,21 +699,21 @@ Error ProjectSettings::_load_settings_text(const String &p_path) {
return err;
}

if (assign != String()) {
if (section == String() && assign == "config_version") {
if (!assign.is_empty()) {
if (section.is_empty() && assign == "config_version") {
config_version = value;
if (config_version > CONFIG_VERSION) {
memdelete(f);
ERR_FAIL_V_MSG(ERR_FILE_CANT_OPEN, vformat("Can't open project at '%s', its `config_version` (%d) is from a more recent and incompatible version of the engine. Expected config version: %d.", p_path, config_version, CONFIG_VERSION));
}
} else {
if (section == String()) {
if (section.is_empty()) {
set(assign, value);
} else {
set(section + "/" + assign, value);
}
}
} else if (next_tag.name != String()) {
} else if (!next_tag.name.is_empty()) {
section = next_tag.name;
}
}
Expand Down Expand Up @@ -797,7 +797,7 @@ Error ProjectSettings::_save_settings_binary(const String &p_file, const Map<Str
count += E.value.size();
}

if (p_custom_features != String()) {
if (!p_custom_features.is_empty()) {
file->store_32(count + 1);
//store how many properties are saved, add one for custom featuers, which must always go first
String key = CoreStringNames::get_singleton()->_custom_features;
Expand Down Expand Up @@ -827,7 +827,7 @@ Error ProjectSettings::_save_settings_binary(const String &p_file, const Map<Str

for (Map<String, List<String>>::Element *E = props.front(); E; E = E->next()) {
for (String &key : E->get()) {
if (E->key() != "") {
if (!E->key().is_empty()) {
key = E->key() + "/" + key;
}
Variant value;
Expand Down Expand Up @@ -881,7 +881,7 @@ Error ProjectSettings::_save_settings_text(const String &p_file, const Map<Strin
file->store_line("");

file->store_string("config_version=" + itos(CONFIG_VERSION) + "\n");
if (p_custom_features != String()) {
if (!p_custom_features.is_empty()) {
file->store_string("custom_features=\"" + p_custom_features + "\"\n");
}
file->store_string("\n");
Expand All @@ -891,12 +891,12 @@ Error ProjectSettings::_save_settings_text(const String &p_file, const Map<Strin
file->store_string("\n");
}

if (E->key() != "") {
if (!E->key().is_empty()) {
file->store_string("[" + E->key() + "]\n\n");
}
for (const String &F : E->get()) {
String key = F;
if (E->key() != "") {
if (!E->key().is_empty()) {
key = E->key() + "/" + key;
}
Variant value;
Expand Down Expand Up @@ -924,7 +924,7 @@ Error ProjectSettings::_save_custom_bnd(const String &p_file) { // add other par
}

Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_custom, const Vector<String> &p_custom_features, bool p_merge_with_current) {
ERR_FAIL_COND_V_MSG(p_path == "", ERR_INVALID_PARAMETER, "Project settings save path cannot be empty.");
ERR_FAIL_COND_V_MSG(p_path.is_empty(), ERR_INVALID_PARAMETER, "Project settings save path cannot be empty.");

PackedStringArray project_features = has_setting("application/config/features") ? (PackedStringArray)get_setting("application/config/features") : PackedStringArray();
// If there is no feature list currently present, force one to generate.
Expand All @@ -933,7 +933,7 @@ Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_cust
}
// Check the rendering API.
const String rendering_api = has_setting("rendering/quality/driver/driver_name") ? (String)get_setting("rendering/quality/driver/driver_name") : String();
if (rendering_api != "") {
if (!rendering_api.is_empty()) {
// Add the rendering API as a project feature if it doesn't already exist.
if (!project_features.has(rendering_api)) {
project_features.append(rendering_api);
Expand Down
8 changes: 4 additions & 4 deletions core/core_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1483,7 +1483,7 @@ String Directory::get_next() {
ERR_FAIL_COND_V_MSG(!is_open(), "", "Directory must be opened before use.");

String next = d->get_next();
while (next != "" && ((_list_skip_navigational && (next == "." || next == "..")) || (_list_skip_hidden && d->current_is_hidden()))) {
while (!next.is_empty() && ((_list_skip_navigational && (next == "." || next == "..")) || (_list_skip_hidden && d->current_is_hidden()))) {
next = d->get_next();
}
return next;
Expand Down Expand Up @@ -1665,7 +1665,7 @@ String Marshalls::variant_to_base64(const Variant &p_var, bool p_full_objects) {
ERR_FAIL_COND_V_MSG(err != OK, "", "Error when trying to encode Variant.");

String ret = CryptoCore::b64_encode_str(&w[0], len);
ERR_FAIL_COND_V(ret == "", ret);
ERR_FAIL_COND_V(ret.is_empty(), ret);

return ret;
}
Expand All @@ -1690,7 +1690,7 @@ Variant Marshalls::base64_to_variant(const String &p_str, bool p_allow_objects)

String Marshalls::raw_to_base64(const Vector<uint8_t> &p_arr) {
String ret = CryptoCore::b64_encode_str(p_arr.ptr(), p_arr.size());
ERR_FAIL_COND_V(ret == "", ret);
ERR_FAIL_COND_V(ret.is_empty(), ret);
return ret;
}

Expand All @@ -1714,7 +1714,7 @@ Vector<uint8_t> Marshalls::base64_to_raw(const String &p_str) {
String Marshalls::utf8_to_base64(const String &p_str) {
CharString cstr = p_str.utf8();
String ret = CryptoCore::b64_encode_str((unsigned char *)cstr.get_data(), cstr.length());
ERR_FAIL_COND_V(ret == "", ret);
ERR_FAIL_COND_V(ret.is_empty(), ret);
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion core/debugger/local_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
// Cache options
String variable_prefix = options["variable_prefix"];

if (line == "") {
if (line.is_empty()) {
print_line("\nDebugger Break, Reason: '" + script_lang->debug_get_error() + "'");
print_line("*Frame " + itos(current_frame) + " - " + script_lang->debug_get_stack_level_source(current_frame) + ":" + itos(script_lang->debug_get_stack_level_line(current_frame)) + " in function '" + script_lang->debug_get_stack_level_function(current_frame) + "'");
print_line("Enter \"help\" for assistance.");
Expand Down
4 changes: 2 additions & 2 deletions core/doc_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
void DocData::return_doc_from_retinfo(DocData::MethodDoc &p_method, const PropertyInfo &p_retinfo) {
if (p_retinfo.type == Variant::INT && p_retinfo.hint == PROPERTY_HINT_INT_IS_POINTER) {
p_method.return_type = p_retinfo.hint_string;
if (p_method.return_type == "") {
if (p_method.return_type.is_empty()) {
p_method.return_type = "void*";
} else {
p_method.return_type += "*";
Expand Down Expand Up @@ -64,7 +64,7 @@ void DocData::argument_doc_from_arginfo(DocData::ArgumentDoc &p_argument, const

if (p_arginfo.type == Variant::INT && p_arginfo.hint == PROPERTY_HINT_INT_IS_POINTER) {
p_argument.type = p_arginfo.hint_string;
if (p_argument.type == "") {
if (p_argument.type.is_empty()) {
p_argument.type = "void*";
} else {
p_argument.type += "*";
Expand Down
4 changes: 2 additions & 2 deletions core/extension/extension_api_dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

static String get_type_name(const PropertyInfo &p_info) {
if (p_info.type == Variant::INT && (p_info.hint == PROPERTY_HINT_INT_IS_POINTER)) {
if (p_info.hint_string == "") {
if (p_info.hint_string.is_empty()) {
return "void*";
} else {
return p_info.hint_string + "*";
Expand Down Expand Up @@ -340,7 +340,7 @@ Dictionary NativeExtensionAPIDump::generate_extension_api() {
int value = CoreConstants::get_global_constant_value(i);
String enum_name = CoreConstants::get_global_constant_enum(i);
String name = CoreConstants::get_global_constant_name(i);
if (enum_name != String()) {
if (!enum_name.is_empty()) {
enum_list[enum_name].push_back(Pair<String, int>(name, value));
} else {
Dictionary d;
Expand Down
2 changes: 1 addition & 1 deletion core/extension/native_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ RES NativeExtensionResourceLoader::load(const String &p_path, const String &p_or
}
}

if (library_path == String()) {
if (library_path.is_empty()) {
if (r_error) {
*r_error = ERR_FILE_NOT_FOUND;
}
Expand Down
2 changes: 1 addition & 1 deletion core/extension/native_extension_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void NativeExtensionManager::load_extensions() {
FileAccessRef f = FileAccess::open(NativeExtension::get_extension_list_config_file(), FileAccess::READ);
while (f && !f->eof_reached()) {
String s = f->get_line().strip_edges();
if (s != String()) {
if (!s.is_empty()) {
LoadStatus err = load_extension(s);
ERR_CONTINUE_MSG(err == LOAD_STATUS_FAILED, "Error loading extension: " + s);
}
Expand Down
8 changes: 4 additions & 4 deletions core/input/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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]);
Expand Down
10 changes: 5 additions & 5 deletions core/input/input_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions core/input/input_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions core/io/config_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ Error ConfigFile::_internal_save(FileAccess *file) {
if (E != values.front()) {
file->store_string("\n");
}
if (E.key() != "") {
if (!E.key().is_empty()) {
file->store_string("[" + E.key() + "]\n\n");
}

Expand Down Expand Up @@ -287,9 +287,9 @@ Error ConfigFile::_parse(const String &p_path, VariantParser::Stream *p_stream)
return err;
}

if (assign != String()) {
if (!assign.is_empty()) {
set_value(section, assign, value);
} else if (next_tag.name != String()) {
} else if (!next_tag.name.is_empty()) {
section = next_tag.name;
}
}
Expand Down
Loading

0 comments on commit bdf8340

Please sign in to comment.