aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerländer2014-05-22 21:07:16 +0200
committerAdrian Kummerländer2014-05-22 21:07:16 +0200
commit2c358ced7ca10ab37a382477d8b55fdb4e353f44 (patch)
tree7478370a0dfe8cb8329e028e55d5860b33d48509
parent4d0569669e01434b3bb9f689cd176f590344bea8 (diff)
downloadInputXSLT-2c358ced7ca10ab37a382477d8b55fdb4e353f44.tar
InputXSLT-2c358ced7ca10ab37a382477d8b55fdb4e353f44.tar.gz
InputXSLT-2c358ced7ca10ab37a382477d8b55fdb4e353f44.tar.bz2
InputXSLT-2c358ced7ca10ab37a382477d8b55fdb4e353f44.tar.lz
InputXSLT-2c358ced7ca10ab37a382477d8b55fdb4e353f44.tar.xz
InputXSLT-2c358ced7ca10ab37a382477d8b55fdb4e353f44.tar.zst
InputXSLT-2c358ced7ca10ab37a382477d8b55fdb4e353f44.zip
Replaced std::pair<bool, *> with the more convenient boost::optional<*>
* InputXSLT is dependent on boost anyway, so there is no argument to be made to emulate boost::optional using std::pair
-rw-r--r--src/function/read_file.cc13
-rw-r--r--src/function/read_xml_file.cc13
-rw-r--r--src/support/include_entity_resolver.cc32
-rw-r--r--src/support/include_entity_resolver.h4
4 files changed, 26 insertions, 36 deletions
diff --git a/src/function/read_file.cc b/src/function/read_file.cc
index 85f834d..1a870a6 100644
--- a/src/function/read_file.cc
+++ b/src/function/read_file.cc
@@ -28,18 +28,13 @@ xercesc::DOMDocument* FunctionReadFile::constructDocument(
const FilesystemContext& fsContext,
const FunctionBase::parameter_tuple& parameters
) {
- boost::filesystem::path filePath(
- fsContext.resolve(std::get<0>(parameters))
- );
+ const std::string& rawPath = std::get<0>(parameters);
+ boost::filesystem::path filePath(fsContext.resolve(rawPath));
if ( !(boost::filesystem::exists(filePath) &&
boost::filesystem::is_regular_file(filePath)) ) {
- auto resolvedPath = this->include_resolver_->resolve(
- std::get<0>(parameters)
- );
-
- if ( resolvedPath.first ) {
- filePath = resolvedPath.second;
+ if ( auto resolvedPath = this->include_resolver_->resolve(rawPath) ) {
+ filePath = *resolvedPath;
}
}
diff --git a/src/function/read_xml_file.cc b/src/function/read_xml_file.cc
index b9246e6..4eb44e5 100644
--- a/src/function/read_xml_file.cc
+++ b/src/function/read_xml_file.cc
@@ -38,18 +38,13 @@ xercesc::DOMDocument* FunctionReadXmlFile::constructDocument(
const FilesystemContext& fsContext,
const FunctionBase::parameter_tuple& parameters
) {
- boost::filesystem::path filePath(
- fsContext.resolve(std::get<0>(parameters))
- );
+ const std::string& rawPath = std::get<0>(parameters);
+ boost::filesystem::path filePath(fsContext.resolve(rawPath));
if ( !(boost::filesystem::exists(filePath) &&
boost::filesystem::is_regular_file(filePath)) ) {
- auto resolvedPath = this->include_resolver_->resolve(
- std::get<0>(parameters)
- );
-
- if ( resolvedPath.first ) {
- filePath = resolvedPath.second;
+ if ( auto resolvedPath = this->include_resolver_->resolve(rawPath) ) {
+ filePath = *resolvedPath;
}
}
diff --git a/src/support/include_entity_resolver.cc b/src/support/include_entity_resolver.cc
index a00d9e6..68af11a 100644
--- a/src/support/include_entity_resolver.cc
+++ b/src/support/include_entity_resolver.cc
@@ -8,22 +8,24 @@
namespace {
-std::pair<bool, std::string> extractFilePath(const std::string& rawPath) {
- const std::size_t leadingDelimiter = rawPath.find_first_of('[');
- const std::size_t closingDelimiter = rawPath.find_last_of(']');
+using InputXSLT::XercesStringGuard;
+
+boost::optional<std::string> extractFilePath(const XMLCh* const rawPath) {
+ const std::string filePath = *XercesStringGuard<char>(rawPath);
+ const std::size_t leadingDelimiter = filePath.find_first_of('[');
+ const std::size_t closingDelimiter = filePath.find_last_of(']');
if ( leadingDelimiter != std::string::npos &&
closingDelimiter != std::string::npos &&
leadingDelimiter < closingDelimiter ) {
- return std::make_pair(
- true,
- rawPath.substr(
+ return boost::make_optional(
+ filePath.substr(
leadingDelimiter + 1,
closingDelimiter - leadingDelimiter - 1
)
);
} else {
- return std::make_pair(false, std::string());
+ return boost::optional<std::string>();
}
}
@@ -51,14 +53,10 @@ xercesc::InputSource* IncludeEntityResolver::resolveEntity(
const XMLCh* const systemId
) {
if ( systemId != nullptr ) {
- auto filePath = extractFilePath(*XercesStringGuard<char>(systemId));
-
- if ( filePath.first ) {
- auto resolvedPath = this->resolve(filePath.second);
-
- if ( resolvedPath.first ) {
+ if ( auto filePath = extractFilePath(systemId) ) {
+ if ( auto resolvedPath = this->resolve(*filePath) ) {
return new xercesc::LocalFileInputSource(
- *XercesStringGuard<XMLCh>(resolvedPath.second.string())
+ *XercesStringGuard<XMLCh>((*resolvedPath).string())
);
} else {
return nullptr;
@@ -71,7 +69,7 @@ xercesc::InputSource* IncludeEntityResolver::resolveEntity(
}
}
-std::pair<bool, boost::filesystem::path> IncludeEntityResolver::resolve(
+boost::optional<boost::filesystem::path> IncludeEntityResolver::resolve(
const std::string& filePath) {
for ( auto&& context : this->path_ ) {
const boost::filesystem::path resolvedPath(
@@ -80,11 +78,11 @@ std::pair<bool, boost::filesystem::path> IncludeEntityResolver::resolve(
if ( boost::filesystem::exists(resolvedPath) &&
boost::filesystem::is_regular_file(resolvedPath) ) {
- return std::make_pair(true, resolvedPath);
+ return boost::make_optional(resolvedPath);
}
}
- return std::make_pair(false, boost::filesystem::path());
+ return boost::optional<boost::filesystem::path>();
}
}
diff --git a/src/support/include_entity_resolver.h b/src/support/include_entity_resolver.h
index b87e10f..1a3bbc1 100644
--- a/src/support/include_entity_resolver.h
+++ b/src/support/include_entity_resolver.h
@@ -4,6 +4,8 @@
#include <xercesc/sax/EntityResolver.hpp>
#include <xercesc/sax/InputSource.hpp>
+#include "boost/optional.hpp"
+
#include <string>
#include <vector>
@@ -20,7 +22,7 @@ class IncludeEntityResolver : public xercesc::EntityResolver {
const XMLCh* const
);
- std::pair<bool, boost::filesystem::path> resolve(const std::string&);
+ boost::optional<boost::filesystem::path> resolve(const std::string&);
private:
std::vector<FilesystemContext> path_;