From 887bf963af2e3b99ddc28f2959d06e26344124ad Mon Sep 17 00:00:00 2001 From: Thomas Roehl Date: Fri, 11 Mar 2022 20:01:18 +0100 Subject: [PATCH] Simplify special cases --- internal/ccUnits/ccUnits.go | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/internal/ccUnits/ccUnits.go b/internal/ccUnits/ccUnits.go index d4eb998..656fa81 100644 --- a/internal/ccUnits/ccUnits.go +++ b/internal/ccUnits/ccUnits.go @@ -96,8 +96,9 @@ func NewUnit(unitStr string) Unit { // Special case for prefix 'p' or 'P' (Peta) and measures starting with 'p' or 'P' // like 'packets' or 'percent'. Same for 'e' or 'E' (Exa) for measures starting with // 'e' or 'E' like 'events' - if m == None && pre == Base { - if strings.ToLower(matches[1]) == "p" || strings.ToLower(matches[1]) == "e" { + if m == None { + switch pre { + case Peta, Exa: t := NewMeasure(matches[1] + measures[0]) if t != None { m = t @@ -111,27 +112,7 @@ func NewUnit(unitStr string) Unit { } // Special case for 'm' as prefix for Bytes as thers is nothing like MilliBytes switch m { - case Bytes: - if pre == Milli { - pre = Mega - } - case Flops: - if pre == Milli { - pre = Mega - } - case Packets: - if pre == Milli { - pre = Mega - } - case Events: - if pre == Milli { - pre = Mega - } - case Cycles: - if pre == Milli { - pre = Mega - } - case Requests: + case Bytes, Flops, Packets, Events, Cycles, Requests: if pre == Milli { pre = Mega }