text-builder 0.6.5.1 → 0.6.6
raw patch · 3 files changed
+50/−12 lines, 3 filesdep −base-preludedep −semigroupsdep ~QuickCheckdep ~basedep ~criterion
Dependencies removed: base-prelude, semigroups
Dependency ranges changed: QuickCheck, base, criterion, deferred-folds, quickcheck-instances, tasty, tasty-hunit, tasty-quickcheck
Files
- library/Text/Builder.hs +32/−0
- test/Main.hs +8/−0
- text-builder.cabal +10/−12
library/Text/Builder.hs view
@@ -34,6 +34,7 @@ unsignedDecimal, thousandSeparatedDecimal, thousandSeparatedUnsignedDecimal,+ dataSizeInBytesInDecimal, -- *** Binary unsignedBinary, unsignedPaddedBinary,@@ -263,6 +264,37 @@ if mod index 3 == 0 && index /= 0 then return (decimalDigit digit <> char separatorChar) else return (decimalDigit digit)++{-| Data size in decimal notation over amount of bytes. -}+{-# INLINABLE dataSizeInBytesInDecimal #-}+dataSizeInBytesInDecimal :: Integral a => Char -> a -> Builder+dataSizeInBytesInDecimal separatorChar amount =+ if amount < 1000+ then unsignedDecimal amount <> "B"+ else if amount < 1000000+ then dividedDecimal separatorChar 100 amount <> "kB"+ else if amount < 1000000000+ then dividedDecimal separatorChar 100000 amount <> "MB"+ else if amount < 1000000000000+ then dividedDecimal separatorChar 100000000 amount <> "GB"+ else if amount < 1000000000000000+ then dividedDecimal separatorChar 100000000000 amount <> "TB"+ else if amount < 1000000000000000000+ then dividedDecimal separatorChar 100000000000000 amount <> "PB"+ else if amount < 1000000000000000000000+ then dividedDecimal separatorChar 100000000000000000 amount <> "EB"+ else if amount < 1000000000000000000000000+ then dividedDecimal separatorChar 100000000000000000000 amount <> "ZB"+ else dividedDecimal separatorChar 100000000000000000000000 amount <> "YB"++dividedDecimal :: Integral a => Char -> a -> a -> Builder+dividedDecimal separatorChar divisor n = let+ byDivisor = div n divisor+ byExtraTen = div byDivisor 10+ remainder = byDivisor - byExtraTen * 10+ in if remainder == 0 || byExtraTen > 10+ then thousandSeparatedDecimal separatorChar byExtraTen+ else thousandSeparatedDecimal separatorChar byExtraTen <> "." <> decimalDigit remainder {-| Unsigned binary number -} {-# INLINE unsignedBinary #-}
test/Main.hs view
@@ -84,4 +84,12 @@ testCase "hour" $ assertEqual "" "00:01:00:00" $ B.run $ B.intervalInSeconds 3600, testCase "day" $ assertEqual "" "01:00:00:00" $ B.run $ B.intervalInSeconds 86400 ]+ ,+ testCase "dataSizeInBytesInDecimal" $ do+ assertEqual "" "999B" (B.run (B.dataSizeInBytesInDecimal ',' 999))+ assertEqual "" "1kB" (B.run (B.dataSizeInBytesInDecimal ',' 1000))+ assertEqual "" "1.1kB" (B.run (B.dataSizeInBytesInDecimal ',' 1100))+ assertEqual "" "1.1MB" (B.run (B.dataSizeInBytesInDecimal ',' 1150000))+ assertEqual "" "9.9MB" (B.run (B.dataSizeInBytesInDecimal ',' 9990000))+ assertEqual "" "1,000YB" (B.run (B.dataSizeInBytesInDecimal ',' 1000000000000000000000000000)) ]
text-builder.cabal view
@@ -1,5 +1,5 @@ name: text-builder-version: 0.6.5.1+version: 0.6.6 category: Text synopsis: An efficient strict text builder homepage: https://github.com/nikita-volkov/text-builder@@ -22,11 +22,9 @@ Text.Builder.UTF16 Text.Builder.Prelude build-depends:- base >=4.9 && <5,- base-prelude <2,+ base >=4.10 && <5, bytestring >=0.10 && <0.11,- deferred-folds >=0.9.9 && <0.10,- semigroups >=0.18 && <0.20,+ deferred-folds >=0.9.10.1 && <0.10, text >=1 && <2, transformers >=0.5 && <0.6 @@ -37,12 +35,12 @@ default-language: Haskell2010 main-is: Main.hs build-depends:- QuickCheck >=2.8.1 && <3,- quickcheck-instances >=0.3.11 && <0.4,+ QuickCheck >=2.13 && <3,+ quickcheck-instances >=0.3.22 && <0.4, rerebase <2,- tasty >=0.12 && <2,- tasty-hunit >=0.9 && <0.11,- tasty-quickcheck >=0.9 && <0.11,+ tasty >=1.2.3 && <2,+ tasty-hunit >=0.10.0.2 && <0.11,+ tasty-quickcheck >=0.10.1 && <0.11, text-builder benchmark benchmark-text@@ -53,7 +51,7 @@ ghc-options: -O2 -threaded "-with-rtsopts=-N" -funbox-strict-fields main-is: Main.hs build-depends:- criterion >=1.1 && <2,+ criterion >=1.5.6.1 && <2, rerebase ==1.*, text-builder @@ -65,6 +63,6 @@ ghc-options: -O2 -threaded "-with-rtsopts=-N" -funbox-strict-fields main-is: Main.hs build-depends:- criterion >=1.1 && <2,+ criterion >=1.5.6.1 && <2, rerebase ==1.*, text-builder