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

Function yaml_scalar_to_json

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

Parse a YAML scalar value string into a JSON value.

(value: &str)

Source from the content-addressed store, hash-verified

818
819/// Parse a YAML scalar value string into a JSON value.
820fn yaml_scalar_to_json(value: &str) -> serde_json::Value {
821 let value = value.trim();
822 if value.is_empty() {
823 return serde_json::Value::Null;
824 }
825 // Booleans
826 if value == "true" || value == "True" || value == "TRUE" {
827 return serde_json::Value::Bool(true);
828 }
829 if value == "false" || value == "False" || value == "FALSE" {
830 return serde_json::Value::Bool(false);
831 }
832 if value == "null" || value == "Null" || value == "NULL" || value == "~" {
833 return serde_json::Value::Null;
834 }
835 // Numbers
836 if let Ok(n) = value.parse::<i64>() {
837 return serde_json::Value::Number(n.into());
838 }
839 if let Ok(n) = value.parse::<f64>() {
840 if let Some(num) = serde_json::Number::from_f64(n) {
841 return serde_json::Value::Number(num);
842 }
843 }
844 // Strip surrounding quotes
845 if (value.starts_with('"') && value.ends_with('"'))
846 || (value.starts_with('\'') && value.ends_with('\''))
847 {
848 return serde_json::Value::String(value[1..value.len() - 1].to_string());
849 }
850 serde_json::Value::String(value.to_string())
851}
852
853/// Parse an inline YAML flow sequence like `[a, b, c]` into a JSON array.
854fn parse_inline_list(value: &str) -> Option<serde_json::Value> {

Callers 4

parse_inline_listFunction · 0.85
parse_inline_mapFunction · 0.85
parse_yaml_mapping_linesFunction · 0.85
parse_yaml_list_linesFunction · 0.85

Calls 1

is_emptyMethod · 0.80

Tested by

no test coverage detected