rapidyaml 0.14.0
parse and emit YAML, and do it fast
Loading...
Searching...
No Matches
from_chars_first: generalized chars to value

Read the first valid sequence of characters from the string, skipping leading whitespace, and convert it using from_chars: generalized chars to value . More...

Functions

size_t c4::from_chars_first (csubstr buf, uint8_t *v) noexcept
size_t c4::from_chars_first (csubstr buf, uint16_t *v) noexcept
size_t c4::from_chars_first (csubstr buf, uint32_t *v) noexcept
size_t c4::from_chars_first (csubstr buf, uint64_t *v) noexcept
size_t c4::from_chars_first (csubstr buf, int8_t *v) noexcept
size_t c4::from_chars_first (csubstr buf, int16_t *v) noexcept
size_t c4::from_chars_first (csubstr buf, int32_t *v) noexcept
size_t c4::from_chars_first (csubstr buf, int64_t *v) noexcept
size_t c4::from_chars_first (csubstr buf, float *v) noexcept
size_t c4::from_chars_first (csubstr buf, double *v) noexcept
template<class T>
auto c4::from_chars_first (csubstr buf, T *v) noexcept -> size_t::type
template<class T>
size_t c4::from_chars_first (csubstr buf, T **v) noexcept
size_t c4::from_chars_first (csubstr buf, bool *v) noexcept
size_t c4::from_chars_first (csubstr buf, char *v) noexcept
size_t c4::from_chars_first (csubstr buf, csubstr *v) noexcept
size_t c4::from_chars_first (csubstr buf, substr *v) noexcept
size_t c4::from_chars_first (csubstr buf, fmt::raw_wrapper *r)
 read a variable in raw binary format, using memcpy
size_t c4::from_chars_first (csubstr buf, fmt::raw_wrapper r)
 read a variable in raw binary format, using memcpy

Detailed Description

Read the first valid sequence of characters from the string, skipping leading whitespace, and convert it using from_chars: generalized chars to value .

Return the number of characters read for converting.

Dispatches to the most appropriate and efficient conversion function.

See also
atou_first, atoi_first, atof_first, atod_first

Function Documentation

◆ from_chars_first() [1/18]

size_t c4::from_chars_first ( csubstr buf,
uint8_t * v )
inlinenoexcept

Definition at line 2410 of file charconv.hpp.

2410{ return atou_first(buf, v); }
size_t atou_first(csubstr str, T *v)
Select the next range of characters in the string that can be parsed as an unsigned integral value,...

◆ from_chars_first() [2/18]

size_t c4::from_chars_first ( csubstr buf,
uint16_t * v )
inlinenoexcept

Definition at line 2411 of file charconv.hpp.

2411{ return atou_first(buf, v); }

◆ from_chars_first() [3/18]

size_t c4::from_chars_first ( csubstr buf,
uint32_t * v )
inlinenoexcept

Definition at line 2412 of file charconv.hpp.

2412{ return atou_first(buf, v); }

◆ from_chars_first() [4/18]

size_t c4::from_chars_first ( csubstr buf,
uint64_t * v )
inlinenoexcept

Definition at line 2413 of file charconv.hpp.

2413{ return atou_first(buf, v); }

◆ from_chars_first() [5/18]

size_t c4::from_chars_first ( csubstr buf,
int8_t * v )
inlinenoexcept

Definition at line 2414 of file charconv.hpp.

2414{ return atoi_first(buf, v); }
size_t atoi_first(csubstr str, T *v)
Select the next range of characters in the string that can be parsed as a signed integral value,...

◆ from_chars_first() [6/18]

size_t c4::from_chars_first ( csubstr buf,
int16_t * v )
inlinenoexcept

Definition at line 2415 of file charconv.hpp.

2415{ return atoi_first(buf, v); }

◆ from_chars_first() [7/18]

size_t c4::from_chars_first ( csubstr buf,
int32_t * v )
inlinenoexcept

Definition at line 2416 of file charconv.hpp.

2416{ return atoi_first(buf, v); }

◆ from_chars_first() [8/18]

size_t c4::from_chars_first ( csubstr buf,
int64_t * v )
inlinenoexcept

Definition at line 2417 of file charconv.hpp.

2417{ return atoi_first(buf, v); }

◆ from_chars_first() [9/18]

size_t c4::from_chars_first ( csubstr buf,
float * v )
inlinenoexcept

Definition at line 2418 of file charconv.hpp.

2418{ return atof_first(buf, v); }
size_t atof_first(csubstr str, float *v) noexcept
Convert a string to a single precision real number.

