-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move detail::to_chars to detail/to_chars.hpp
- Loading branch information
Showing
2 changed files
with
62 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#ifndef BOOST_UUID_DETAIL_TO_CHARS_HPP_INCLUDED | ||
#define BOOST_UUID_DETAIL_TO_CHARS_HPP_INCLUDED | ||
|
||
// Copyright 2009 Andy Tompkins | ||
// Copyright 2024 Peter Dimov | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// https://www.boost.org/LICENSE_1_0.txt | ||
|
||
#include <boost/uuid/uuid.hpp> | ||
|
||
namespace boost { | ||
namespace uuids { | ||
namespace detail { | ||
|
||
constexpr char const* digits( char const* ) noexcept | ||
{ | ||
return "0123456789abcdef-"; | ||
} | ||
|
||
constexpr wchar_t const* digits( wchar_t const* ) noexcept | ||
{ | ||
return L"0123456789abcdef-"; | ||
} | ||
|
||
template<class Ch> inline Ch* to_chars( uuid const& u, Ch* out ) noexcept | ||
{ | ||
constexpr Ch const* p = digits( static_cast<Ch const*>( nullptr ) ); | ||
|
||
for( std::size_t i = 0; i < 16; ++i ) | ||
{ | ||
std::uint8_t ch = u.data[ i ]; | ||
|
||
*out++ = p[ (ch >> 4) & 0x0F ]; | ||
*out++ = p[ ch & 0x0F ]; | ||
|
||
if( i == 3 || i == 5 || i == 7 || i == 9 ) | ||
{ | ||
*out++ = p[ 16 ]; | ||
} | ||
} | ||
|
||
return out; | ||
} | ||
|
||
} // namespace detail | ||
}} //namespace boost::uuids | ||
|
||
#endif // BOOST_UUID_DETAIL_TO_CHARS_HPP_INCLUDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters