text-builder 0.6.6.2 → 0.6.6.3
raw patch · 3 files changed
+25/−1 lines, 3 filesPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
API changes (from Hackage documentation)
+ Text.Builder: doublePercent :: Int -> Double -> Builder
+ Text.Builder: padFromRight :: Int -> Char -> Builder -> Builder
Files
- library/Text/Builder.hs +16/−0
- test/Main.hs +8/−0
- text-builder.cabal +1/−1
library/Text/Builder.hs view
@@ -14,6 +14,7 @@ -- ** Builder manipulators intercalate, padFromLeft,+ padFromRight, -- ** Textual text, string,@@ -46,6 +47,7 @@ hexadecimalDigit, -- ** Real fixedDouble,+ doublePercent, -- ** Time intervalInSeconds, )@@ -355,6 +357,15 @@ then builder else foldMap char (replicate (paddedLength - builderLength) paddingChar) <> builder +{-| Pad a builder from the right side to the specified length with the specified character -}+{-# INLINABLE padFromRight #-}+padFromRight :: Int -> Char -> Builder -> Builder+padFromRight paddedLength paddingChar builder = let+ builderLength = length builder+ in if paddedLength <= builderLength+ then builder+ else builder <> foldMap char (replicate (paddedLength - builderLength) paddingChar)+ {-| Time interval in seconds. Directly applicable to 'DiffTime' and 'NominalDiffTime'.@@ -376,3 +387,8 @@ {-# INLINE fixedDouble #-} fixedDouble :: Int {-^ Amount of decimals after point. -} -> Double -> Builder fixedDouble decimalPlaces = fromString . printf ("%." ++ show decimalPlaces ++ "f")++{-| Double multiplied by 100 with a fixed number of decimal places applied and followed by a percent-sign. -}+{-# INLINE doublePercent #-}+doublePercent :: Int {-^ Amount of decimals after point. -} -> Double -> Builder+doublePercent decimalPlaces x = fixedDouble decimalPlaces (x * 100) <> "%"
test/Main.hs view
@@ -70,6 +70,14 @@ assertEqual "" "12" (B.run (B.padFromLeft 2 '0' "12")) assertEqual "" "123" (B.run (B.padFromLeft 2 '0' "123")) ,+ testCase "Pad from right" $ do+ assertEqual "" "00" (B.run (B.padFromRight 2 '0' ""))+ assertEqual "" "00" (B.run (B.padFromRight 2 '0' "0"))+ assertEqual "" "10" (B.run (B.padFromRight 2 '0' "1"))+ assertEqual "" "12" (B.run (B.padFromRight 2 '0' "12"))+ assertEqual "" "123" (B.run (B.padFromRight 2 '0' "123"))+ assertEqual "" "1 " (B.run (B.padFromRight 3 ' ' "1"))+ , testCase "Hexadecimal" $ assertEqual "" "1f23" (B.run (B.hexadecimal 0x01f23)) ,
text-builder.cabal view
@@ -1,5 +1,5 @@ name: text-builder-version: 0.6.6.2+version: 0.6.6.3 category: Text synopsis: An efficient strict text builder homepage: https://github.com/nikita-volkov/text-builder