2
0
mirror of https://github.com/boostorg/uuid.git synced 2026-01-19 04:42:16 +00:00

Move some support functions from string_generator.hpp to from_chars.hpp

This commit is contained in:
Peter Dimov
2025-12-23 03:49:23 +02:00
parent 6622230ae1
commit 39232114eb
2 changed files with 25 additions and 43 deletions

View File

@@ -14,29 +14,29 @@ namespace detail {
constexpr char const* from_chars_digits( char const* ) noexcept
{
return "0123456789ABCDEFabcdef-";
return "0123456789ABCDEFabcdef-{}";
}
constexpr wchar_t const* from_chars_digits( wchar_t const* ) noexcept
{
return L"0123456789ABCDEFabcdef-";
return L"0123456789ABCDEFabcdef-{}";
}
constexpr char16_t const* from_chars_digits( char16_t const* ) noexcept
{
return u"0123456789ABCDEFabcdef-";
return u"0123456789ABCDEFabcdef-{}";
}
constexpr char32_t const* from_chars_digits( char32_t const* ) noexcept
{
return U"0123456789ABCDEFabcdef-";
return U"0123456789ABCDEFabcdef-{}";
}
#if defined(__cpp_char8_t) && __cpp_char8_t >= 201811L
constexpr char8_t const* from_chars_digits( char8_t const* ) noexcept
{
return u8"0123456789ABCDEFabcdef-";
return u8"0123456789ABCDEFabcdef-{}";
}
#endif
@@ -67,10 +67,25 @@ BOOST_CXX14_CONSTEXPR inline
unsigned char from_chars_is_dash( Ch ch ) noexcept
{
constexpr Ch const* digits = detail::from_chars_digits( static_cast<Ch const*>( nullptr ) );
return ch == digits[ 22 ];
}
template<class Ch>
BOOST_CXX14_CONSTEXPR inline
unsigned char from_chars_is_opening_brace( Ch ch ) noexcept
{
constexpr Ch const* digits = detail::from_chars_digits( static_cast<Ch const*>( nullptr ) );
return ch == digits[ 23 ];
}
template<class Ch>
BOOST_CXX14_CONSTEXPR inline
unsigned char from_chars_is_closing_brace( Ch ch ) noexcept
{
constexpr Ch const* digits = detail::from_chars_digits( static_cast<Ch const*>( nullptr ) );
return ch == digits[ 24 ];
}
} // namespace detail
enum class from_chars_error

View File

@@ -11,7 +11,6 @@
#include <boost/throw_exception.hpp>
#include <boost/config.hpp>
#include <string>
#include <iterator>
#include <stdexcept>
#include <cstdio>
#include <cstddef>
@@ -84,7 +83,7 @@ public:
// check open brace
bool has_open_brace = is_open_brace( *first );
bool has_open_brace = detail::from_chars_is_opening_brace( *first );
if( has_open_brace )
{
@@ -137,7 +136,7 @@ public:
return u;
}
has_dashes = is_dash( *first );
has_dashes = detail::from_chars_is_dash( *first );
if( has_dashes )
{
@@ -156,7 +155,7 @@ public:
return u;
}
if( is_dash( *first ) )
if( detail::from_chars_is_dash( *first ) )
{
++first, ++pos;
}
@@ -179,7 +178,7 @@ public:
return u;
}
if( is_close_brace( *first ) )
if( detail::from_chars_is_closing_brace( *first ) )
{
++first, ++pos;
}
@@ -235,38 +234,6 @@ public:
{
return operator()( s, s + detail::cx_strlen( s ) );
}
private:
static constexpr bool is_dash( char c ) noexcept
{
return c == '-';
}
static constexpr bool is_dash( wchar_t c ) noexcept
{
return c == L'-';
}
static constexpr bool is_open_brace( char c ) noexcept
{
return c == '{';
}
static constexpr bool is_open_brace( wchar_t c ) noexcept
{
return c == L'{';
}
static constexpr bool is_close_brace( char c ) noexcept
{
return c == '}';
}
static constexpr bool is_close_brace( wchar_t c ) noexcept
{
return c == L'}';
}
};
}} // namespace boost::uuids