diff options
author | Tetsuo Kiso <tetsuo-s@is.naist.jp> | 2011-11-12 06:50:39 +0400 |
---|---|---|
committer | Tetsuo Kiso <tetsuo-s@is.naist.jp> | 2011-11-12 06:50:39 +0400 |
commit | 03abf54d2112ece58981ee8f96c23008b95d6def (patch) | |
tree | 68ae5e54abecb457d9a299cf9c11b378a09255b1 /mert/FileStream.cpp | |
parent | ee0345b9b6abc23c46c0eb1cf9114d720d64482c (diff) |
Add a utility function to make sure the filename with ".gz" extension.
Diffstat (limited to 'mert/FileStream.cpp')
-rw-r--r-- | mert/FileStream.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/mert/FileStream.cpp b/mert/FileStream.cpp index 3b00efa7d..b1969616e 100644 --- a/mert/FileStream.cpp +++ b/mert/FileStream.cpp @@ -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; |