Support extensions with multiple dots in agi::fs::HasExtension

This commit is contained in:
Thomas Goyne 2013-02-02 07:29:55 -08:00
parent b885c2c19d
commit 6cb9665202
5 changed files with 4 additions and 12 deletions

View File

@ -100,7 +100,9 @@ namespace agi { namespace fs {
}
bool HasExtension(path const& p, std::string const& ext) {
if (!p.has_extension()) return ext.empty();
return boost::iequals(p.extension().string().substr(1), ext);
auto filename = p.filename().string();
if (filename.size() < ext.size() + 1) return false;
if (filename[filename.size() - ext.size() - 1] != '.') return false;
return boost::iends_with(filename, ext);
}
} }

View File

@ -57,10 +57,6 @@ std::vector<std::string> EncoreSubtitleFormat::GetWriteWildcards() const {
return formats;
}
bool EncoreSubtitleFormat::CanWriteFile(agi::fs::path const& filename) const {
return boost::iends_with(filename.string(), ".encore.txt");
}
void EncoreSubtitleFormat::WriteFile(const AssFile *src, agi::fs::path const& filename, std::string const&) const {
agi::vfr::Framerate fps = AskForFPS(false, true);
if (!fps.IsLoaded()) return;

View File

@ -38,6 +38,5 @@ class EncoreSubtitleFormat : public SubtitleFormat {
public:
EncoreSubtitleFormat();
std::vector<std::string> GetWriteWildcards() const override;
bool CanWriteFile(agi::fs::path const& filename) const override;
void WriteFile(const AssFile *src, agi::fs::path const& filename, std::string const&) const override;
};

View File

@ -61,10 +61,6 @@ std::vector<std::string> TranStationSubtitleFormat::GetWriteWildcards() const {
return formats;
}
bool TranStationSubtitleFormat::CanWriteFile(agi::fs::path const& filename) const {
return boost::iends_with(filename.string(), ".transtation.txt");
}
void TranStationSubtitleFormat::WriteFile(const AssFile *src, agi::fs::path const& filename, std::string const& encoding) const {
agi::vfr::Framerate fps = AskForFPS(false, true);
if (!fps.IsLoaded()) return;

View File

@ -42,7 +42,6 @@ class TranStationSubtitleFormat : public SubtitleFormat {
public:
TranStationSubtitleFormat();
bool CanWriteFile(agi::fs::path const& filename) const override;
std::vector<std::string> GetWriteWildcards() const override;
void WriteFile(const AssFile *src, agi::fs::path const& filename, std::string const& encoding) const override;
};