mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 11:25:40 +03:00
Add a utility function to make sure the filename with ".gz" extension.
This commit is contained in:
parent
ee0345b9b6
commit
03abf54d21
@ -5,6 +5,13 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace {
|
||||
bool IsGzipFile(const std::string &filename) {
|
||||
return filename.size() > 3 &&
|
||||
filename.substr(filename.size() - 3, 3) == ".gz";
|
||||
}
|
||||
} // namespace
|
||||
|
||||
inputfilestream::inputfilestream(const std::string &filePath)
|
||||
: std::istream(0), m_streambuf(0)
|
||||
{
|
||||
@ -12,8 +19,7 @@ inputfilestream::inputfilestream(const std::string &filePath)
|
||||
std::filebuf* fb = new std::filebuf();
|
||||
is_good = (fb->open(filePath.c_str(), std::ios::in) != NULL);
|
||||
|
||||
if (filePath.size() > 3 &&
|
||||
filePath.substr(filePath.size() - 3, 3) == ".gz") {
|
||||
if (IsGzipFile(filePath)) {
|
||||
fb->close();
|
||||
delete fb;
|
||||
m_streambuf = new gzfilebuf(filePath.c_str());
|
||||
@ -40,7 +46,7 @@ outputfilestream::outputfilestream(const std::string &filePath)
|
||||
std::filebuf* fb = new std::filebuf();
|
||||
is_good = (fb->open(filePath.c_str(), std::ios::out) != NULL);
|
||||
|
||||
if (filePath.size() > 3 && filePath.substr(filePath.size() - 3, 3) == ".gz") {
|
||||
if (IsGzipFile(filePath)) {
|
||||
throw runtime_error("Output to a zipped file not supported!");
|
||||
} else {
|
||||
m_streambuf = fb;
|
||||
|
Loading…
Reference in New Issue
Block a user