mirror of
https://github.com/boostorg/uuid.git
synced 2026-01-19 04:42:16 +00:00
Change the type of pos to std::ptrdiff_t to avoid casts
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
namespace uuids {
|
namespace uuids {
|
||||||
@@ -29,10 +30,10 @@ BOOST_CXX14_CONSTEXPR inline char const* fc_error_to_string( from_chars_error er
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_NORETURN inline void throw_invalid_uuid( int pos, from_chars_error err )
|
BOOST_NORETURN inline void throw_invalid_uuid( std::ptrdiff_t pos, from_chars_error err )
|
||||||
{
|
{
|
||||||
char buffer[ 128 ];
|
char buffer[ 128 ];
|
||||||
std::snprintf( buffer, sizeof( buffer ), "Invalid UUID string at position %d: %s", pos, fc_error_to_string( err ) );
|
std::snprintf( buffer, sizeof( buffer ), "Invalid UUID string at position %td: %s", pos, fc_error_to_string( err ) );
|
||||||
|
|
||||||
BOOST_THROW_EXCEPTION( std::runtime_error( buffer ) );
|
BOOST_THROW_EXCEPTION( std::runtime_error( buffer ) );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
#include <boost/uuid/detail/throw_invalid_uuid.hpp>
|
#include <boost/uuid/detail/throw_invalid_uuid.hpp>
|
||||||
#include <boost/uuid/detail/cstring.hpp>
|
#include <boost/uuid/detail/cstring.hpp>
|
||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
namespace uuids {
|
namespace uuids {
|
||||||
@@ -27,12 +26,12 @@ uuid uuid_from_string( Ch const* first, Ch const* last )
|
|||||||
|
|
||||||
if( r.ec != from_chars_error::none )
|
if( r.ec != from_chars_error::none )
|
||||||
{
|
{
|
||||||
detail::throw_invalid_uuid( static_cast<int>( r.ptr - first ), r.ec );
|
detail::throw_invalid_uuid( r.ptr - first, r.ec );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( r.ptr != last )
|
if( r.ptr != last )
|
||||||
{
|
{
|
||||||
detail::throw_invalid_uuid( static_cast<int>( r.ptr - first ), from_chars_error::unexpected_extra_input );
|
detail::throw_invalid_uuid( r.ptr - first, from_chars_error::unexpected_extra_input );
|
||||||
}
|
}
|
||||||
|
|
||||||
return u;
|
return u;
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public:
|
|||||||
using result_type = uuid;
|
using result_type = uuid;
|
||||||
|
|
||||||
template<class CharIterator>
|
template<class CharIterator>
|
||||||
BOOST_CXX14_CONSTEXPR uuid operator()( CharIterator first, CharIterator last, int& pos, from_chars_error& err ) const noexcept
|
BOOST_CXX14_CONSTEXPR uuid operator()( CharIterator first, CharIterator last, std::ptrdiff_t& pos, from_chars_error& err ) const noexcept
|
||||||
{
|
{
|
||||||
uuid u;
|
uuid u;
|
||||||
|
|
||||||
@@ -170,7 +170,7 @@ public:
|
|||||||
template<class CharIterator>
|
template<class CharIterator>
|
||||||
BOOST_CXX14_CONSTEXPR uuid operator()( CharIterator first, CharIterator last ) const
|
BOOST_CXX14_CONSTEXPR uuid operator()( CharIterator first, CharIterator last ) const
|
||||||
{
|
{
|
||||||
int pos = 0;
|
std::ptrdiff_t pos = 0;
|
||||||
from_chars_error err = {};
|
from_chars_error err = {};
|
||||||
|
|
||||||
uuid r = operator()( first, last, pos, err );
|
uuid r = operator()( first, last, pos, err );
|
||||||
|
|||||||
Reference in New Issue
Block a user