From 2df02a121411e43d819fd4b36e3ea423d4530d5b Mon Sep 17 00:00:00 2001 From: Daniel Frey Date: Tue, 3 Dec 2024 22:41:57 +0100 Subject: [PATCH] More refactoring --- include/tao/pq/result_traits_array.hpp | 28 +++++++++----------------- src/lib/pq/result_traits_array.cpp | 10 +++++++++ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/include/tao/pq/result_traits_array.hpp b/include/tao/pq/result_traits_array.hpp index 244f813..d3b8110 100644 --- a/include/tao/pq/result_traits_array.hpp +++ b/include/tao/pq/result_traits_array.hpp @@ -5,8 +5,6 @@ #ifndef TAO_PQ_RESULT_TRAITS_ARRAY_HPP #define TAO_PQ_RESULT_TRAITS_ARRAY_HPP -#include -#include #include #include #include @@ -48,6 +46,7 @@ namespace tao::pq namespace internal { [[nodiscard]] auto parse_quoted( const char*& value ) -> std::string; + [[nodiscard]] auto parse_unquoted( const char*& value ) -> std::string; template< typename T > requires( !pq::is_array_result< T > ) && ( result_traits_size< T > == 1 ) @@ -57,24 +56,17 @@ namespace tao::pq const std::string input = parse_quoted( ++value ); return result_traits< T >::from( input.c_str() ); } - else { - if( const auto* end = std::strpbrk( value, ",;}" ) ) { - const std::string input( value, end ); - value = end; - if( input == "NULL" ) { - if constexpr( requires { result_traits< T >::null(); } ) { - return result_traits< T >::null(); - } - else { - throw std::invalid_argument( "unexpected NULL value" ); - } - } - else { - return result_traits< T >::from( input.c_str() ); - } + + const std::string input = parse_unquoted( value ); + if( input == "NULL" ) { + if constexpr( requires { result_traits< T >::null(); } ) { + return result_traits< T >::null(); + } + else { + throw std::invalid_argument( "unexpected NULL value" ); } - throw std::invalid_argument( "unterminated unquoted string" ); } + return result_traits< T >::from( input.c_str() ); } template< typename T > diff --git a/src/lib/pq/result_traits_array.cpp b/src/lib/pq/result_traits_array.cpp index da283ac..bc7db40 100644 --- a/src/lib/pq/result_traits_array.cpp +++ b/src/lib/pq/result_traits_array.cpp @@ -35,4 +35,14 @@ namespace tao::pq::internal throw std::invalid_argument( "unterminated quoted string" ); } + auto parse_unquoted( const char*& value ) -> std::string + { + if( const auto* end = std::strpbrk( value, ",;}" ) ) { + const std::string result( value, end ); + value = end; + return result; + } + throw std::invalid_argument( "unterminated unquoted string" ); + } + } // namespace tao::pq::internal