package engine import ( "fmt" "strings" ) // ParseKeyValueFormat parses key:value format from text // Each line should be "key:value" or "key: value" (whitespace trimmed) // If skipComments=true, lines starting with # are ignored // Empty lines are always skipped func ParseKeyValueFormat(data string, skipComments bool) (map[string]string, error) { fields := make(map[string]string) lines := strings.Split(data, "\n") for i, line := range lines { // Trim whitespace line = strings.TrimSpace(line) // Skip empty lines if line == "" { continue } // Skip comments if requested if skipComments && strings.HasPrefix(line, "#") { continue } // Split on first ':' parts := strings.SplitN(line, ":", 2) if len(parts) != 2 { return nil, fmt.Errorf("line %d: invalid format (expected 'key:value')", i+1) } key := strings.TrimSpace(parts[0]) value := strings.TrimSpace(parts[1]) fields[key] = value } return fields, nil }