yaml namespace
Classes
- class yaml_parser
- Line-oriented YAML parser that emits JSON.
Functions
- auto is_ipv6_literal(std::string_view s) -> bool
- True if
sis an IPv6 literal, with or without[]. - auto is_ipv4_literal(const std::string_view s) -> bool
- True if
sis a dotted-quad IPv4 literal. - auto is_ip_literal(const std::string_view s) -> bool
- True if
sis an IPv4 or IPv6 literal. - auto parse_yaml(std::istream& input) -> nlohmann::json
- Parse YAML from an input stream into JSON.
- auto parse_yaml(const std::string& input) -> nlohmann::json
- Parse YAML from a string into JSON.
- auto json_to_string(const nlohmann::json& v) -> std::string
- Convert a JSON scalar to a string.
- auto json_to_bool(const nlohmann::json& v, const bool fallback = false) -> bool
- Convert a JSON value to a boolean.
Function documentation
bool microserve:: yaml:: is_ipv6_literal(std::string_view s)
#include <src/microserve/yaml.cppm>
True if s is an IPv6 literal, with or without [].
bool microserve:: yaml:: is_ipv4_literal(const std::string_view s)
#include <src/microserve/yaml.cppm>
True if s is a dotted-quad IPv4 literal.
bool microserve:: yaml:: is_ip_literal(const std::string_view s)
#include <src/microserve/yaml.cppm>
True if s is an IPv4 or IPv6 literal.
nlohmann::json microserve:: yaml:: parse_yaml(std::istream& input)
#include <src/microserve/yaml.cppm>
Parse YAML from an input stream into JSON.
| Parameters | |
|---|---|
| input | Stream of YAML text. |
| Returns | JSON object for the parsed document. |
nlohmann::json microserve:: yaml:: parse_yaml(const std::string& input)
#include <src/microserve/yaml.cppm>
Parse YAML from a string into JSON.
| Parameters | |
|---|---|
| input | YAML text. |
| Returns | JSON object for the parsed document. |
std::string microserve:: yaml:: json_to_string(const nlohmann::json& v)
#include <src/microserve/yaml.cppm>
Convert a JSON scalar to a string.
| Parameters | |
|---|---|
| v | JSON value to convert. |
| Returns | String representation of v. |
| Exceptions | |
| std::runtime_error | If v is not a string, number, or one-key object. |
Strings are returned as-is. Integers, unsigned integers, and floats are formatted with std::to_string. A single-key object is treated as a host:port pair (YAML sequence items such as - 127.0.0.1:9934).
bool microserve:: yaml:: json_to_bool(const nlohmann::json& v,
const bool fallback = false)
#include <src/microserve/yaml.cppm>
Convert a JSON value to a boolean.
| Parameters | |
|---|---|
| v | JSON value to convert. |
| fallback | Value used when v has no recognised boolean form. |
| Returns | Converted boolean, or fallback. |
Accepts JSON booleans, YAML-style strings (true/false, on/off, yes/no, any common capitalisation), and integers (non-zero is true).