diff options
author | Anilforextra <anilforextra@gmail.com> | 2022-02-03 21:48:38 +0545 |
---|---|---|
committer | Anilforextra <anilforextra@gmail.com> | 2022-02-04 01:28:02 +0545 |
commit | adbe948bda202209b55249198e1837324e703ddb (patch) | |
tree | a7f424318e1d944e0564edb6fc55e8eabf266bd0 /core | |
parent | bf12719ccabcea9bf9b274f77511e02581678774 (diff) |
String: Add contains().
Diffstat (limited to 'core')
-rw-r--r-- | core/debugger/remote_debugger_peer.cpp | 2 | ||||
-rw-r--r-- | core/io/dir_access.cpp | 2 | ||||
-rw-r--r-- | core/io/file_access.cpp | 2 | ||||
-rw-r--r-- | core/io/file_access_pack.cpp | 2 | ||||
-rw-r--r-- | core/io/resource.h | 2 | ||||
-rw-r--r-- | core/io/resource_format_binary.cpp | 4 | ||||
-rw-r--r-- | core/io/translation_loader_po.cpp | 2 | ||||
-rw-r--r-- | core/object/class_db.cpp | 2 | ||||
-rw-r--r-- | core/string/ustring.h | 2 | ||||
-rw-r--r-- | core/variant/variant_call.cpp | 1 | ||||
-rw-r--r-- | core/variant/variant_parser.cpp | 2 |
11 files changed, 13 insertions, 10 deletions
diff --git a/core/debugger/remote_debugger_peer.cpp b/core/debugger/remote_debugger_peer.cpp index 8c6e95e276..7c7d38ab0a 100644 --- a/core/debugger/remote_debugger_peer.cpp +++ b/core/debugger/remote_debugger_peer.cpp @@ -226,7 +226,7 @@ RemoteDebuggerPeer *RemoteDebuggerPeerTCP::create(const String &p_uri) { String debug_host = p_uri.replace("tcp://", ""); uint16_t debug_port = 6007; - if (debug_host.find(":") != -1) { + if (debug_host.contains(":")) { int sep_pos = debug_host.rfind(":"); debug_port = debug_host.substr(sep_pos + 1).to_int(); debug_host = debug_host.substr(0, sep_pos); diff --git a/core/io/dir_access.cpp b/core/io/dir_access.cpp index db0758d7fc..86d8dea3d9 100644 --- a/core/io/dir_access.cpp +++ b/core/io/dir_access.cpp @@ -159,7 +159,7 @@ Error DirAccess::make_dir_recursive(String p_dir) { base = full_dir.substr(0, pos + 1); } else if (full_dir.begins_with("/")) { base = "/"; - } else if (full_dir.find(":/") != -1) { + } else if (full_dir.contains(":/")) { base = full_dir.substr(0, full_dir.find(":/") + 2); } else { ERR_FAIL_V(ERR_INVALID_PARAMETER); diff --git a/core/io/file_access.cpp b/core/io/file_access.cpp index bb92648484..86836454c5 100644 --- a/core/io/file_access.cpp +++ b/core/io/file_access.cpp @@ -538,7 +538,7 @@ void FileAccess::store_csv_line(const Vector<String> &p_values, const String &p_ for (int i = 0; i < size; ++i) { String value = p_values[i]; - if (value.find("\"") != -1 || value.find(p_delim) != -1 || value.find("\n") != -1) { + if (value.contains("\"") || value.contains(p_delim) || value.contains("\n")) { value = "\"" + value.replace("\"", "\"\"") + "\""; } if (i < size - 1) { diff --git a/core/io/file_access_pack.cpp b/core/io/file_access_pack.cpp index 3882627103..7dbea96c3d 100644 --- a/core/io/file_access_pack.cpp +++ b/core/io/file_access_pack.cpp @@ -70,7 +70,7 @@ void PackedData::add_path(const String &p_pkg_path, const String &p_path, uint64 String p = p_path.replace_first("res://", ""); PackedDir *cd = root; - if (p.find("/") != -1) { //in a subdir + if (p.contains("/")) { //in a subdir Vector<String> ds = p.get_base_dir().split("/"); diff --git a/core/io/resource.h b/core/io/resource.h index dea2160616..b1e1c15541 100644 --- a/core/io/resource.h +++ b/core/io/resource.h @@ -105,7 +105,7 @@ public: virtual void set_path(const String &p_path, bool p_take_over = false); String get_path() const; - _FORCE_INLINE_ bool is_built_in() const { return path_cache.is_empty() || path_cache.find("::") != -1 || path_cache.begins_with("local://"); } + _FORCE_INLINE_ bool is_built_in() const { return path_cache.is_empty() || path_cache.contains("::") || path_cache.begins_with("local://"); } static String generate_scene_unique_id(); void set_scene_unique_id(const String &p_id); diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 200d5fafde..8588bab0be 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -335,7 +335,7 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { String exttype = get_unicode_string(); String path = get_unicode_string(); - if (path.find("://") == -1 && path.is_relative_path()) { + if (!path.contains("://") && path.is_relative_path()) { // path is relative to file being loaded, so convert to a resource path path = ProjectSettings::get_singleton()->localize_path(res_path.get_base_dir().plus_file(path)); } @@ -626,7 +626,7 @@ Error ResourceLoaderBinary::load() { path = remaps[path]; } - if (path.find("://") == -1 && path.is_relative_path()) { + if (!path.contains("://") && path.is_relative_path()) { // path is relative to file being loaded, so convert to a resource path path = ProjectSettings::get_singleton()->localize_path(path.get_base_dir().plus_file(external_resources[i].path)); } diff --git a/core/io/translation_loader_po.cpp b/core/io/translation_loader_po.cpp index 2f6742bd7a..8d3e58cad1 100644 --- a/core/io/translation_loader_po.cpp +++ b/core/io/translation_loader_po.cpp @@ -179,7 +179,7 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) { } if (l.is_empty() || l.begins_with("#")) { - if (l.find("fuzzy") != -1) { + if (l.contains("fuzzy")) { skip_next = true; } line++; diff --git a/core/object/class_db.cpp b/core/object/class_db.cpp index 03774bc36a..72a98ca20c 100644 --- a/core/object/class_db.cpp +++ b/core/object/class_db.cpp @@ -732,7 +732,7 @@ void ClassDB::bind_integer_constant(const StringName &p_class, const StringName String enum_name = p_enum; if (!enum_name.is_empty()) { - if (enum_name.find(".") != -1) { + if (enum_name.contains(".")) { enum_name = enum_name.get_slicec('.', 1); } diff --git a/core/string/ustring.h b/core/string/ustring.h index 6df87280a4..b685e3929f 100644 --- a/core/string/ustring.h +++ b/core/string/ustring.h @@ -394,6 +394,8 @@ public: Vector<uint8_t> sha256_buffer() const; _FORCE_INLINE_ bool is_empty() const { return length() == 0; } + _FORCE_INLINE_ bool contains(const char *p_str) const { return find(p_str) != -1; } + _FORCE_INLINE_ bool contains(const String &p_str) const { return find(p_str) != -1; } // path functions bool is_absolute_path() const; diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index aecc6e9a26..750f23902d 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -1421,6 +1421,7 @@ static void _register_variant_builtin_methods() { bind_method(String, sha1_buffer, sarray(), varray()); bind_method(String, sha256_buffer, sarray(), varray()); bind_method(String, is_empty, sarray(), varray()); + bind_methodv(String, contains, static_cast<bool (String::*)(const String &) const>(&String::contains), sarray("what"), varray()); bind_method(String, is_absolute_path, sarray(), varray()); bind_method(String, is_relative_path, sarray(), varray()); diff --git a/core/variant/variant_parser.cpp b/core/variant/variant_parser.cpp index 96cdc0678e..55fc9212b7 100644 --- a/core/variant/variant_parser.cpp +++ b/core/variant/variant_parser.cpp @@ -1495,7 +1495,7 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str case Variant::FLOAT: { String s = rtos_fix(p_variant.operator double()); if (s != "inf" && s != "inf_neg" && s != "nan") { - if (s.find(".") == -1 && s.find("e") == -1) { + if (!s.contains(".") && !s.contains("e")) { s += ".0"; } } |