Merge pull request #43181 from nathanfranke/string-empty
Replace String comparisons with "", String() to is_empty()
This commit is contained in:
commit
bdf8340e59
226 changed files with 1051 additions and 1034 deletions
|
|
@ -413,7 +413,7 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l
|
|||
previous_column = j;
|
||||
|
||||
// ignore if just whitespace
|
||||
if (text != "") {
|
||||
if (!text.is_empty()) {
|
||||
previous_text = text;
|
||||
}
|
||||
}
|
||||
|
|
@ -509,7 +509,7 @@ void GDScriptSyntaxHighlighter::_update_cache() {
|
|||
for (const String &comment : comments) {
|
||||
String beg = comment.get_slice(" ", 0);
|
||||
String end = comment.get_slice_count(" ") > 1 ? comment.get_slice(" ", 1) : String();
|
||||
add_color_region(beg, end, comment_color, end == "");
|
||||
add_color_region(beg, end, comment_color, end.is_empty());
|
||||
}
|
||||
|
||||
/* Strings */
|
||||
|
|
@ -519,7 +519,7 @@ void GDScriptSyntaxHighlighter::_update_cache() {
|
|||
for (const String &string : strings) {
|
||||
String beg = string.get_slice(" ", 0);
|
||||
String end = string.get_slice_count(" ") > 1 ? string.get_slice(" ", 1) : String();
|
||||
add_color_region(beg, end, string_color, end == "");
|
||||
add_color_region(beg, end, string_color, end.is_empty());
|
||||
}
|
||||
|
||||
const Ref<Script> script = _get_edited_resource();
|
||||
|
|
|
|||
|
|
@ -389,7 +389,7 @@ bool GDScript::instance_has(const Object *p_this) const {
|
|||
}
|
||||
|
||||
bool GDScript::has_source_code() const {
|
||||
return source != "";
|
||||
return !source.is_empty();
|
||||
}
|
||||
|
||||
String GDScript::get_source_code() const {
|
||||
|
|
@ -458,7 +458,7 @@ void GDScript::_update_doc() {
|
|||
doc.is_script_doc = true;
|
||||
|
||||
if (base.is_valid() && base->is_valid()) {
|
||||
if (base->doc.name != String()) {
|
||||
if (!base->doc.name.is_empty()) {
|
||||
doc.inherits = base->doc.name;
|
||||
} else {
|
||||
doc.inherits = base->get_instance_base_type();
|
||||
|
|
@ -472,7 +472,7 @@ void GDScript::_update_doc() {
|
|||
doc.tutorials = doc_tutorials;
|
||||
|
||||
for (const KeyValue<String, DocData::EnumDoc> &E : doc_enums) {
|
||||
if (E.value.description != "") {
|
||||
if (!E.value.description.is_empty()) {
|
||||
doc.enums[E.key] = E.value.description;
|
||||
}
|
||||
}
|
||||
|
|
@ -616,11 +616,11 @@ bool GDScript::_update_exports(bool *r_err, bool p_recursive_call, PlaceHolderSc
|
|||
|
||||
String basedir = path;
|
||||
|
||||
if (basedir == "") {
|
||||
if (basedir.is_empty()) {
|
||||
basedir = get_path();
|
||||
}
|
||||
|
||||
if (basedir != "") {
|
||||
if (!basedir.is_empty()) {
|
||||
basedir = basedir.get_base_dir();
|
||||
}
|
||||
|
||||
|
|
@ -642,7 +642,7 @@ bool GDScript::_update_exports(bool *r_err, bool p_recursive_call, PlaceHolderSc
|
|||
path = c->extends_path;
|
||||
if (path.is_relative_path()) {
|
||||
String base = get_path();
|
||||
if (base == "" || base.is_relative_path()) {
|
||||
if (base.is_empty() || base.is_relative_path()) {
|
||||
ERR_PRINT(("Could not resolve relative path for parent class: " + path).utf8().get_data());
|
||||
} else {
|
||||
path = base.get_base_dir().plus_file(path);
|
||||
|
|
@ -656,7 +656,7 @@ bool GDScript::_update_exports(bool *r_err, bool p_recursive_call, PlaceHolderSc
|
|||
}
|
||||
}
|
||||
|
||||
if (path != "") {
|
||||
if (!path.is_empty()) {
|
||||
if (path != get_path()) {
|
||||
Ref<GDScript> bf = ResourceLoader::load(path);
|
||||
|
||||
|
|
@ -809,11 +809,11 @@ Error GDScript::reload(bool p_keep_state) {
|
|||
|
||||
String basedir = path;
|
||||
|
||||
if (basedir == "") {
|
||||
if (basedir.is_empty()) {
|
||||
basedir = get_path();
|
||||
}
|
||||
|
||||
if (basedir != "") {
|
||||
if (!basedir.is_empty()) {
|
||||
basedir = basedir.get_base_dir();
|
||||
}
|
||||
|
||||
|
|
@ -1122,7 +1122,7 @@ String GDScript::_get_gdscript_reference_class_name(const GDScript *p_gdscript)
|
|||
|
||||
String class_name;
|
||||
while (p_gdscript) {
|
||||
if (class_name == "") {
|
||||
if (class_name.is_empty()) {
|
||||
class_name = p_gdscript->get_script_class_name();
|
||||
} else {
|
||||
class_name = p_gdscript->get_script_class_name() + "." + class_name;
|
||||
|
|
@ -1433,7 +1433,7 @@ void GDScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const
|
|||
pinfo.type = Variant::Type(d["type"].operator int());
|
||||
ERR_CONTINUE(pinfo.type < 0 || pinfo.type >= Variant::VARIANT_MAX);
|
||||
pinfo.name = d["name"];
|
||||
ERR_CONTINUE(pinfo.name == "");
|
||||
ERR_CONTINUE(pinfo.name.is_empty());
|
||||
if (d.has("hint")) {
|
||||
pinfo.hint = PropertyHint(d["hint"].operator int());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ void GDScriptCache::remove_script(const String &p_path) {
|
|||
Ref<GDScriptParserRef> GDScriptCache::get_parser(const String &p_path, GDScriptParserRef::Status p_status, Error &r_error, const String &p_owner) {
|
||||
MutexLock lock(singleton->lock);
|
||||
Ref<GDScriptParserRef> ref;
|
||||
if (p_owner != String()) {
|
||||
if (!p_owner.is_empty()) {
|
||||
singleton->dependencies[p_owner].insert(p_path);
|
||||
}
|
||||
if (singleton->parser_map.has(p_path)) {
|
||||
|
|
@ -163,7 +163,7 @@ String GDScriptCache::get_source_code(const String &p_path) {
|
|||
|
||||
Ref<GDScript> GDScriptCache::get_shallow_script(const String &p_path, const String &p_owner) {
|
||||
MutexLock lock(singleton->lock);
|
||||
if (p_owner != String()) {
|
||||
if (!p_owner.is_empty()) {
|
||||
singleton->dependencies[p_owner].insert(p_path);
|
||||
}
|
||||
if (singleton->full_gdscript_cache.has(p_path)) {
|
||||
|
|
@ -186,7 +186,7 @@ Ref<GDScript> GDScriptCache::get_shallow_script(const String &p_path, const Stri
|
|||
Ref<GDScript> GDScriptCache::get_full_script(const String &p_path, Error &r_error, const String &p_owner) {
|
||||
MutexLock lock(singleton->lock);
|
||||
|
||||
if (p_owner != String()) {
|
||||
if (!p_owner.is_empty()) {
|
||||
singleton->dependencies[p_owner].insert(p_path);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ bool GDScriptCompiler::_is_class_member_property(GDScript *owner, const StringNa
|
|||
}
|
||||
|
||||
void GDScriptCompiler::_set_error(const String &p_error, const GDScriptParser::Node *p_node) {
|
||||
if (error != "") {
|
||||
if (!error.is_empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -2020,7 +2020,7 @@ GDScriptFunction *GDScriptCompiler::_parse_function(Error &r_error, GDScript *p_
|
|||
if (EngineDebugger::is_active()) {
|
||||
String signature;
|
||||
// Path.
|
||||
if (p_script->get_path() != String()) {
|
||||
if (!p_script->get_path().is_empty()) {
|
||||
signature += p_script->get_path();
|
||||
}
|
||||
// Location.
|
||||
|
|
@ -2158,7 +2158,7 @@ Error GDScriptCompiler::_parse_class_level(GDScript *p_script, const GDScriptPar
|
|||
p_script->tool = parser->is_tool();
|
||||
p_script->name = p_class->identifier ? p_class->identifier->name : "";
|
||||
|
||||
if (p_script->name != "") {
|
||||
if (!p_script->name.is_empty()) {
|
||||
if (ClassDB::class_exists(p_script->name) && ClassDB::is_class_exposed(p_script->name)) {
|
||||
_set_error("The class '" + p_script->name + "' shadows a native class", p_class);
|
||||
return ERR_ALREADY_EXISTS;
|
||||
|
|
@ -2287,7 +2287,7 @@ Error GDScriptCompiler::_parse_class_level(GDScript *p_script, const GDScriptPar
|
|||
p_script->constants.insert(name, constant->initializer->reduced_value);
|
||||
#ifdef TOOLS_ENABLED
|
||||
p_script->member_lines[name] = constant->start_line;
|
||||
if (constant->doc_description != String()) {
|
||||
if (!constant->doc_description.is_empty()) {
|
||||
p_script->doc_constants[name] = constant->doc_description;
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1365,7 +1365,7 @@ static bool _guess_expression_type(GDScriptParser::CompletionContext &p_context,
|
|||
String arg1 = args[0];
|
||||
if (arg1.begins_with("/root/")) {
|
||||
String which = arg1.get_slice("/", 2);
|
||||
if (which != "") {
|
||||
if (!which.is_empty()) {
|
||||
// Try singletons first
|
||||
if (GDScriptLanguage::get_singleton()->get_named_globals_map().has(which)) {
|
||||
r_type = _type_from_variant(GDScriptLanguage::get_singleton()->get_named_globals_map()[which]);
|
||||
|
|
@ -2753,7 +2753,7 @@ void GDScriptLanguage::auto_indent_code(String &p_code, int p_from_line, int p_t
|
|||
}
|
||||
|
||||
String st = l.substr(tc, l.length()).strip_edges();
|
||||
if (st == "" || st.begins_with("#")) {
|
||||
if (st.is_empty() || st.begins_with("#")) {
|
||||
continue; //ignore!
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3100,7 +3100,7 @@ void GDScriptParser::get_class_doc_comment(int p_line, String &p_brief, String &
|
|||
if (!comments.has(p_line)) {
|
||||
return;
|
||||
}
|
||||
ERR_FAIL_COND(p_brief != "" || p_desc != "" || p_tutorials.size() != 0);
|
||||
ERR_FAIL_COND(!p_brief.is_empty() || !p_desc.is_empty() || p_tutorials.size() != 0);
|
||||
|
||||
int line = p_line;
|
||||
bool in_codeblock = false;
|
||||
|
|
@ -3132,7 +3132,7 @@ void GDScriptParser::get_class_doc_comment(int p_line, String &p_brief, String &
|
|||
String striped_line = doc_line.strip_edges();
|
||||
|
||||
// Set the read mode.
|
||||
if (striped_line.begins_with("@desc:") && p_desc == "") {
|
||||
if (striped_line.begins_with("@desc:") && p_desc.is_empty()) {
|
||||
mode = DESC;
|
||||
striped_line = striped_line.trim_prefix("@desc:");
|
||||
in_codeblock = _in_codeblock(doc_line, in_codeblock);
|
||||
|
|
|
|||
|
|
@ -755,7 +755,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
|
|||
#ifdef DEBUG_ENABLED
|
||||
if (!valid) {
|
||||
String v = index->operator String();
|
||||
if (v != "") {
|
||||
if (!v.is_empty()) {
|
||||
v = "'" + v + "'";
|
||||
} else {
|
||||
v = "of type '" + _get_var_type(index) + "'";
|
||||
|
|
@ -785,7 +785,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
|
|||
#ifdef DEBUG_ENABLED
|
||||
if (!valid) {
|
||||
String v = index->operator String();
|
||||
if (v != "") {
|
||||
if (!v.is_empty()) {
|
||||
v = "'" + v + "'";
|
||||
} else {
|
||||
v = "of type '" + _get_var_type(index) + "'";
|
||||
|
|
@ -817,7 +817,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
|
|||
#ifdef DEBUG_ENABLED
|
||||
if (oob) {
|
||||
String v = index->operator String();
|
||||
if (v != "") {
|
||||
if (!v.is_empty()) {
|
||||
v = "'" + v + "'";
|
||||
} else {
|
||||
v = "of type '" + _get_var_type(index) + "'";
|
||||
|
|
@ -848,7 +848,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
|
|||
#ifdef DEBUG_ENABLED
|
||||
if (!valid) {
|
||||
String v = index->operator String();
|
||||
if (v != "") {
|
||||
if (!v.is_empty()) {
|
||||
v = "'" + v + "'";
|
||||
} else {
|
||||
v = "of type '" + _get_var_type(index) + "'";
|
||||
|
|
@ -884,7 +884,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
|
|||
#ifdef DEBUG_ENABLED
|
||||
if (!valid) {
|
||||
String v = key->operator String();
|
||||
if (v != "") {
|
||||
if (!v.is_empty()) {
|
||||
v = "'" + v + "'";
|
||||
} else {
|
||||
v = "of type '" + _get_var_type(key) + "'";
|
||||
|
|
@ -917,7 +917,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
|
|||
#ifdef DEBUG_ENABLED
|
||||
if (oob) {
|
||||
String v = index->operator String();
|
||||
if (v != "") {
|
||||
if (!v.is_empty()) {
|
||||
v = "'" + v + "'";
|
||||
} else {
|
||||
v = "of type '" + _get_var_type(index) + "'";
|
||||
|
|
@ -3295,20 +3295,20 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
|
|||
//error
|
||||
// function, file, line, error, explanation
|
||||
String err_file;
|
||||
if (p_instance && ObjectDB::get_instance(p_instance->owner_id) != nullptr && p_instance->script->is_valid() && p_instance->script->path != "") {
|
||||
if (p_instance && ObjectDB::get_instance(p_instance->owner_id) != nullptr && p_instance->script->is_valid() && !p_instance->script->path.is_empty()) {
|
||||
err_file = p_instance->script->path;
|
||||
} else if (script) {
|
||||
err_file = script->path;
|
||||
}
|
||||
if (err_file == "") {
|
||||
if (err_file.is_empty()) {
|
||||
err_file = "<built-in>";
|
||||
}
|
||||
String err_func = name;
|
||||
if (p_instance && ObjectDB::get_instance(p_instance->owner_id) != nullptr && p_instance->script->is_valid() && p_instance->script->name != "") {
|
||||
if (p_instance && ObjectDB::get_instance(p_instance->owner_id) != nullptr && p_instance->script->is_valid() && !p_instance->script->name.is_empty()) {
|
||||
err_func = p_instance->script->name + "." + err_func;
|
||||
}
|
||||
int err_line = line;
|
||||
if (err_text == "") {
|
||||
if (err_text.is_empty()) {
|
||||
err_text = "Internal script error! Opcode: " + itos(last_opcode) + " (please report).";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -267,7 +267,7 @@ bool GDScriptTestRunner::generate_class_index() {
|
|||
String base_type;
|
||||
|
||||
String class_name = GDScriptLanguage::get_singleton()->get_global_class_name(test.get_source_file(), &base_type);
|
||||
if (class_name == String()) {
|
||||
if (class_name.is_empty()) {
|
||||
continue;
|
||||
}
|
||||
ERR_FAIL_COND_V_MSG(ScriptServer::is_global_class(class_name), false,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue