7#include "Stroika/Foundation/Common/Common.h"
12 template <
typename T =
int>
13 [[deprecated (
"Since Stroika v3.0d1, use span{} overload")]] T
String2Int (
const wchar_t* start,
const wchar_t* end)
15 return String2Int (span<const wchar_t>{start, end});
19 unsigned long long int String2UInt_ (
const String& s);
20 long long int String2Int_ (
const String& s);
21 DISABLE_COMPILER_MSC_WARNING_START (4018)
23 T String2IntOrUInt_ (const String& s)
25 if constexpr (numeric_limits<T>::is_signed) {
26 long long int l = String2Int_ (s);
27 if (l <= numeric_limits<T>::min ()) {
28 return numeric_limits<T>::min ();
30 if (l >= numeric_limits<T>::max ()) {
31 return numeric_limits<T>::max ();
33 return static_cast<T
> (l);
36 unsigned long long int l = String2UInt_ (s);
37 if (l >= numeric_limits<T>::max ()) {
38 return numeric_limits<T>::max ();
40 return static_cast<T
> (l);
43 DISABLE_COMPILER_MSC_WARNING_END (4018)
51 template <
integral T, IUNICODECodePo
int CHAR_T>
52 inline T String2Int (span<const CHAR_T> s)
59 if constexpr (
sizeof (CHAR_T) ==
sizeof (
wchar_t)) {
67 auto b = asciiS.begin ();
68 auto e = asciiS.end ();
69 if (b != e and *b ==
'+') {
72 auto [ptr, ec] = from_chars (b, e, r);
73 if (ec == errc::result_out_of_range) [[unlikely]] {
74 return *b ==
'-' ? numeric_limits<T>::min () : numeric_limits<T>::max ();
77 T result = (ec == std::errc{} and ptr == e) ? r : 0;
78 Ensure (result == Private_::String2IntOrUInt_<T> (
String{s}));
82 return Private_::String2IntOrUInt_<T> (
String{s});
86 return String2Int<T> (
String{s});
89 template <
integral T, IConvertibleToString STRINGISH_ARG>
90 inline T String2Int (STRINGISH_ARG&& s)
92 using DecayedStringishArg = remove_cvref_t<STRINGISH_ARG>;
93 if constexpr (same_as<DecayedStringishArg, const char*> or same_as<DecayedStringishArg, const char8_t*> or
94 same_as<DecayedStringishArg, const char16_t*> or same_as<DecayedStringishArg, const char32_t*> or
95 same_as<DecayedStringishArg, const wchar_t*>) {
96 return String2Int<T> (span{s, CString::Length (s)});
98 else if constexpr (same_as<DecayedStringishArg, String>) {
100 Memory::StackBuffer<wchar_t> ignored;
101 auto sp = s.template GetData<wchar_t> (&ignored);
102 return String2Int<T> (sp);
105 return String2Int<T> (String{forward<STRINGISH_ARG> (s)});
T String2Int(const string &s)
static bool AsASCIIQuietly(span< const CHAR_T > fromS, RESULT_T *into)
String is like std::u32string, except it is much easier to use, often much more space efficient,...
nonvirtual String Trim(bool(*shouldBeTrimmed)(Character)=Character::IsWhitespace) const
Logically halfway between std::array and std::vector; Smart 'direct memory array' - which when needed...