1 // Copyright 2020, 2021 Francesco Biscani (bluescarni@gmail.com), Dario Izzo (dario.izzo@gmail.com)
2 //
3 // This file is part of the heyoka library.
4 //
5 // This Source Code Form is subject to the terms of the Mozilla
6 // Public License v. 2.0. If a copy of the MPL was not distributed
7 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #include <cassert>
10 #include <charconv>
11 #include <cstdint>
12 #include <string>
13 #include <system_error>
14 
15 #include <heyoka/detail/string_conv.hpp>
16 
17 namespace heyoka::detail
18 {
19 
uname_to_index(const std::string & s)20 std::uint32_t uname_to_index(const std::string &s)
21 {
22     assert(s.rfind("u_", 0) == 0);
23 
24     std::uint32_t value;
25     [[maybe_unused]] auto ret = std::from_chars(s.data() + 2, s.data() + s.size(), value);
26     assert(ret.ec == std::errc{});
27 
28     return value;
29 }
30 
31 } // namespace heyoka::detail
32