diff options
Diffstat (limited to 'src/support')
-rw-r--r-- | src/support/include_entity_resolver.cc | 32 | ||||
-rw-r--r-- | src/support/include_entity_resolver.h | 4 |
2 files changed, 18 insertions, 18 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>(); } } 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_; |