aboutsummaryrefslogtreecommitdiff
path: root/src/support/include_entity_resolver.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/support/include_entity_resolver.cc')
-rw-r--r--src/support/include_entity_resolver.cc32
1 files changed, 15 insertions, 17 deletions
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>();
}
}