Read a value from the string, which must be trimmed to the value (ie, no leading/trailing whitespace).
More...
|
| bool | c4::from_chars (csubstr buf, uint8_t *v) noexcept |
| bool | c4::from_chars (csubstr buf, uint16_t *v) noexcept |
| bool | c4::from_chars (csubstr buf, uint32_t *v) noexcept |
| bool | c4::from_chars (csubstr buf, uint64_t *v) noexcept |
| bool | c4::from_chars (csubstr buf, int8_t *v) noexcept |
| bool | c4::from_chars (csubstr buf, int16_t *v) noexcept |
| bool | c4::from_chars (csubstr buf, int32_t *v) noexcept |
| bool | c4::from_chars (csubstr buf, int64_t *v) noexcept |
| bool | c4::from_chars (csubstr buf, float *v) noexcept |
| bool | c4::from_chars (csubstr buf, double *v) noexcept |
| template<class T> |
| auto | c4::from_chars (csubstr buf, T *v) noexcept -> bool::type |
| template<class T> |
| bool | c4::from_chars (csubstr buf, T **v) noexcept |
| bool | c4::from_chars (csubstr buf, bool *v) noexcept |
| bool | c4::from_chars (csubstr buf, char *v) noexcept |
| | extract a single character from a substring
|
| bool | c4::from_chars (csubstr buf, csubstr *v) noexcept |
| bool | c4::from_chars (csubstr buf, substr *v) noexcept |
| template<class T> |
| bool | c4::from_chars (csubstr s, fmt::overflow_checked_< T > wrapper) |
| | read an integer type, detecting overflow (returns false on overflow)
|
| template<class T> |
| bool | c4::from_chars (csubstr s, fmt::overflow_checked_< T > *wrapper) |
| | read an integer type, detecting overflow (returns false on overflow)
|
| bool | c4::from_chars (csubstr buf, fmt::raw_wrapper *r) |
| | read a variable in raw binary format, using memcpy
|
| bool | c4::from_chars (csubstr buf, fmt::raw_wrapper r) |
| | read a variable in raw binary format, using memcpy
|
Read a value from the string, which must be trimmed to the value (ie, no leading/trailing whitespace).
return true if the conversion succeeded. There is no check for overflow; the value wraps around in a way similar to the standard C/C++ overflow behavior. For example, from_chars<int8_t>("128", &val) returns true and val will be set tot 0. See overflows: does a number string overflow a type and Check read for overflow for facilities enforcing no-overflow.
Dispatches to the most appropriate and efficient conversion function
- See also
- from_chars_first: generalized chars to value, atou, atoi, atof, atod
◆ from_chars() [1/20]
| bool c4::from_chars |
( |
csubstr | buf, |
|
|
uint8_t * | v ) |
|
inlinenoexcept |
Definition at line 2382 of file charconv.hpp.
2382{
return atou(buf, v); }
bool atou(csubstr str, T *v) noexcept
Convert a trimmed string to an unsigned integral value.
◆ from_chars() [2/20]
| bool c4::from_chars |
( |
csubstr | buf, |
|
|
uint16_t * | v ) |
|
inlinenoexcept |
◆ from_chars() [3/20]
| bool c4::from_chars |
( |
csubstr | buf, |
|
|
uint32_t * | v ) |
|
inlinenoexcept |
◆ from_chars() [4/20]
| bool c4::from_chars |
( |
csubstr | buf, |
|
|
uint64_t * | v ) |
|
inlinenoexcept |
◆ from_chars() [5/20]
| bool c4::from_chars |
( |
csubstr | buf, |
|
|
int8_t * | v ) |
|
inlinenoexcept |
Definition at line 2386 of file charconv.hpp.
2386{
return atoi(buf, v); }
bool atoi(csubstr str, T *v) noexcept
Convert a trimmed string to a signed integral value.
◆ from_chars() [6/20]
| bool c4::from_chars |
( |
csubstr | buf, |
|
|
int16_t * | v ) |
|
inlinenoexcept |
◆ from_chars() [7/20]
| bool c4::from_chars |
( |
csubstr | buf, |
|
|
int32_t * | v ) |
|
inlinenoexcept |
◆ from_chars() [8/20]
| bool c4::from_chars |
( |
csubstr | buf, |
|
|
int64_t * | v ) |
|
inlinenoexcept |
◆ from_chars() [9/20]
| bool c4::from_chars |
( |
csubstr | buf, |
|
|
float * | v ) |
|
inlinenoexcept |
Definition at line 2390 of file charconv.hpp.
2390{
return atof(buf, v); }
bool atof(csubstr str, float *v) noexcept
Convert a string to a single precision real number.
◆ from_chars() [10/20]
| bool c4::from_chars |
( |
csubstr | buf, |
|
|
double * | v ) |
|
inlinenoexcept |
Definition at line 2391 of file charconv.hpp.
2391{
return atod(buf, v); }
bool atod(csubstr str, double *v) noexcept
Convert a string to a double precision real number.
◆ from_chars() [11/20]
template<class T>
| auto c4::from_chars |
( |
csubstr | buf, |
|
|
T * | v )->bool::type |
|
inlinenoexcept |
◆ from_chars() [12/20]
template<class T>
| bool c4::from_chars |
( |
csubstr | buf, |
|
|
T ** | v ) |
|
inlinenoexcept |
Definition at line 2396 of file charconv.hpp.
2396{ intptr_t tmp;
bool ret =
from_chars(buf, &tmp);
if(ret) { *v = (T*)tmp; }
return ret; }
bool from_chars(csubstr buf, uint8_t *v) noexcept
◆ from_chars() [13/20]
| bool c4::from_chars |
( |
csubstr | buf, |
|
|
bool * | v ) |
|
inlinenoexcept |
Definition at line 2465 of file charconv.hpp.
2466{
2468 {
2469 if(buf.
str[0] ==
'0')
2470 {
2471 *v = false; return true;
2472 }
2473 else if(buf.
str[0] ==
'1')
2474 {
2475 *v = true; return true;
2476 }
2477 }
2478 else if(buf.
len == 4)
2479 {
2480 if(((buf.
str[0] ==
't') && (0 == memcmp(buf.
str + 1,
"rue", 3)))
2481 ||
2482 ((buf.
str[0] ==
'T') && (0 == memcmp(buf.
str + 1,
"rue", 3) ||
2483 0 == memcmp(buf.
str + 1,
"RUE", 3))))
2484 {
2485 *v = true; return true;
2486 }
2487 }
2488 else if(buf.
len == 5)
2489 {
2490 if(((buf.
str[0] ==
'f') && (0 == memcmp(buf.
str + 1,
"alse", 4)))
2491 ||
2492 ((buf.
str[0] ==
'F') && (0 == memcmp(buf.
str + 1,
"alse", 4) ||
2493 0 == memcmp(buf.
str + 1,
"ALSE", 4))))
2494 {
2495 *v = false; return true;
2496 }
2497 }
2498
2499 int val = 0;
2501 if(C4_LIKELY(ret))
2502 {
2503 *v = (val != 0);
2504 }
2505 return ret;
2506}
size_t len
the length of the substring
C * str
a restricted pointer to the first character of the substring
◆ from_chars() [14/20]
| bool c4::from_chars |
( |
csubstr | buf, |
|
|
char * | v ) |
|
inlinenoexcept |
extract a single character from a substring
- Note
- to extract a string instead and not just a single character, use the csubstr overload
Definition at line 2536 of file charconv.hpp.
2537{
2539 return false;
2540 C4_XASSERT(buf.
str);
2542 return true;
2543}
◆ from_chars() [15/20]
Definition at line 2576 of file charconv.hpp.
2577{
2578 *v = buf;
2579 return true;
2580}
◆ from_chars() [16/20]
Definition at line 2614 of file charconv.hpp.
2615{
2617
2619 {
2620
2621
2622
2624 {
2625 C4_ASSERT(buf.
str !=
nullptr);
2626 C4_ASSERT(v->
str !=
nullptr);
2628 }
2630 return true;
2631 }
2632 return false;
2633}
bool overlaps(ro_substr const that) const noexcept
true if there is overlap of at least one element between that and *this
◆ from_chars() [17/20]
read an integer type, detecting overflow (returns false on overflow)
Definition at line 322 of file format.hpp.
323{
326 return false;
327}
bool atox(csubstr s, uint8_t *v) noexcept
auto overflows(csubstr str) noexcept -> typename std::enable_if< std::is_unsigned< T >::value, bool >::type
Test if the following string would overflow when converted to associated integral types; this functio...
◆ from_chars() [18/20]
read an integer type, detecting overflow (returns false on overflow)
Definition at line 331 of file format.hpp.
332{
335 return false;
336}
◆ from_chars() [19/20]
read a variable in raw binary format, using memcpy
◆ from_chars() [20/20]
read a variable in raw binary format, using memcpy
Definition at line 465 of file format.hpp.