diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-23 23:58:50 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-23 23:58:50 +0300 |
| commit | cb2668bc57fb205fbd44b77695d36d019a7e1054 (patch) | |
| tree | 2cf14216148eb5ac08274d8a7e5b4e13e77004ce | |
| parent | cd74d811d257d5579fbe974abbd6ad39a751d508 (diff) | |
docs(internal/perc): fix misleading comments in perc.go
- ParsingStrategy: clarify that (nil, false, nil) means input not
matched, not that an error occurred. Errors only happen when the
pattern matches but value parsing fails.
- ParseCalculation: remove mention of "formatting options" since
callers get raw values and the Format() method, not configurable
formatting.
| -rw-r--r-- | internal/perc/perc.go | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/internal/perc/perc.go b/internal/perc/perc.go index 63a171e..4f5056f 100644 --- a/internal/perc/perc.go +++ b/internal/perc/perc.go @@ -51,7 +51,8 @@ func (c *Calculation) Format() string { } // ParsingStrategy represents a parsing function that attempts to parse input. -// Returns a Calculation if handled, or error if not. +// Returns (calc, true, nil) on success, (nil, true, err) if the pattern matched +// but value parsing failed, or (nil, false, nil) if the input did not match. type ParsingStrategy func(input string) (*Calculation, bool, error) // strategyRegistry maintains a registry of parsing strategies. @@ -108,7 +109,7 @@ func Parse(input string) (string, error) { // ParseCalculation parses a percentage calculation input string and returns the Calculation object. // It handles formats like "20% of 150", "30 is what % of 150", and "30 is 20% of what". -// This provides callers with more flexibility to access raw values and formatting options. +// This provides callers with access to the raw values and calculation type. func ParseCalculation(input string) (*Calculation, error) { input = strings.ToLower(strings.TrimSpace(input)) input = strings.ReplaceAll(input, "what is ", "") |
