Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
String2Int.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#include "Stroika/Foundation/StroikaPreComp.h"
5
6#include <cstdlib>
7
8#include "Stroika/Foundation/Containers/Common.h"
11#include "Stroika/Foundation/Math/Common.h"
12
13#include "String2Int.h"
14
15using namespace Stroika::Foundation;
17
18/*
19 ********************************************************************************
20 ****************************** HexString2Int ***********************************
21 ********************************************************************************
22 */
23unsigned int Characters::HexString2Int (const String& s)
24{
25 Memory::StackBuffer<wchar_t> sPossibleBackingStore;
26 unsigned long l = wcstoul (get<0> (s.c_str (&sPossibleBackingStore)), nullptr, 16);
27 if (l >= numeric_limits<unsigned int>::max ()) {
28 return numeric_limits<unsigned int>::max ();
29 }
30 return l;
31}
32
33/*
34 ********************************************************************************
35 ********************************* String2Int ***********************************
36 ********************************************************************************
37 */
38long long int Characters::Private_::String2Int_ (const String& s)
39{
40 Memory::StackBuffer<wchar_t> possibleBackingStore;
41 wchar_t* endptr = nullptr;
42 unsigned long long int l = wcstoll (get<0> (s.c_str (&possibleBackingStore)), &endptr, 10);
43 return *endptr == '\0' ? l : 0; // weird but I document default is zero if failed to fully parse
44}
45
46/*
47 ********************************************************************************
48 ******************************** String2UInt ***********************************
49 ********************************************************************************
50 */
51unsigned long long int Characters::Private_::String2UInt_ (const String& s)
52{
53 Memory::StackBuffer<wchar_t> possibleBackingStore;
54 wchar_t* endptr = nullptr;
55 long long int l = wcstoull (get<0> (s.c_str (&possibleBackingStore)), &endptr, 10);
56 return *endptr == '\0' ? l : 0; // weird but I document default is zero if failed to fully parse
57}
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
nonvirtual tuple< const wchar_t *, wstring_view > c_str(Memory::StackBuffer< wchar_t > *possibleBackingStore) const
Definition String.inl:1049
Logically halfway between std::array and std::vector; Smart 'direct memory array' - which when needed...