module Debug.TimeStats.Internal
( formatIntWithSeparator
) where
formatIntWithSeparator :: Char -> Int -> ShowS
formatIntWithSeparator :: Char -> Int -> ShowS
formatIntWithSeparator Char
sep Int
x0 String
s0 =
if Int
x0 forall a. Ord a => a -> a -> Bool
>= Int
0 then forall {a}. (Show a, Integral a) => a -> ShowS
go Int
x0 String
s0 else Char
'-' forall a. a -> [a] -> [a]
: forall {a}. (Show a, Integral a) => a -> ShowS
go (-Int
x0) String
s0
where
go :: a -> ShowS
go a
x String
s =
let (a
d, a
m) = forall a. Integral a => a -> a -> (a, a)
divMod a
x a
1000
in if a
d forall a. Ord a => a -> a -> Bool
<= a
0 then forall a. Show a => a -> ShowS
shows a
m String
s
else a -> ShowS
go a
d forall a b. (a -> b) -> a -> b
$ Char
sep forall a. a -> [a] -> [a]
: forall {a}. (Ord a, Num a) => a -> String
pad999 a
m forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> ShowS
shows a
m String
s
pad999 :: a -> String
pad999 a
m
| a
m forall a. Ord a => a -> a -> Bool
< a
10 = String
"00"
| a
m forall a. Ord a => a -> a -> Bool
< a
100 = String
"0"
| Bool
otherwise = String
""