From 2c358ced7ca10ab37a382477d8b55fdb4e353f44 Mon Sep 17 00:00:00 2001 From: Adrian Kummerländer Date: Thu, 22 May 2014 21:07:16 +0200 Subject: Replaced std::pair 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 --- src/support/include_entity_resolver.cc | 32 +++++++++++++++----------------- src/support/include_entity_resolver.h | 4 +++- 2 files changed, 18 insertions(+), 18 deletions(-) (limited to 'src/support') 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 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 extractFilePath(const XMLCh* const rawPath) { + const std::string filePath = *XercesStringGuard(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(); } } @@ -51,14 +53,10 @@ xercesc::InputSource* IncludeEntityResolver::resolveEntity( const XMLCh* const systemId ) { if ( systemId != nullptr ) { - auto filePath = extractFilePath(*XercesStringGuard(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(resolvedPath.second.string()) + *XercesStringGuard((*resolvedPath).string()) ); } else { return nullptr; @@ -71,7 +69,7 @@ xercesc::InputSource* IncludeEntityResolver::resolveEntity( } } -std::pair IncludeEntityResolver::resolve( +boost::optional IncludeEntityResolver::resolve( const std::string& filePath) { for ( auto&& context : this->path_ ) { const boost::filesystem::path resolvedPath( @@ -80,11 +78,11 @@ std::pair 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(); } } 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 #include +#include "boost/optional.hpp" + #include #include @@ -20,7 +22,7 @@ class IncludeEntityResolver : public xercesc::EntityResolver { const XMLCh* const ); - std::pair resolve(const std::string&); + boost::optional resolve(const std::string&); private: std::vector path_; -- cgit v1.2.3