mal-packet-weaver
C++20 packet serialization/deserialization library.
Loading...
Searching...
No Matches
converter.hpp
Go to the documentation of this file.
1#pragma once
2#include "library-pch.hpp"
8namespace mal_toolkit
9{
21 inline std::optional<int64_t> to_int64(std::string_view str)
22 {
23 char *end;
24 int64_t ll = strtoll(str.data(), &end, static_cast<int>(str.size()));
25 if (str.data() != end)
26 {
27 return ll;
28 }
29 return std::nullopt;
30 }
31
43 inline std::optional<uint64_t> to_uint64(std::string_view str)
44 {
45 char *end;
46 uint64_t ll = strtoull(str.data(), &end, static_cast<int>(str.size()));
47 if (str.data() != end)
48 {
49 return ll;
50 }
51 return std::nullopt;
52 }
53
65 inline std::optional<long double> to_long_double(std::string_view str)
66 {
67 char *end;
68 long double ld = strtold(str.data(), &end);
69 if (str.data() != end)
70 {
71 return ld;
72 }
73 return std::nullopt;
74 }
75} // namespace mal_toolkit
Precompiled header (PCH) file for common headers used across the library.
Contains a collection of tools and utilities provided by the MAL Toolkit library.
Definition backoffs.hpp:7
std::optional< int64_t > to_int64(std::string_view str)
Convert a string_view to an optional int64_t.
Definition converter.hpp:21
std::optional< uint64_t > to_uint64(std::string_view str)
Convert a string_view to an optional uint64_t.
Definition converter.hpp:43
std::optional< long double > to_long_double(std::string_view str)
Convert a string_view to an optional long double.
Definition converter.hpp:65