tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
stoi.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2021 Tobias Hienzsch
3#ifndef TETL_STRING_STOI_HPP
4#define TETL_STRING_STOI_HPP
5
6#include <etl/_concepts/integral.hpp>
7#include <etl/_string_view/basic_string_view.hpp>
8#include <etl/_strings/to_integer.hpp>
9
10namespace etl {
11
12namespace detail {
13
14template <etl::integral Int>
15[[nodiscard]] constexpr auto sto_impl(etl::string_view str, etl::size_t* pos, int base) -> Int
16{
17 auto const res = strings::to_integer<Int>(str, static_cast<Int>(base));
18 if (pos != nullptr) {
19 *pos = static_cast<etl::size_t>(etl::distance(str.data(), res.end));
20 }
21 return res.value;
22}
23
24} // namespace detail
25
26/// \brief Interprets a signed integer value in the string str.
27/// \param str The string to convert.
28/// \param pos Address of an integer to store the number of characters
29/// processed.
30/// \param base The number base.
31/// \returns Integer value corresponding to the content of str.
32[[nodiscard]] constexpr auto stoi(etl::string_view str, etl::size_t* pos = nullptr, int base = 10) -> int
33{
34 return detail::sto_impl<int>(str, pos, base);
35}
36
37/// \brief Interprets a signed integer value in the string str.
38/// \param str The string to convert.
39/// \param pos Address of an integer to store the number of characters
40/// processed.
41/// \param base The number base.
42/// \returns Integer value corresponding to the content of str.
43[[nodiscard]] constexpr auto stol(etl::string_view str, etl::size_t* pos = nullptr, int base = 10) -> long
44{
45 return detail::sto_impl<long>(str, pos, base);
46}
47
48/// \brief Interprets a signed integer value in the string str.
49/// \param str The string to convert.
50/// \param pos Address of an integer to store the number of characters
51/// processed.
52/// \param base The number base.
53/// \returns Integer value corresponding to the content of str.
54[[nodiscard]] constexpr auto stoll(etl::string_view str, etl::size_t* pos = nullptr, int base = 10) -> long long
55{
56 return detail::sto_impl<long long>(str, pos, base);
57}
58
59/// \brief Interprets a signed integer value in the string str.
60/// \param str The string to convert.
61/// \param pos Address of an integer to store the number of characters
62/// processed.
63/// \param base The number base.
64/// \returns Integer value corresponding to the content of str.
65[[nodiscard]] constexpr auto stoul(etl::string_view str, etl::size_t* pos = nullptr, int base = 10) -> unsigned long
66{
67 return detail::sto_impl<unsigned long>(str, pos, base);
68}
69
70/// \brief Interprets a signed integer value in the string str.
71/// \param str The string to convert.
72/// \param pos Address of an integer to store the number of characters
73/// processed.
74/// \param base The number base.
75/// \returns Integer value corresponding to the content of str.
76[[nodiscard]] constexpr auto stoull(etl::string_view str, etl::size_t* pos = nullptr, int base = 10)
77 -> unsigned long long
78{
79 return detail::sto_impl<unsigned long long>(str, pos, base);
80}
81
82} // namespace etl
83
84#endif // TETL_STRING_STOI_HPP
Definition find.hpp:9
Definition adjacent_find.hpp:9
constexpr auto stoul(etl::string_view str, etl::size_t *pos=nullptr, int base=10) -> unsigned long
Interprets a signed integer value in the string str.
Definition stoi.hpp:65
constexpr auto stoi(etl::string_view str, etl::size_t *pos=nullptr, int base=10) -> int
Interprets a signed integer value in the string str.
Definition stoi.hpp:32
constexpr auto stoull(etl::string_view str, etl::size_t *pos=nullptr, int base=10) -> unsigned long long
Interprets a signed integer value in the string str.
Definition stoi.hpp:76
constexpr auto stol(etl::string_view str, etl::size_t *pos=nullptr, int base=10) -> long
Interprets a signed integer value in the string str.
Definition stoi.hpp:43
constexpr auto stoll(etl::string_view str, etl::size_t *pos=nullptr, int base=10) -> long long
Interprets a signed integer value in the string str.
Definition stoi.hpp:54