rapidyaml 0.15.2
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 2411 of file charconv.hpp.

2411{ 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,...

Referenced by from_chars_first(), from_chars_first(), from_chars_first(), from_chars_first(), from_chars_first(), from_chars_first(), from_chars_first(), from_chars_first(), from_chars_first(), from_chars_first(), from_chars_first(), from_chars_first(), from_chars_first(), from_chars_first(), from_chars_first(), from_chars_first(), uncat(), and unformat().

◆ from_chars_first() [2/18]

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

Definition at line 2412 of file charconv.hpp.

2412{ 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 2413 of file charconv.hpp.

2413{ 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 2414 of file charconv.hpp.

2414{ 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 2415 of file charconv.hpp.

2415{ 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 2416 of file charconv.hpp.

2416{ 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 2417 of file charconv.hpp.

2417{ 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 2418 of file charconv.hpp.

2418{ return atoi_first(buf, v); }

◆ from_chars_first() [9/18]

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

Definition at line 2419 of file charconv.hpp.

2419{ 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 2420 of file charconv.hpp.

2420{ 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 2422 of file charconv.hpp.

2422{ 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 2425 of file charconv.hpp.

2425{ 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 2510 of file charconv.hpp.

2511{
2512 csubstr trimmed = buf.first_non_empty_span();
2513 if(trimmed.len == 0 || !from_chars(buf, v))
2514 return csubstr::npos;
2515 return trimmed.len;
2516}
bool from_chars(csubstr buf, uint8_t *v) noexcept
basic_substring< const char > csubstr
an immutable string view
Definition substr.hpp:2356
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:1265

◆ from_chars_first() [14/18]

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

Definition at line 2547 of file charconv.hpp.

2548{
2549 if(buf.len < 1)
2550 return csubstr::npos;
2551 *v = buf.str[0];
2552 return 1;
2553}
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 2584 of file charconv.hpp.

2585{
2586 csubstr trimmed = buf.first_non_empty_span();
2587 if(trimmed.len == 0)
2588 return csubstr::npos;
2589 *v = trimmed;
2590 return static_cast<size_t>(trimmed.end() - buf.begin());
2591}
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 2637 of file charconv.hpp.

2638{
2639 csubstr trimmed = buf.first_non_empty_span();
2640 C4_ASSERT(!trimmed.overlaps(*v));
2641 if C4_UNLIKELY(trimmed.len == 0)
2642 return csubstr::npos;
2643 size_t len = trimmed.len > v->len ? v->len : trimmed.len;
2644 // calling memcpy with zero len is undefined behavior
2645 // and will wreak havoc in calling code's branches.
2646 // see https://github.com/biojppm/rapidyaml/pull/264#issuecomment-1262133637
2647 if(len)
2648 {
2649 C4_ASSERT(buf.str != nullptr);
2650 C4_ASSERT(v->str != nullptr);
2651 memcpy(v->str, trimmed.str, len);
2652 }
2653 if C4_UNLIKELY(trimmed.len > v->len)
2654 return csubstr::npos;
2655 return static_cast<size_t>(trimmed.end() - buf.begin());
2656}
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:493

◆ 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}