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
|
| bool | c4::from_chars (csubstr buf, fmt::base64_wrapper const &b) |
| | (1) read a variable in base64 format
|
| bool | c4::from_chars (csubstr buf, fmt::base64_wrapper *b) |
| | (2) read a variable in base64 format
|
| template<class T> |
| bool | c4::from_chars (csubstr buf, fmt::base64_container_wrapper< T > const &b) |
| | read a container in base64 format, resizing it as needed to accomodate the result
|
| template<class T> |
| bool | c4::from_chars (csubstr buf, fmt::base64_container_wrapper< T > const *b) |
| | read a container in base64 format, resizing it as needed to accomodate the result
|
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/24]
| bool c4::from_chars |
( |
csubstr | buf, |
|
|
uint8_t * | v ) |
|
inlinenoexcept |
Definition at line 2383 of file charconv.hpp.
2383{
return atou(buf, v); }
bool atou(csubstr str, T *v) noexcept
Convert a trimmed string to an unsigned integral value.
Referenced by from_chars(), from_chars(), from_chars(), from_chars_first(), from_chars_first(), from_chars_first(), c4::yml::from_chars_float(), c4::yml::from_chars_integral(), c4::yml::read(), c4::yml::read(), c4::yml::scalar_deserialize(), and uncatsep().
◆ from_chars() [2/24]
| bool c4::from_chars |
( |
csubstr | buf, |
|
|
uint16_t * | v ) |
|
inlinenoexcept |
◆ from_chars() [3/24]
| bool c4::from_chars |
( |
csubstr | buf, |
|
|
uint32_t * | v ) |
|
inlinenoexcept |
◆ from_chars() [4/24]
| bool c4::from_chars |
( |
csubstr | buf, |
|
|
uint64_t * | v ) |
|
inlinenoexcept |
◆ from_chars() [5/24]
| bool c4::from_chars |
( |
csubstr | buf, |
|
|
int8_t * | v ) |
|
inlinenoexcept |
Definition at line 2387 of file charconv.hpp.
2387{
return atoi(buf, v); }
bool atoi(csubstr str, T *v) noexcept
Convert a trimmed string to a signed integral value.
◆ from_chars() [6/24]
| bool c4::from_chars |
( |
csubstr | buf, |
|
|
int16_t * | v ) |
|
inlinenoexcept |
◆ from_chars() [7/24]
| bool c4::from_chars |
( |
csubstr | buf, |
|
|
int32_t * | v ) |
|
inlinenoexcept |
◆ from_chars() [8/24]
| bool c4::from_chars |
( |
csubstr | buf, |
|
|
int64_t * | v ) |
|
inlinenoexcept |
◆ from_chars() [9/24]
| bool c4::from_chars |
( |
csubstr | buf, |
|
|
float * | v ) |
|
inlinenoexcept |
Definition at line 2391 of file charconv.hpp.
2391{
return atof(buf, v); }
bool atof(csubstr str, float *v) noexcept
Convert a string to a single precision real number.
◆ from_chars() [10/24]
| bool c4::from_chars |
( |
csubstr | buf, |
|
|
double * | v ) |
|
inlinenoexcept |
Definition at line 2392 of file charconv.hpp.
2392{
return atod(buf, v); }
bool atod(csubstr str, double *v) noexcept
Convert a string to a double precision real number.
◆ from_chars() [11/24]
template<class T>
| auto c4::from_chars |
( |
csubstr | buf, |
|
|
T * | v )->bool::type |
|
inlinenoexcept |
◆ from_chars() [12/24]
template<class T>
| bool c4::from_chars |
( |
csubstr | buf, |
|
|
T ** | v ) |
|
inlinenoexcept |
Definition at line 2397 of file charconv.hpp.
2397{ 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/24]
| bool c4::from_chars |
( |
csubstr | buf, |
|
|
bool * | v ) |
|
inlinenoexcept |
Definition at line 2466 of file charconv.hpp.
2467{
2469 {
2470 if(buf.
str[0] ==
'0')
2471 {
2472 *v = false; return true;
2473 }
2474 else if(buf.
str[0] ==
'1')
2475 {
2476 *v = true; return true;
2477 }
2478 }
2479 else if(buf.
len == 4)
2480 {
2481 if(((buf.
str[0] ==
't') && (0 == memcmp(buf.
str + 1,
"rue", 3)))
2482 ||
2483 ((buf.
str[0] ==
'T') && (0 == memcmp(buf.
str + 1,
"rue", 3) ||
2484 0 == memcmp(buf.
str + 1,
"RUE", 3))))
2485 {
2486 *v = true; return true;
2487 }
2488 }
2489 else if(buf.
len == 5)
2490 {
2491 if(((buf.
str[0] ==
'f') && (0 == memcmp(buf.
str + 1,
"alse", 4)))
2492 ||
2493 ((buf.
str[0] ==
'F') && (0 == memcmp(buf.
str + 1,
"alse", 4) ||
2494 0 == memcmp(buf.
str + 1,
"ALSE", 4))))
2495 {
2496 *v = false; return true;
2497 }
2498 }
2499
2500 int val = 0;
2502 if C4_LIKELY(ret)
2503 {
2504 *v = (val != 0);
2505 }
2506 return ret;
2507}
size_t len
the length of the substring
C * str
a restricted pointer to the first character of the substring
◆ from_chars() [14/24]
| 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 2537 of file charconv.hpp.
2538{
2540 return false;
2541 C4_XASSERT(buf.
str);
2543 return true;
2544}
◆ from_chars() [15/24]
Definition at line 2577 of file charconv.hpp.
2578{
2579 *v = buf;
2580 return true;
2581}
◆ from_chars() [16/24]
Definition at line 2615 of file charconv.hpp.
2616{
2618
2620 {
2621
2622
2623
2625 {
2626 C4_ASSERT(buf.
str !=
nullptr);
2627 C4_ASSERT(v->
str !=
nullptr);
2629 }
2631 return true;
2632 }
2633 return false;
2634}
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/24]
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/24]
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/24]
read a variable in raw binary format, using memcpy
Definition at line 39 of file format.cpp.
40{
41 C4_SUPPRESS_WARNING_GCC_WITH_PUSH("-Wcast-qual")
42 void * vptr = (void*)buf.str;
43 C4_SUPPRESS_WARNING_GCC_POP
44 size_t space = buf.len;
45 char * ptr = (char*) std::align(r->alignment, r->len, vptr, space);
46 C4_CHECK(ptr != nullptr);
47 C4_CHECK(ptr >= buf.begin() && ptr <= buf.end());
48 C4_SUPPRESS_WARNING_GCC_PUSH
49 #if defined(__GNUC__) && __GNUC__ > 9
50 C4_SUPPRESS_WARNING_GCC("-Wanalyzer-null-argument")
51 #endif
52 memcpy(r->buf, ptr, r->len);
53 C4_SUPPRESS_WARNING_GCC_POP
54 return true;
55}
◆ from_chars() [20/24]
read a variable in raw binary format, using memcpy
Definition at line 465 of file format.hpp.
◆ from_chars() [21/24]
(1) read a variable in base64 format
Definition at line 219 of file format_base64.hpp.
220{
221 size_t reqsize = 0;
223 if(b.required_size)
224 *b.required_size = reqsize;
225 return ok;
226}
bool base64_decode(char const *encoded, size_t encoded_sz, void *data, size_t data_sz, size_t *data_sz_required)
decode the base64 encoding in the given buffer.
◆ from_chars() [22/24]
◆ from_chars() [23/24]
read a container in base64 format, resizing it as needed to accomodate the result
Definition at line 261 of file format_base64.hpp.
262{
264 blob data = b.data();
265 size_t required_size = 0;
267 if(b.required_size)
268 *b.required_size = required_size;
269 if(!required_size)
270 return ok;
271 else if(!ok && ((required_size < data.len) || (required_size % elm_sz)))
272 return false;
273 size_t num_elms = required_size / elm_sz;
274 b.container->resize(num_elms);
275 if(required_size > data.len)
276 {
277 data = b.data();
279 if(b.required_size)
280 *b.required_size = required_size;
281 }
282 return ok;
283}
detail::base64_container_wrapper_< Container, byte > base64_container_wrapper
a tag type to mark a payload to be encoded as base64
◆ from_chars() [24/24]
read a container in base64 format, resizing it as needed to accomodate the result
Definition at line 288 of file format_base64.hpp.