{- data size display and parsing
-
- - Copyright 2011-2022 Joey Hess <id@joeyh.name>
+ - Copyright 2011-2024 Joey Hess <id@joeyh.name>
-
- License: BSD-2-clause
-
roughSize,
roughSize',
+ preciseSize,
compareSizes,
readSize
) where
roughSize units short i = copyright $ roughSize' units short 2 i
roughSize' :: [Unit] -> Bool -> Int -> ByteSize -> String
-roughSize' units short precision i
+roughSize' units short = showSize units short . showImprecise
+
+preciseSize :: [Unit] -> Bool -> ByteSize -> String
+preciseSize units short = showSize units short show
+
+showSize :: [Unit] -> Bool -> (Double -> String) -> ByteSize -> String
+showSize units short showdouble i
| i < 0 = '-' : findUnit units' (negate i)
| otherwise = findUnit units' i
where
showUnit x (Unit size abbrev name) = s ++ " " ++ unit
where
v = (fromInteger x :: Double) / fromInteger size
- s = showImprecise precision v
+ s = showdouble v
unit
| short = abbrev
| s == "1" = name