parse.c file
Parser implementation.
Functions
- auto bd_parse_digits(const char* str) -> bool
- True when str is non-empty and contains only decimal digits.
- auto bd_parse_colon_count(const char* str) -> int
- Count ':' characters in str.
- static auto accumulate(uint64_t* value, const unsigned digit, const uint64_t limit) -> bool
- auto bd_parse_u64(const char* str, uint64_t* out) -> bool
- Parse an unsigned 64-bit decimal integer.
- auto bd_parse_i64(const char* str, int64_t* out) -> bool
- Parse a signed 64-bit decimal integer.
- auto bd_parse_i32(const char* str, int32_t* out) -> bool
- Parse a signed 32-bit decimal integer.
- auto bd_parse_u32(const char* str, uint32_t* out) -> bool
- Parse an unsigned 32-bit decimal integer.
- auto bd_parse_u16(const char* str, uint16_t* out) -> bool
- Parse an unsigned 16-bit decimal integer.
- auto bd_parse_f64(const char* str, double* out) -> bool
- Parse a floating-point value.
- auto bd_parse_bool(const char* str, bool* out) -> bool
- Parse a boolean word.
- auto bd_parse_host_port(const char* spec, char* host, size_t host_size, uint16_t* port) -> bool
- Split "host" or "host:port".
Function documentation
bool bd_parse_digits(const char* str)
True when str is non-empty and contains only decimal digits.
| Parameters | |
|---|---|
| str | String to test. NULL is not digits. |
| Returns | true when str is non-empty and contains only decimal digits. |
int bd_parse_colon_count(const char* str)
Count ':' characters in str.
| Parameters | |
|---|---|
| str | String to scan. NULL counts as zero. |
| Returns | Number of ':' characters, or 0 if str is NULL. |
bool bd_parse_u64(const char* str, uint64_t* out)
Parse an unsigned 64-bit decimal integer.
| Parameters | |
|---|---|
| str | Text to parse. |
| out | Receives the value on success. |
| Returns | true on success. |
No sign is accepted.
bool bd_parse_i64(const char* str, int64_t* out)
Parse a signed 64-bit decimal integer.
| Parameters | |
|---|---|
| str | Text to parse. |
| out | Receives the value on success. |
| Returns | true on success. |
Accepts an optional leading + or -. Rejects empty input, trailing junk, and values outside int64_t.
bool bd_parse_i32(const char* str, int32_t* out)
Parse a signed 32-bit decimal integer.
| Parameters | |
|---|---|
| str | Text to parse. |
| out | Receives the value on success. |
| Returns | true on success. |
bool bd_parse_u32(const char* str, uint32_t* out)
Parse an unsigned 32-bit decimal integer.
| Parameters | |
|---|---|
| str | Text to parse. |
| out | Receives the value on success. |
| Returns | true on success. |
bool bd_parse_u16(const char* str, uint16_t* out)
Parse an unsigned 16-bit decimal integer.
| Parameters | |
|---|---|
| str | Text to parse. |
| out | Receives the value on success. |
| Returns | true on success. |
bool bd_parse_f64(const char* str, double* out)
Parse a floating-point value.
| Parameters | |
|---|---|
| str | Text to parse. |
| out | Receives the value on success. |
| Returns | true on success. |
Uses base-10 text. Rejects empty input, leading space, trailing junk, non-finite values, and overflow.
bool bd_parse_bool(const char* str, bool* out)
Parse a boolean word.
| Parameters | |
|---|---|
| str | Text to parse. |
| out | Receives the value on success. |
| Returns | true on success. |
Accepts 1/0, true/false, and yes/no, ignoring case.
bool bd_parse_host_port(const char* spec, char* host, size_t host_size, uint16_t* port)
Split "host" or "host:port".
| Parameters | |
|---|---|
| spec | Input "host" or "host:port". |
| host | Output buffer. Always NUL-terminated on success. |
| host_size | Capacity of host. |
| port | Optional. Set only when a valid port is present. |
| Returns | true on success. |
Several colons stay part of the host. A single trailing ":digits" with a non-zero port is parsed. Rejects empty or leading-dash specs and hosts that do not fit in host_size, including the terminating NUL.