Parse an inline YAML flow mapping like `{a: 1, b: true}` into a JSON object.
(value: &str)
| 869 | |
| 870 | /// Parse an inline YAML flow mapping like `{a: 1, b: true}` into a JSON object. |
| 871 | fn parse_inline_map(value: &str) -> Option<serde_json::Value> { |
| 872 | let trimmed = value.trim(); |
| 873 | if !trimmed.starts_with('{') || !trimmed.ends_with('}') { |
| 874 | return None; |
| 875 | } |
| 876 | let inner = trimmed[1..trimmed.len() - 1].trim(); |
| 877 | if inner.is_empty() { |
| 878 | return Some(serde_json::Value::Object(serde_json::Map::new())); |
| 879 | } |
| 880 | let mut map = serde_json::Map::new(); |
| 881 | for pair in inner.split(',') { |
| 882 | if let Some((k, v)) = pair.split_once(':') { |
| 883 | map.insert(k.trim().to_string(), yaml_scalar_to_json(v)); |
| 884 | } |
| 885 | } |
| 886 | Some(serde_json::Value::Object(map)) |
| 887 | } |
| 888 | |
| 889 | /// Compute the indentation level (number of leading spaces) of a line. |
| 890 | fn indent_level(line: &str) -> usize { |
no test coverage detected