diff options
Diffstat (limited to 'src/support/filesystem_context.cc')
-rw-r--r-- | src/support/filesystem_context.cc | 49 |
1 files changed, 41 insertions, 8 deletions
diff --git a/src/support/filesystem_context.cc b/src/support/filesystem_context.cc index d3f9614..d0813c2 100644 --- a/src/support/filesystem_context.cc +++ b/src/support/filesystem_context.cc @@ -1,24 +1,57 @@ #include "filesystem_context.h" +namespace { + +inline std::string xalanToString(const xalan::XalanDOMString& text) { + xalan::CharVectorType castHelper; + text.transcode(castHelper); + + return std::string( + castHelper.begin(), + castHelper.end() - 1 + ); +} + +} + namespace InputXSLT { FilesystemContext::FilesystemContext(const std::string& path): - path_(path) { } + path_(canonical(boost::filesystem::path(path))) { } boost::filesystem::path FilesystemContext::resolve( const std::string& path) const { - return boost::filesystem::path(this->path_ / path); + return canonical(this->path_ / path); } boost::filesystem::path FilesystemContext::resolve( const xalan::XalanDOMString& path) const { - xalan::CharVectorType castHelper; - path.transcode(castHelper); + return this->resolve(xalanToString(path)); +} - return this->resolve(std::string( - castHelper.begin(), - castHelper.end() - )); +void FilesystemContext::iterate( + const std::string& path, + std::function<void(const boost::filesystem::path&)> func +) const { + const boost::filesystem::path directory(this->resolve(path)); + + if ( boost::filesystem::exists(directory) && + boost::filesystem::is_directory(directory) ) { + for ( boost::filesystem::directory_iterator iter(directory); + iter != boost::filesystem::directory_iterator(); + ++iter ) { + if ( boost::filesystem::is_regular_file(iter->status()) ) { + func(*iter); + } + } + } +} + +void FilesystemContext::iterate( + const xalan::XalanDOMString& path, + std::function<void(const boost::filesystem::path&)> func +) const { + this->iterate(xalanToString(path), func); } } |