tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
strtol.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2021 Tobias Hienzsch
3
4#ifndef TETL_CSTDLIB_STRTOL_HPP
5#define TETL_CSTDLIB_STRTOL_HPP
6
7#include <etl/_cstring/strlen.hpp>
8#include <etl/_strings/to_integer.hpp>
9
10namespace etl {
11
12/// \brief Interprets an integer value in a byte string pointed to by str.
13///
14/// https://en.cppreference.com/w/cpp/string/byte/strtol
15[[nodiscard]] constexpr auto strtol(char const* str, char const** last, int base) noexcept -> long
16{
17 auto const res = strings::to_integer<long>(str, base);
18 if (last != nullptr) {
19 *last = res.end;
20 }
21 return res.value;
22}
23
24/// \brief Interprets an integer value in a byte string pointed to by str.
25///
26/// https://en.cppreference.com/w/cpp/string/byte/strtol
27[[nodiscard]] constexpr auto strtoll(char const* str, char const** last, int base) noexcept -> long long
28{
29 auto const res = strings::to_integer<long long>(str, base);
30 if (last != nullptr) {
31 *last = res.end;
32 }
33 return res.value;
34}
35
36} // namespace etl
37
38#endif // TETL_CSTDLIB_STRTOL_HPP
Definition find.hpp:9
constexpr auto to_integer(string_view str, Int base=Int(10)) noexcept -> to_integer_result< Int >
Definition to_integer.hpp:98
Definition adjacent_find.hpp:9
constexpr auto strtol(char const *str, char const **last, int base) noexcept -> long
Interprets an integer value in a byte string pointed to by str.
Definition strtol.hpp:15
constexpr auto strtoll(char const *str, char const **last, int base) noexcept -> long long
Interprets an integer value in a byte string pointed to by str.
Definition strtol.hpp:27