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

Add charN_t support to to_chars

This commit is contained in:
Peter Dimov
2024-05-04 18:19:07 +03:00
parent 34eb75ce98
commit 2480bedcea
3 changed files with 33 additions and 12 deletions

View File

@@ -22,6 +22,25 @@ constexpr wchar_t const* digits( wchar_t const* ) noexcept
return L"0123456789abcdef-";
}
constexpr char16_t const* digits( char16_t const* ) noexcept
{
return u"0123456789abcdef-";
}
constexpr char32_t const* digits( char32_t const* ) noexcept
{
return U"0123456789abcdef-";
}
#if defined(__cpp_char8_t) && __cpp_char8_t >= 201811L
constexpr char8_t const* digits( char8_t const* ) noexcept
{
return u8"0123456789abcdef-";
}
#endif
template<class Ch> inline Ch* to_chars( uuid const& u, Ch* out ) noexcept
{
constexpr Ch const* p = digits( static_cast<Ch const*>( nullptr ) );

View File

@@ -33,18 +33,8 @@ OutputIterator to_chars( uuid const& u, OutputIterator out )
return std::copy_n( tmp, 36, out );
}
inline bool to_chars( uuid const& u, char* first, char* last ) noexcept
{
if( last - first < 36 )
{
return false;
}
detail::to_chars( u, first );
return true;
}
inline bool to_chars( uuid const& u, wchar_t* first, wchar_t* last ) noexcept
template<class Ch>
inline bool to_chars( uuid const& u, Ch* first, Ch* last ) noexcept
{
if( last - first < 36 )
{

View File

@@ -59,5 +59,17 @@ int main()
test( u2, L"00010203-0405-0607-0809-0a0b0c0d0e0f" );
test( u3, L"12345678-90ab-cdef-1234-567890abcdef" );
test( u1, u"00000000-0000-0000-0000-000000000000" );
test( u2, u"00010203-0405-0607-0809-0a0b0c0d0e0f" );
test( u3, u"12345678-90ab-cdef-1234-567890abcdef" );
test( u1, U"00000000-0000-0000-0000-000000000000" );
test( u2, U"00010203-0405-0607-0809-0a0b0c0d0e0f" );
test( u3, U"12345678-90ab-cdef-1234-567890abcdef" );
test( u1, u8"00000000-0000-0000-0000-000000000000" );
test( u2, u8"00010203-0405-0607-0809-0a0b0c0d0e0f" );
test( u3, u8"12345678-90ab-cdef-1234-567890abcdef" );
return boost::report_errors();
}