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) { bool HasExtension(path const& p, std::string const& ext) {
if (!p.has_extension()) return ext.empty(); auto filename = p.filename().string();
return boost::iequals(p.extension().string().substr(1), ext); 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; 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 { void EncoreSubtitleFormat::WriteFile(const AssFile *src, agi::fs::path const& filename, std::string const&) const {
agi::vfr::Framerate fps = AskForFPS(false, true); agi::vfr::Framerate fps = AskForFPS(false, true);
if (!fps.IsLoaded()) return; if (!fps.IsLoaded()) return;

View file

@ -38,6 +38,5 @@ class EncoreSubtitleFormat : public SubtitleFormat {
public: public:
EncoreSubtitleFormat(); EncoreSubtitleFormat();
std::vector<std::string> GetWriteWildcards() const override; 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; 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; 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 { void TranStationSubtitleFormat::WriteFile(const AssFile *src, agi::fs::path const& filename, std::string const& encoding) const {
agi::vfr::Framerate fps = AskForFPS(false, true); agi::vfr::Framerate fps = AskForFPS(false, true);
if (!fps.IsLoaded()) return; if (!fps.IsLoaded()) return;

View file

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