File tree Expand file tree Collapse file tree 1 file changed +17
-4
lines changed
Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -125,13 +125,26 @@ LIBHAT_EXPORT namespace hat {
125125 }
126126
127127 template <typename Char>
128- [[nodiscard]] constexpr result<signature, signature_error> string_to_signature (std::basic_string_view<Char> str) {
129- const auto bytes = std::as_bytes (std::span{str});
130- return bytes_to_signature (bytes);
128+ [[nodiscard]] LIBHAT_CONSTEXPR_RESULT result<signature, signature_error> string_to_signature (std::basic_string_view<Char> str) {
129+ if (str.empty ()) {
130+ return result_error{signature_error::empty_signature};
131+ }
132+
133+ signature result;
134+ result.resize (str.size () * sizeof (Char));
135+
136+ auto it = result.begin ();
137+ for (Char ch : str) {
138+ const auto bytes = std::bit_cast<std::array<std::byte, sizeof (Char)>>(ch);
139+ std::ranges::copy (bytes, it);
140+ it += bytes.size ();
141+ }
142+
143+ return result;
131144 }
132145
133146 template <typename Char>
134- [[nodiscard]] constexpr result<signature, signature_error> string_to_signature (std::basic_string<Char> str) {
147+ [[nodiscard]] LIBHAT_CONSTEXPR_RESULT result<signature, signature_error> string_to_signature (std::basic_string<Char> str) {
135148 return string_to_signature (std::basic_string_view<Char>{str});
136149 }
137150
You can’t perform that action at this time.
0 commit comments