fix: stabilize runtime follow-up regressions
This commit is contained in:
1 parent
7f757654b6
commit
20db669589
37 files changed
+906
-144
No files matched your search
@@ -1,5 +1,9 @@
|
||||
:sig
|
||||
bool DTree::to_bool()
|
||||
bool DTree::to_bool(bool default_value = false) const
|
||||
|
||||
:params
|
||||
default_value : returned when the value is missing or empty
|
||||
return value : the value as a boolean, or `default_value`
|
||||
|
||||
:see
|
||||
>types
|
||||
@@ -7,12 +11,27 @@ bool DTree::to_bool()
|
||||
json_decode
|
||||
to_f64
|
||||
to_u64
|
||||
to_string
|
||||
|
||||
:content
|
||||
Reads a `DTree` value as a boolean.
|
||||
Reads a `DTree` value as a boolean. This is a read accessor: it is `const`, never creates or modifies nodes, and dereferences internal references automatically.
|
||||
|
||||
String values such as `true`, `yes`, `on`, and `1` read as true. Values such as `false`, `no`, `off`, `0`, and `null` read as false.
|
||||
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.
|
||||
|
||||
Numeric values read as true when non-zero. Empty strings read as false.
|
||||
`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();
|
||||
```
|
||||
|
||||
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
|
||||
Reference in new issue
Block a user