rapidyaml  0.16.0
parseandemitYAML,anddoitfast
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 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

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

Definition at line 2411 of file charconv.hpp.

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

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...
Definition: charconv.hpp:1600
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); }
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:1600
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); }
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:1600
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); }
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:1600
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...
Definition: charconv.hpp:1521
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); }
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:1521
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); }
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:1521
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); }
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:1521
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.
Definition: charconv.hpp:2159
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.
Definition: charconv.hpp:2224
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); }
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:1521
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, substr *v) noexcept
Definition: charconv.hpp:2637
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, substr *v) noexcept
Definition: charconv.hpp:2615
basic_substring first_non_empty_span() const
get the first span consisting exclusively of non-empty characters
Definition: substr.hpp:1265
a null string position
Definition: common.hpp:138
basic_substring< const char > csubstr
an immutable string view
Definition: substr.hpp:2356
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 }
a null string position
Definition: common.hpp:138
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 }
basic_substring first_non_empty_span() const
get the first span consisting exclusively of non-empty characters
Definition: substr.hpp:1265
a null string position
Definition: common.hpp:138
basic_substring< const char > csubstr
an immutable string view
Definition: substr.hpp:2356
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 }
basic_substring first_non_empty_span() const
get the first span consisting exclusively of non-empty characters
Definition: substr.hpp:1265
a null string position
Definition: common.hpp:138
basic_substring< const char > csubstr
an immutable string view
Definition: substr.hpp:2356
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 }
bool from_chars(csubstr buf, fmt::raw_wrapper r)
read a variable in raw binary format, using memcpy
Definition: format.hpp:465
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 }
bool from_chars(csubstr buf, fmt::raw_wrapper r)
read a variable in raw binary format, using memcpy
Definition: format.hpp:465