diff options
author | Adrian Kummerländer | 2014-04-21 21:47:20 +0200 |
---|---|---|
committer | Adrian Kummerländer | 2014-04-21 21:47:20 +0200 |
commit | 7142544d43b431df44d34921b0f3012fa1e0137d (patch) | |
tree | 5fb5de3222d25f0e48f24a0dbdd0d18f5d917c89 /src/support | |
parent | cdf4ad3486debe75fe89b2f04bb62541f3ac8405 (diff) | |
download | InputXSLT-7142544d43b431df44d34921b0f3012fa1e0137d.tar InputXSLT-7142544d43b431df44d34921b0f3012fa1e0137d.tar.gz InputXSLT-7142544d43b431df44d34921b0f3012fa1e0137d.tar.bz2 InputXSLT-7142544d43b431df44d34921b0f3012fa1e0137d.tar.lz InputXSLT-7142544d43b431df44d34921b0f3012fa1e0137d.tar.xz InputXSLT-7142544d43b431df44d34921b0f3012fa1e0137d.tar.zst InputXSLT-7142544d43b431df44d34921b0f3012fa1e0137d.zip |
Implemented basic external directory traversal function
* _read-directory_ lists all files in a given directory
** currently text-only output, xml planned
* improved FilesystemContext path resolution (relative path is fully resolved by boost::filesystem)
Diffstat (limited to 'src/support')
-rw-r--r-- | src/support/filesystem_context.cc | 49 | ||||
-rw-r--r-- | src/support/filesystem_context.h | 6 |
2 files changed, 47 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); } } diff --git a/src/support/filesystem_context.h b/src/support/filesystem_context.h index d5836f1..cb3edd4 100644 --- a/src/support/filesystem_context.h +++ b/src/support/filesystem_context.h @@ -6,6 +6,7 @@ #include "boost/filesystem.hpp" #include <string> +#include <functional> #include "common.h" @@ -18,6 +19,11 @@ class FilesystemContext { boost::filesystem::path resolve(const std::string&) const; boost::filesystem::path resolve(const xalan::XalanDOMString&) const; + void iterate(const std::string&, + std::function<void(const boost::filesystem::path&)>) const; + void iterate(const xalan::XalanDOMString&, + std::function<void(const boost::filesystem::path&)>) const; + private: const boost::filesystem::path path_; |