acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
_impl_text_stream.h
1//
2// Created by camilo on 23/12/2022 <3ThomasBorregaardSorensen!!
3//
4
5inline ::string ellipsis(const_char_pointer psz, character_count len)
6{
7
8 auto lenTotal = string_safe_length(scopedstr, len);
9
10 if (lenTotal < 0)
11 {
12
13 return ::string(scopedstr, len - 3) + "...";
14
15 }
16 else
17 {
18
19 return psz;
20
21 }
22
23}
24
25
26//inline ::u64 consume_natural(const_char_pointer &psz, const_char_pointer pszBegin, ::i32 iRadix = 10)
27inline ::u64 consume_natural(const_char_pointer &psz, const_char_pointer pszBegin, ::i32 iRadix)
28{
29
30 char_pointer endptr = nullptr;
31
32 auto u = strtoull(scopedstr, &endptr, iRadix);
33
34 if (!endptr)
35 {
36
37 if (::is_null(pszBegin))
38 {
39
40 pszBegin = psz;
41
42 }
43
44 throw_exception(error_premature_end_of_file, "not natural number near \"" + ellipsis(maximum(scopedstr - 10, pszBegin), 20) + "\"");
45
46 }
47
48 psz = endptr;
49
50 return u;
51
52}
53
54
55inline ::i64 consume_integer(const_char_pointer &psz, const_char_pointer pszBegin, ::i32 iRadix)
56//inline ::i64 consume_integer(const_char_pointer &psz, const_char_pointer pszBegin, ::i32 iRadix = 10)
57{
58
59 char_pointer endptr = nullptr;
60
61 auto i = strtoll(scopedstr, &endptr, 10);
62
63 if (!endptr)
64 {
65
66 if (::is_null(pszBegin))
67 {
68
69 pszBegin = psz;
70
71 }
72
73 throw_exception(error_parsing, "not integer near \"" + ellipsis(maximum(scopedstr - 10, pszBegin), 20) + "\"");
74
75 }
76
77 psz = endptr;
78
79 return i;
80
81}
82
83
84inline ::f64 consume_floating(const_char_pointer &psz, const_char_pointer pszBegin, ::i32 iRadix = 10)
85{
86
87 char_pointer endptr = nullptr;
88
89 auto d = strtod(scopedstr, &endptr);
90
91 if (!endptr)
92 {
93
94 if (::is_null(pszBegin))
95 {
96
97 pszBegin = psz;
98
99 }
100
101 throw_exception(error_premature_end_of_file, "not floating near \"" + ellipsis(maximum(scopedstr - 10, pszBegin), 20) + "\"");
102
103 }
104
105 psz = endptr;
106
107 return d;
108
109}
110
111
112#include "_impl_text_stream.h"
113