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

@ -231,8 +231,7 @@ Error ResourceFormatSaverCrypto::save(const Ref<Resource> &p_resource, const Str
if (cert.is_valid()) {
err = cert->save(p_path);
} else if (key.is_valid()) {
String el = p_path.get_extension().to_lower();
err = key->save(p_path, el == "pub");
err = key->save(p_path, p_path.has_extension("pub"));
} else {
ERR_FAIL_V(ERR_INVALID_PARAMETER);
}

View file

@ -888,8 +888,7 @@ bool GDExtensionResourceLoader::handles_type(const String &p_type) const {
}
String GDExtensionResourceLoader::get_resource_type(const String &p_path) const {
String el = p_path.get_extension().to_lower();
if (el == "gdextension") {
if (p_path.has_extension("gdextension")) {
return "GDExtension";
}
return "";

View file

@ -1593,8 +1593,7 @@ bool ResourceFormatLoaderJSON::handles_type(const String &p_type) const {
}
String ResourceFormatLoaderJSON::get_resource_type(const String &p_path) const {
String el = p_path.get_extension().to_lower();
if (el == "json") {
if (p_path.has_extension("json")) {
return "JSON";
}
return "";

View file

@ -105,7 +105,6 @@ Error ResourceSaver::save(const Ref<Resource> &p_resource, const String &p_path,
}
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.");
String extension = path.get_extension();
Error err = ERR_FILE_UNRECOGNIZED;
for (int i = 0; i < saver_count; i++) {

View file

@ -368,7 +368,7 @@ bool TranslationLoaderPO::handles_type(const String &p_type) const {
}
String TranslationLoaderPO::get_resource_type(const String &p_path) const {
if (p_path.get_extension().to_lower() == "po" || p_path.get_extension().to_lower() == "mo") {
if (p_path.has_extension("po") || p_path.has_extension("mo")) {
return "Translation";
}
return "";

View file

@ -519,6 +519,8 @@ public:
String get_basename() const;
String path_join(const String &p_path) const;
char32_t unicode_at(int p_idx) const;
bool has_extension(const char *p_ext) const { return get_extension().to_lower() == p_ext; }
bool has_extension(const String &p_ext) const { return get_extension().to_lower() == p_ext; }
CharString ascii(bool p_allow_extended = false) const;
// Parse an ascii string.