◆ from_chars_first() [10/18]

size_t c4::from_chars_first ( csubstr buf,
double * v )
inlinenoexcept

Definition at line 2419 of file charconv.hpp.

2419{ return atod_first(buf, v); }
size_t atod_first(csubstr str, double *v) noexcept
Convert a string to a double precision real number.

◆ from_chars_first() [11/18]

template<class T>
auto c4::from_chars_first ( csubstr buf,
T * v )->size_t::type
inlinenoexcept

Definition at line 2421 of file charconv.hpp.

2421{ return atoi_first(buf, v); }

◆ from_chars_first() [12/18]

template<class T>
size_t c4::from_chars_first ( csubstr buf,
T ** v )
inlinenoexcept

Definition at line 2424 of file charconv.hpp.

2424{ intptr_t tmp; bool ret = from_chars_first(buf, &tmp); if(ret) { *v = (T*)tmp; } return ret; }
size_t from_chars_first(csubstr buf, uint8_t *v) noexcept

◆ from_chars_first() [13/18]

size_t c4::from_chars_first ( csubstr buf,
bool * v )
inlinenoexcept

Definition at line 2509 of file charconv.hpp.

2510{
2511 csubstr trimmed = buf.first_non_empty_span();
2512 if(trimmed.len == 0 || !from_chars(buf, v))
2513 return csubstr::npos;
2514 return trimmed.len;
2515}
bool from_chars(csubstr buf, uint8_t *v) noexcept
basic_substring< const char > csubstr
an immutable string view
Definition substr.hpp:2357
size_t len
the length of the substring
Definition substr.hpp:218
basic_substring first_non_empty_span() const
get the first span consisting exclusively of non-empty characters
Definition substr.hpp:1266

◆ from_chars_first() [14/18]

size_t c4::from_chars_first ( csubstr buf,
char * v )
inlinenoexcept

Definition at line 2546 of file charconv.hpp.

2547{
2548 if(buf.len < 1)
2549 return csubstr::npos;
2550 *v = buf.str[0];
2551 return 1;
2552}
C * str
a restricted pointer to the first character of the substring
Definition substr.hpp:216

◆ from_chars_first() [15/18]

size_t c4::from_chars_first ( csubstr buf,
csubstr * v )
inlinenoexcept

Definition at line 2583 of file charconv.hpp.

2584{
2585 csubstr trimmed = buf.first_non_empty_span();
2586 if(trimmed.len == 0)
2587 return csubstr::npos;
2588 *v = trimmed;
2589 return static_cast<size_t>(trimmed.end() - buf.begin());
2590}
iterator begin() noexcept
Definition substr.hpp:360
iterator end() noexcept
Definition substr.hpp:361

◆ from_chars_first() [16/18]

size_t c4::from_chars_first ( csubstr buf,
substr * v )
inlinenoexcept

Definition at line 2636 of file charconv.hpp.

2637{
2638 csubstr trimmed = buf.first_non_empty_span();
2639 C4_ASSERT(!trimmed.overlaps(*v));
2640 if(C4_UNLIKELY(trimmed.len == 0))
2641 return csubstr::npos;
2642 size_t len = trimmed.len > v->len ? v->len : trimmed.len;
2643 // calling memcpy with zero len is undefined behavior
2644 // and will wreak havoc in calling code's branches.
2645 // see https://github.com/biojppm/rapidyaml/pull/264#issuecomment-1262133637
2646 if(len)
2647 {
2648 C4_ASSERT(buf.str != nullptr);
2649 C4_ASSERT(v->str != nullptr);
2650 memcpy(v->str, trimmed.str, len);
2651 }
2652 if(C4_UNLIKELY(trimmed.len > v->len))
2653 return csubstr::npos;
2654 return static_cast<size_t>(trimmed.end() - buf.begin());
2655}
bool overlaps(ro_substr const that) const noexcept
true if there is overlap of at least one element between that and *this
Definition substr.hpp:494

◆ from_chars_first() [17/18]

size_t c4::from_chars_first ( csubstr buf,
fmt::raw_wrapper * r )
inline

read a variable in raw binary format, using memcpy

Definition at line 472 of file format.hpp.

473{
474 return from_chars(buf, r);
475}

◆ from_chars_first() [18/18]

size_t c4::from_chars_first ( csubstr buf,
fmt::raw_wrapper r )
inline

read a variable in raw binary format, using memcpy

Definition at line 478 of file format.hpp.

479{
480 return from_chars(buf, &r);
481}