rapidyaml  0.12.1
parse and emit YAML, and do it fast
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 (substr 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 More...
 
size_t c4::from_chars_first (csubstr buf, fmt::raw_wrapper r)
 read a variable in raw binary format, using memcpy More...
 

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 2394 of file charconv.hpp.

2394 { 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,...
Definition: charconv.hpp:1588

References c4::atou_first().

◆ from_chars_first() [2/18]

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

Definition at line 2395 of file charconv.hpp.

2395 { return atou_first(buf, v); }

References c4::atou_first().

◆ from_chars_first() [3/18]

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

Definition at line 2396 of file charconv.hpp.

2396 { return atou_first(buf, v); }

References c4::atou_first().

◆ from_chars_first() [4/18]

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

Definition at line 2397 of file charconv.hpp.

2397 { return atou_first(buf, v); }

References c4::atou_first().

◆ from_chars_first() [5/18]

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

Definition at line 2398 of file charconv.hpp.

2398 { 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,...
Definition: charconv.hpp:1507

References c4::atoi_first().

◆ from_chars_first() [6/18]

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

Definition at line 2399 of file charconv.hpp.

2399 { return atoi_first(buf, v); }

References c4::atoi_first().

◆ from_chars_first() [7/18]

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

Definition at line 2400 of file charconv.hpp.

2400 { return atoi_first(buf, v); }

References c4::atoi_first().

◆ from_chars_first() [8/18]

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

Definition at line 2401 of file charconv.hpp.

2401 { return atoi_first(buf, v); }

References c4::atoi_first().

◆ from_chars_first() [9/18]

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

Definition at line 2402 of file charconv.hpp.

2402 { return atof_first(buf, v); }
size_t atof_first(csubstr str, float *v) noexcept
Convert a string to a single precision real number.
Definition: charconv.hpp:2148

References c4::atof_first().

◆ from_chars_first() [10/18]

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

Definition at line 2403 of file charconv.hpp.

2403 { return atod_first(buf, v); }
size_t atod_first(csubstr str, double *v) noexcept
Convert a string to a double precision real number.
Definition: charconv.hpp:2213

References c4::atod_first().

◆ from_chars_first() [11/18]

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

Definition at line 2405 of file charconv.hpp.

2405 { 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 2408 of file charconv.hpp.

2408 { intptr_t tmp; bool ret = from_chars_first(buf, &tmp); if(ret) { *v = (T*)tmp; } return ret; }
size_t from_chars_first(csubstr buf, substr *v) noexcept
Definition: charconv.hpp:2621

References c4::from_chars_first().

◆ from_chars_first() [13/18]

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

Definition at line 2494 of file charconv.hpp.

2495 {
2496  csubstr trimmed = buf.first_non_empty_span();
2497  if(trimmed.len == 0 || !from_chars(buf, v))
2498  return csubstr::npos;
2499  return trimmed.len;
2500 }
bool from_chars(csubstr buf, substr *v) noexcept
Definition: charconv.hpp:2599
@ npos
a null string position
Definition: common.hpp:258

References c4::from_chars(), and c4::yml::npos.

◆ from_chars_first() [14/18]

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

Definition at line 2531 of file charconv.hpp.

2532 {
2533  if(buf.len < 1)
2534  return csubstr::npos;
2535  *v = buf.str[0];
2536  return 1;
2537 }

References c4::yml::npos.

◆ from_chars_first() [15/18]

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

Definition at line 2568 of file charconv.hpp.

2569 {
2570  csubstr trimmed = buf.first_non_empty_span();
2571  if(trimmed.len == 0)
2572  return csubstr::npos;
2573  *v = trimmed;
2574  return static_cast<size_t>(trimmed.end() - buf.begin());
2575 }

References c4::yml::npos.

◆ from_chars_first() [16/18]

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

Definition at line 2621 of file charconv.hpp.

2622 {
2623  csubstr trimmed = buf.first_non_empty_span();
2624  C4_ASSERT(!trimmed.overlaps(*v));
2625  if(C4_UNLIKELY(trimmed.len == 0))
2626  return csubstr::npos;
2627  size_t len = trimmed.len > v->len ? v->len : trimmed.len;
2628  // calling memcpy with null strings is undefined behavior
2629  // and will wreak havoc in calling code's branches.
2630  // see https://github.com/biojppm/rapidyaml/pull/264#issuecomment-1262133637
2631  if(len)
2632  {
2633  C4_ASSERT(buf.str != nullptr);
2634  C4_ASSERT(v->str != nullptr);
2635  memcpy(v->str, trimmed.str, len);
2636  }
2637  if(C4_UNLIKELY(trimmed.len > v->len))
2638  return csubstr::npos;
2639  return static_cast<size_t>(trimmed.end() - buf.begin());
2640 }

References c4::yml::npos.

◆ 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 480 of file format.hpp.

481 {
482  return from_chars(buf, r);
483 }
bool from_chars(csubstr buf, fmt::raw_wrapper r)
read a variable in raw binary format, using memcpy
Definition: format.hpp:473

References c4::from_chars().

◆ 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 486 of file format.hpp.

487 {
488  return from_chars(buf, &r);
489 }

References c4::from_chars().