Skip to content

Commit ae97321

Browse files
committed
Merge pull request #109433 from KoBeWi/hastension
Add `has_extension()` method to String
2 parents c3d3197 + a33ae0b commit ae97321

29 files changed

+46
-48
lines changed

core/crypto/crypto.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,7 @@ Error ResourceFormatSaverCrypto::save(const Ref<Resource> &p_resource, const Str
231231
if (cert.is_valid()) {
232232
err = cert->save(p_path);
233233
} else if (key.is_valid()) {
234-
String el = p_path.get_extension().to_lower();
235-
err = key->save(p_path, el == "pub");
234+
err = key->save(p_path, p_path.has_extension("pub"));
236235
} else {
237236
ERR_FAIL_V(ERR_INVALID_PARAMETER);
238237
}

core/extension/gdextension.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -888,8 +888,7 @@ bool GDExtensionResourceLoader::handles_type(const String &p_type) const {
888888
}
889889

890890
String GDExtensionResourceLoader::get_resource_type(const String &p_path) const {
891-
String el = p_path.get_extension().to_lower();
892-
if (el == "gdextension") {
891+
if (p_path.has_extension("gdextension")) {
893892
return "GDExtension";
894893
}
895894
return "";

core/io/json.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,8 +1593,7 @@ bool ResourceFormatLoaderJSON::handles_type(const String &p_type) const {
15931593
}
15941594

15951595
String ResourceFormatLoaderJSON::get_resource_type(const String &p_path) const {
1596-
String el = p_path.get_extension().to_lower();
1597-
if (el == "json") {
1596+
if (p_path.has_extension("json")) {
15981597
return "JSON";
15991598
}
16001599
return "";

core/io/resource_saver.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ Error ResourceSaver::save(const Ref<Resource> &p_resource, const String &p_path,
105105
}
106106
ERR_FAIL_COND_V_MSG(path.is_empty(), ERR_INVALID_PARAMETER, "Can't save resource to empty path. Provide non-empty path or a Resource with non-empty resource_path.");
107107

108-
String extension = path.get_extension();
109108
Error err = ERR_FILE_UNRECOGNIZED;
110109

111110
for (int i = 0; i < saver_count; i++) {

core/io/translation_loader_po.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ bool TranslationLoaderPO::handles_type(const String &p_type) const {
368368
}
369369

370370
String TranslationLoaderPO::get_resource_type(const String &p_path) const {
371-
if (p_path.get_extension().to_lower() == "po" || p_path.get_extension().to_lower() == "mo") {
371+
if (p_path.has_extension("po") || p_path.has_extension("mo")) {
372372
return "Translation";
373373
}
374374
return "";

core/string/ustring.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,8 @@ class [[nodiscard]] String {
519519
String get_basename() const;
520520
String path_join(const String &p_path) const;
521521
char32_t unicode_at(int p_idx) const;
522+
bool has_extension(const char *p_ext) const { return get_extension().to_lower() == p_ext; }
523+
bool has_extension(const String &p_ext) const { return get_extension().to_lower() == p_ext; }
522524

523525
CharString ascii(bool p_allow_extended = false) const;
524526
// Parse an ascii string.

editor/export/editor_export_platform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1521,7 +1521,7 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
15211521
// Just store it as it comes.
15221522

15231523
// Customization only happens if plugins did not take care of it before.
1524-
bool force_binary = convert_text_to_binary && (path.get_extension().to_lower() == "tres" || path.get_extension().to_lower() == "tscn");
1524+
bool force_binary = convert_text_to_binary && (path.has_extension("tres") || path.has_extension("tscn"));
15251525
String export_path = _export_customize(path, customize_resources_plugins, customize_scenes_plugins, export_cache, export_base_path, force_binary);
15261526

15271527
if (export_path != path) {

editor/import/3d/resource_importer_scene.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2514,7 +2514,7 @@ void ResourceImporterScene::get_import_options(const String &p_path, List<Import
25142514
}
25152515
script_ext_hint += "*." + E;
25162516
}
2517-
bool trimming_defaults_on = p_path.get_extension().to_lower() == "fbx";
2517+
bool trimming_defaults_on = p_path.has_extension("fbx");
25182518

25192519
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "nodes/apply_root_scale"), true));
25202520
r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "nodes/root_scale", PROPERTY_HINT_RANGE, "0.001,1000,0.001"), 1.0));

editor/project_manager/project_manager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,15 @@ void ProjectManager::_notification(int p_what) {
140140
// Utility data.
141141

142142
Ref<Texture2D> ProjectManager::_file_dialog_get_icon(const String &p_path) {
143-
if (p_path.get_extension().to_lower() == "godot") {
143+
if (p_path.has_extension("godot")) {
144144
return singleton->icon_type_cache["GodotMonochrome"];
145145
}
146146

147147
return singleton->icon_type_cache["Object"];
148148
}
149149

150150
Ref<Texture2D> ProjectManager::_file_dialog_get_thumbnail(const String &p_path) {
151-
if (p_path.get_extension().to_lower() == "godot") {
151+
if (p_path.has_extension("godot")) {
152152
return singleton->icon_type_cache["GodotFile"];
153153
}
154154

editor/scene/3d/gpu_particles_collision_sdf_editor_plugin.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ void GPUParticlesCollisionSDF3DEditorPlugin::_bake() {
4242
if (path.is_empty()) {
4343
path = "res://" + col_sdf->get_name() + "_data.exr";
4444
} else {
45-
String ext = path.get_extension();
4645
path = path.get_basename() + "." + col_sdf->get_name() + "_data.exr";
4746
}
4847
probe_file->set_current_path(path);

0 commit comments

Comments
 (0)