rapidyaml  0.13.0
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 2396 of file charconv.hpp.

2396 { 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:1586

◆ from_chars_first() [2/18]

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

Definition at line 2397 of file charconv.hpp.

2397 { 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 2398 of file charconv.hpp.

2398 { 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 2399 of file charconv.hpp.

2399 { 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 2400 of file charconv.hpp.

2400 { 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

◆ from_chars_first() [6/18]

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

Definition at line 2401 of file charconv.hpp.

2401 { 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 2402 of file charconv.hpp.

2402 { 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 2403 of file charconv.hpp.

2403 { return atoi_first(buf, v); }

◆ from_chars_first() [9/18]

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

Definition at line 2404 of file charconv.hpp.

2404 { 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:2144

◆ from_chars_first() [10/18]

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

Definition at line 2405 of file charconv.hpp.

2405 { 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:2209

◆ from_chars_first() [11/18]

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

Definition at line 2407 of file charconv.hpp.

2407 { 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 2410 of file charconv.hpp.

2410 { 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:2622

◆ from_chars_first() [13/18]

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

Definition at line 2495 of file charconv.hpp.

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

◆ from_chars_first() [14/18]

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

Definition at line 2532 of file charconv.hpp.

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

◆ from_chars_first() [15/18]

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

Definition at line 2569 of file charconv.hpp.

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

◆ from_chars_first() [16/18]

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

Definition at line 2622 of file charconv.hpp.

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

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

477 {
478  return from_chars(buf, r);
479 }
bool from_chars(csubstr buf, fmt::raw_wrapper r)
read a variable in raw binary format, using memcpy
Definition: format.hpp:469

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

483 {
484  return from_chars(buf, &r);
485 }