MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / parse_inline_map

Function parse_inline_map

crates/opencode-config/src/loader.rs:871–887  ·  view source on GitHub ↗

Parse an inline YAML flow mapping like `{a: 1, b: true}` into a JSON object.

(value: &str)

Source from the content-addressed store, hash-verified

869
870/// Parse an inline YAML flow mapping like `{a: 1, b: true}` into a JSON object.
871fn 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.
890fn indent_level(line: &str) -> usize {

Callers 1

parse_yaml_mapping_linesFunction · 0.85

Calls 3

newFunction · 0.85
yaml_scalar_to_jsonFunction · 0.85
is_emptyMethod · 0.80

Tested by

no test coverage detected