13inline ::i32 utoa_base(char_pointer psz,
size_t size, ::u64 u, ::i32 base);
23inline ::i32 itoa_base(char_pointer psz,
size_t size, ::i64 i, ::i32 base);
26constexpr character_count _utoa_base(char_pointer psz, character_count size, ::u64 u, ::i32 base)
32 ::i32 digit = (u % base);
46 *psz = __digit(digit);
59inline character_count utoa_base(char_pointer psz, character_count size, ::u64 u, ::i32 base)
62 if (base < 2 || base > 36)
65 throw error_bad_argument;
71 auto res = _utoa_base(psz, size - 1, u, base);
76 psz[minimum(size - 1, size - 1 + res)] =
'\0';
85constexpr character_count _itoa_base(char_pointer psz, character_count size, ::i64 i, ::i32 base)
91 ::i32 digit = -(i % base);
105 *psz = __digit(digit);
118inline character_count itoa_base(char_pointer psz, character_count size, ::i64 i, ::i32 base)
121 if (base < 2 || base > 36)
124 throw_exception(error_bad_argument);
145 auto res = _itoa_base(psz, size - 1, i, base);
150 psz[minimum(size - 1, size - 1 + res)] =
'\0';
159template < prototype_
integral INTEGRAL >
160inline INTEGRAL& _consume(INTEGRAL& i, ::ansi_range&
range, ::i32 iBase = 10)
165 auto end = minimum(
range.end(),
range.begin() + maximum_digits<INTEGRAL>(iBase));
167 while (
range.begin() < end)
170 auto digit =
range.defer_consume_digit(iBase);
175 throw "_string parsing error _consume";
179 i = digit + i * iBase;
188template < prototype_
unsigned UNSIGNED >
189inline UNSIGNED & consume(UNSIGNED& u, ::ansi_range&
range, ::i32 iBase = 10)
192 return _consume(u,
range, iBase);
197template < prototype_
signed SIGNED >
198inline SIGNED & consume(SIGNED & s, ::ansi_range&
range, ::i32 iBase = 10)
201 bool bNegative =
range.begins_eat(
'-');
203 _consume(s,
range, iBase);
205 if(bNegative) s = -s;
212template < prototype_
integral INTEGRAL >
213INTEGRAL consume_integral(::ansi_range&
range, ::i32 iBase = 10)
218 consume(integral,
range, iBase);
225template <
typename BASE_RANGE >
226inline ::i64 consume_i64(::string_range < BASE_RANGE > &
range , ::i32 iBase = 10) {
return consume_integral < ::i64 >(
range, iBase); }
227template <
typename BASE_RANGE >
228inline ::i32 consume_int(::string_range < BASE_RANGE > &
range , ::i32 iBase = 10) {
return consume_integral < ::i32 >(
range, iBase); }
229template <
typename BASE_RANGE >
230inline ::i16 consume_short(::string_range < BASE_RANGE > &
range , ::i32 iBase = 10) {
return consume_integral < ::i16 >(
range, iBase); }
231template <
typename BASE_RANGE >
232inline ::i8 consume_char(::string_range < BASE_RANGE > &
range, ::i32 iBase = 10) {
return consume_integral < ::i8 >(
range, iBase); }
235template <
typename BASE_RANGE >
236inline ::u64 consume_u64(::string_range < BASE_RANGE >&
range, ::i32 iBase = 10) {
return consume_integral < ::u64 >(
range, iBase); }
237template <
typename BASE_RANGE >
238inline ::u32 consume_u32(::string_range < BASE_RANGE >&
range, ::i32 iBase = 10) {
return consume_integral < ::u32 >(
range, iBase); }
239template <
typename BASE_RANGE >
240inline ::u16 consume_unsigned_short(::string_range < BASE_RANGE >&
range, ::i32 iBase = 10) {
return consume_integral < ::u16 >(
range, iBase); }
241template <
typename BASE_RANGE >
242inline ::u8 consume_unsigned_char(::string_range < BASE_RANGE >&
range, ::i32 iBase = 10) {
return consume_integral < ::u8 >(
range, iBase); }
244template <
typename BASE_RANGE >
245inline long consume_long(::string_range < BASE_RANGE >&
range, ::i32 iBase = 10) {
return consume_integral < long >(
range, iBase); }
246template <
typename BASE_RANGE >
247inline ulong consume_unsigned_long(::string_range < BASE_RANGE >&
range, ::i32 iBase = 10) {
return consume_integral < ulong >(
range, iBase); }
248template <
typename BASE_RANGE >
249inline size_t consume_size_t(::string_range < BASE_RANGE >&
range, ::i32 iBase = 10) {
return consume_integral < size_t >(
range, iBase); }
252inline ::i64 as_i64(const ::scoped_string& scopedstr, ::i32 iBase = 10) {
auto r = scopedstr();
return consume_i64(r, iBase); }
253inline ::i32 as_i32(const ::scoped_string& scopedstr, ::i32 iBase = 10) {
auto r = scopedstr();
return consume_int(r, iBase); }
254inline ::i32 as_i16(const ::scoped_string& scopedstr, ::i32 iBase = 10) {
auto r = scopedstr();
return consume_short(r, iBase); }
255inline ::i8 as_i8(const ::scoped_string& scopedstr, ::i32 iBase = 10) {
auto r = scopedstr();
return consume_char(r, iBase); }
258inline ::u64 as_u64(const ::scoped_string& scopedstr, ::i32 iBase = 10) {
auto r = scopedstr();
return consume_u64(r, iBase); }
259inline ::u32 as_u32(const ::scoped_string& scopedstr, ::i32 iBase = 10) {
auto r = scopedstr();
return consume_u32(r, iBase); }
260inline ::u32 as_u16(const ::scoped_string& scopedstr, ::i32 iBase = 10) {
auto r = scopedstr();
return consume_unsigned_short(r, iBase); }
261inline ::u8 as_u8(const ::scoped_string& scopedstr, ::i32 iBase = 10) {
auto r = scopedstr();
return consume_unsigned_char(r, iBase); }
264inline long as_long(const ::scoped_string& scopedstr, ::i32 iBase = 10) {
auto r = scopedstr();
return consume_long(r, iBase); }
265inline ulong as_unsigned_long(const ::scoped_string& scopedstr, ::i32 iBase = 10) {
auto r = scopedstr();
return consume_unsigned_long(r, iBase); }
266inline size_t as_size_t(const ::scoped_string& scopedstr, ::i32 iBase = 10) {
auto r = scopedstr();
return consume_size_t(r, iBase); }
443template < prototype_
integral INTEGRAL >
444inline void from_string(INTEGRAL & i, const ::scoped_string & scopedstr, ::i32 iBase = 10)
447 auto r = scopedstr();
449 if(r.case_insensitive_equals(
"FALSE") ||
450 r.case_insensitive_equals(
"OFF") ||
451 r.case_insensitive_equals(
"NO"))
457 else if(r.case_insensitive_equals(
"TRUE") ||
458 r.case_insensitive_equals(
"ON") ||
459 r.case_insensitive_equals(
"YES"))
468 consume(i, r, iBase);
475template < prototype_
floating FLOATING >
476inline void from_string(FLOATING& f, const ::scoped_string& scopedstr)
479 ::string str(scopedstr);
481 f = (FLOATING) strtod(str.c_str(),
nullptr);