2
3
4
5
6
7
8
11#ifndef _MSTD_STRTONUM_HPP
12 #define _MSTD_STRTONUM_HPP
14 #include <mstd/config.hpp>
17_MSTD_WARNING(
"this is only available for c++17 and greater!");
20 #include <mstd/overflow_operations.hpp>
21 #include <mstd/string_types.hpp>
28 template<
class N, std::enable_if_t<std::is_integral_v<N>,
bool> =
true>
37 if (
hexStr[0] !=
'0' ||
hexStr[1] !=
'x') {
return false; }
74 template<
class N, std::enable_if_t<std::is_integral_v<N>,
bool> =
true>
81 if (
octStr[0] !=
'0' ||
octStr[1] !=
'c') {
return false; }
108 template<
class N, std::enable_if_t<std::is_integral_v<N>,
bool> =
true>
113 if (
binStr[0] !=
'0' ||
binStr[1] !=
'b') {
return false; }
140 template<
class SN, std::enable_if_t<mstd::is_signed_integral_v<SN>,
bool> =
true>
158 while (
str[
i] ==
'-' ||
str[
i] ==
'+') {
159 if (
str[
i] ==
'-') {
sign *=
static_cast<
SN>(-1); }
162 if (
i ==
str.
size()) {
return false; }
166 while (
str[
i] >=
'0' &&
str[
i] <=
'9') {
171 if (
i ==
str.
size()) {
return true; }
181 template<
class UN, std::enable_if_t<mstd::is_unsigned_integral_v<UN>,
bool> =
true>
197 while (
str[
i] ==
'+') {
199 if (
i ==
str.
size()) {
return false; }
203 while (
str[
i] >=
'0' &&
str[
i] <=
'9') {
208 if (
i ==
str.
size()) {
return true; }
218 template<
class FP, std::enable_if_t<std::is_floating_point_v<FP>,
bool> =
true>
229 while (
str[
i] ==
'-' ||
str[
i] ==
'+') {
230 if (
str[
i] ==
'-') {
sign *=
static_cast<
FP>(-1); }
233 if (
i ==
str.
size()) {
return false; }
238 while (
str[
i] >=
'0' &&
str[
i] <=
'9') {
251 if (
i ==
str.
size()) {
return false; }
254 while (
str[
i] >=
'0' &&
str[
i] <=
'9') {
#define _MSTD_HAS_CXX17
Definition config.hpp:45
#define _MSTD_CONSTEXPR17
Definition config.hpp:76
#define _MSTD_HAS_CXX20
Definition config.hpp:52
#define _MSTD_INLINE17
Definition config.hpp:83
#define _MSTD_CONSTEXPR20
Definition config.hpp:84
Definition arithmetic_types.hpp:23
_MSTD_INLINE17 _MSTD_CONSTEXPR20 bool strtounum(const std::string_view str, UN &num)
Definition strtonum.hpp:183
_MSTD_INLINE17 _MSTD_CONSTEXPR20 bool strxtonum(const std::string_view hexStr, N &num)
Definition strtonum.hpp:30
_MSTD_INLINE17 _MSTD_CONSTEXPR20 bool strbtonum(const std::string_view binStr, N &num)
Definition strtonum.hpp:110
_MSTD_INLINE17 _MSTD_CONSTEXPR20 bool strctonum(const std::string_view octStr, N &num)
Definition strtonum.hpp:76
_MSTD_INLINE17 _MSTD_CONSTEXPR20 bool strtofp(const std::string_view str, FP &num)
Definition strtonum.hpp:220
_MSTD_INLINE17 _MSTD_CONSTEXPR20 bool strtonum(const std::string_view str, SN &num)
Definition strtonum.hpp:142