This commit is contained in:
root
2026-06-15 21:42:50 +00:00
parent 34a97e2577
commit 99cd92fb4a
126 changed files with 1615 additions and 1057 deletions
+10 -25
View File
@@ -1,37 +1,22 @@
:sig
bool DValue::to_bool(bool default_value = false) const
bool to_bool(String s, bool fallback = false)
:params
default_value : returned when the value is missing or empty
return value : the value as a boolean, or `default_value`
s : string to parse
fallback : value returned when `s` is empty or not a recognized boolean token
return value : parsed bool, or `fallback`.
:see
>types
0_DValue
json_decode
to_f64
to_u64
to_string
to_s64
to_f64
:content
Reads a `DValue` value as a boolean. This is a read accessor: it is `const`, never creates or modifies nodes, and dereferences internal references automatically.
Parses a trimmed, case-insensitive boolean string.
String values such as `true`, `yes`, `on`, and `1` read as true. Values such as `false`, `no`, `off`, `0`, and `null` read as false. Numeric values read as true when non-zero.
Truthy tokens are `"1"`, `"true"`, `"yes"`, and `"on"`. Falsey tokens are `"0"`, `"false"`, `"no"`, and `"off"`. Empty or unrecognized strings return the fallback.
`default_value` is returned when the node is unset, holds an empty string, or is an unresolvable reference. Note the truthiness rule: a non-empty string that parses as neither a boolean word nor a number still reads as `true` — only missing/empty values fall back to the default.
A map-shaped node with exactly one entry unwraps to that entry's value; other maps read as true when non-empty.
## Example
```cpp
bool log_requests = context.cfg.get_by_path("app/log_requests").to_bool(true);
bool wants_compact = context.props["compact"].to_bool();
```uce
bool enabled = to_bool(context.server->config["FEATURE_ENABLED"], true);
```
Use this when consuming request data, JSON-decoded values, config trees, or component props where the original input may be string-shaped.
## Related Concepts
- PHP: `filter_var($v, FILTER_VALIDATE_BOOLEAN)`
- JavaScript: `Boolean(value)` plus string handling