Files
joakim 9973631df0 refactor: deduplicate engine internals, replace bubble sorts, remove dead code
Extract shared code that was duplicated across functions:
- taskJSON struct (MarshalJSON/UnmarshalJSON) to package-level type
- scanTask(scanner) helper for GetTask/GetTasks (~70 identical lines)
- monthNames map for parseMonthName/parseDayAndMonth
- applyNonDateAttribute helper for Apply/ApplyToNew
- resolveDisplayID calls replace inline loops in FormatTaskListWithFormat

Replace O(n²) bubble sorts with sort.Slice in all four report sort
functions (sortByUrgency, NewestReport, NextReport, OldestReport).

Remove dead code: formatTimeWithColor (unused, also used time.Now()
instead of timeNow()), getCurrentTimestamp (unnecessary wrapper).

Remove ~20 comments that restated the next line of code.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-21 01:46:46 +01:00

40 lines
868 B
Go

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 {
line = strings.TrimSpace(line)
if line == "" {
continue
}
if skipComments && strings.HasPrefix(line, "#") {
continue
}
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
}