Merge pull request #109433 from KoBeWi/hastension

Add `has_extension()` method to String
This commit is contained in:
Thaddeus Crews 2025-10-31 09:23:30 -05:00
commit ae9732139a
No known key found for this signature in database
GPG key ID: 8C6E5FEB5FC03CCC
29 changed files with 46 additions and 48 deletions

View file

@ -486,7 +486,7 @@ bool ResourceFormatLoaderCompressedTexture2D::handles_type(const String &p_type)
}
String ResourceFormatLoaderCompressedTexture2D::get_resource_type(const String &p_path) const {
if (p_path.get_extension().to_lower() == "ctex") {
if (p_path.has_extension("ctex")) {
return "CompressedTexture2D";
}
return "";
@ -670,7 +670,7 @@ bool ResourceFormatLoaderCompressedTexture3D::handles_type(const String &p_type)
}
String ResourceFormatLoaderCompressedTexture3D::get_resource_type(const String &p_path) const {
if (p_path.get_extension().to_lower() == "ctex3d") {
if (p_path.has_extension("ctex3d")) {
return "CompressedTexture3D";
}
return "";
@ -844,15 +844,15 @@ CompressedTextureLayered::~CompressedTextureLayered() {
Ref<Resource> ResourceFormatLoaderCompressedTextureLayered::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) {
Ref<CompressedTextureLayered> ct;
if (p_path.get_extension().to_lower() == "ctexarray") {
if (p_path.has_extension("ctexarray")) {
Ref<CompressedTexture2DArray> c;
c.instantiate();
ct = c;
} else if (p_path.get_extension().to_lower() == "ccube") {
} else if (p_path.has_extension("ccube")) {
Ref<CompressedCubemap> c;
c.instantiate();
ct = c;
} else if (p_path.get_extension().to_lower() == "ccubearray") {
} else if (p_path.has_extension("ccubearray")) {
Ref<CompressedCubemapArray> c;
c.instantiate();
ct = c;
@ -884,13 +884,13 @@ bool ResourceFormatLoaderCompressedTextureLayered::handles_type(const String &p_
}
String ResourceFormatLoaderCompressedTextureLayered::get_resource_type(const String &p_path) const {
if (p_path.get_extension().to_lower() == "ctexarray") {
if (p_path.has_extension("ctexarray")) {
return "CompressedTexture2DArray";
}
if (p_path.get_extension().to_lower() == "ccube") {
if (p_path.has_extension("ccube")) {
return "CompressedCubemap";
}
if (p_path.get_extension().to_lower() == "ccubearray") {
if (p_path.has_extension("ccubearray")) {
return "CompressedCubemapArray";
}
return "";

View file

@ -1488,7 +1488,7 @@ void ResourceFormatLoaderText::get_classes_used(const String &p_path, HashSet<St
}
String ResourceFormatLoaderText::get_resource_type(const String &p_path) const {
String ext = p_path.get_extension().to_lower();
const String ext = p_path.get_extension().to_lower();
if (ext == "tscn") {
return "PackedScene";
} else if (ext != "tres") {
@ -1510,8 +1510,7 @@ String ResourceFormatLoaderText::get_resource_type(const String &p_path) const {
}
String ResourceFormatLoaderText::get_resource_script_class(const String &p_path) const {
String ext = p_path.get_extension().to_lower();
if (ext != "tres") {
if (!p_path.has_extension("tres")) {
return String();
}
@ -1529,8 +1528,7 @@ String ResourceFormatLoaderText::get_resource_script_class(const String &p_path)
}
ResourceUID::ID ResourceFormatLoaderText::get_resource_uid(const String &p_path) const {
String ext = p_path.get_extension().to_lower();
const String ext = p_path.get_extension().to_lower();
if (ext != "tscn" && ext != "tres") {
return ResourceUID::INVALID_ID;
}

View file

@ -338,8 +338,7 @@ bool ResourceFormatLoaderShader::handles_type(const String &p_type) const {
}
String ResourceFormatLoaderShader::get_resource_type(const String &p_path) const {
String el = p_path.get_extension().to_lower();
if (el == "gdshader") {
if (p_path.has_extension("gdshader")) {
return "Shader";
}
return "";

View file

@ -121,8 +121,7 @@ bool ResourceFormatLoaderShaderInclude::handles_type(const String &p_type) const
}
String ResourceFormatLoaderShaderInclude::get_resource_type(const String &p_path) const {
String extension = p_path.get_extension().to_lower();
if (extension == "gdshaderinc") {
if (p_path.has_extension("gdshaderinc")) {
return "ShaderInclude";
}
return "";