formatYAMLValue formats a value for YAML output, quoting strings and rendering booleans/numbers as unquoted scalars.
(value any)
| 446 | // formatYAMLValue formats a value for YAML output, quoting strings and rendering |
| 447 | // booleans/numbers as unquoted scalars. |
| 448 | func formatYAMLValue(value any) string { |
| 449 | switch v := value.(type) { |
| 450 | case string: |
| 451 | // Quote strings if they contain special characters or look like non-string types |
| 452 | if v == "true" || v == "false" || v == "null" { |
| 453 | return fmt.Sprintf("'%s'", v) |
| 454 | } |
| 455 | // Check if it's a number |
| 456 | if _, err := fmt.Sscanf(v, "%f", new(float64)); err == nil { |
| 457 | return fmt.Sprintf("'%s'", v) |
| 458 | } |
| 459 | // Return as-is for simple strings, quote for complex ones |
| 460 | return fmt.Sprintf("'%s'", v) |
| 461 | case bool: |
| 462 | if v { |
| 463 | return "true" |
| 464 | } |
| 465 | return "false" |
| 466 | case int: |
| 467 | return strconv.Itoa(v) |
| 468 | case int8: |
| 469 | return strconv.Itoa(int(v)) |
| 470 | case int16: |
| 471 | return strconv.Itoa(int(v)) |
| 472 | case int32: |
| 473 | return strconv.Itoa(int(v)) |
| 474 | case int64: |
| 475 | return strconv.FormatInt(v, 10) |
| 476 | case uint: |
| 477 | return strconv.FormatUint(uint64(v), 10) |
| 478 | case uint8: |
| 479 | return strconv.FormatUint(uint64(v), 10) |
| 480 | case uint16: |
| 481 | return strconv.FormatUint(uint64(v), 10) |
| 482 | case uint32: |
| 483 | return strconv.FormatUint(uint64(v), 10) |
| 484 | case uint64: |
| 485 | return strconv.FormatUint(v, 10) |
| 486 | case float32: |
| 487 | return fmt.Sprintf("%v", v) |
| 488 | case float64: |
| 489 | return fmt.Sprintf("%v", v) |
| 490 | default: |
| 491 | // For other types, convert to string and quote |
| 492 | return fmt.Sprintf("'%v'", v) |
| 493 | } |
| 494 | } |
no outgoing calls