aboutsummaryrefslogtreecommitdiff
path: root/src/support
diff options
context:
space:
mode:
Diffstat (limited to 'src/support')
-rw-r--r--src/support/filesystem_context.cc49
-rw-r--r--src/support/filesystem_context.h6
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_;