Commits

Bryan O'Sullivan  committed 5f5e58a Merge

Merge

  • Participants
  • Parent commits 99a5d7f, 7ef7f15

Comments (0)

Files changed (12)

 45d4878cb327b4f18c7ea39036b458ba1f78ca40 0.2.1.0
 d9b6162ca74f0f993b01745e700ce601c1fe0e0a 0.3.0.0
 afc1e224abef9063d95380bf5bea28a349cef2fc 0.3.0.2
+6679f1e108bb5306e782acbd5edc00b5c742b598 0.3.0.3
+2e98bdbb4d6c7578973bef024a3ab369462928d9 0.3.0.4
+9bd748faa46d5b1f9792e980204ef689dfef381e 0.3.0.5
+69d3bef4f0e9ee5f37b821887f545f5b61d73bb0 0.3.0.6

File Data/Text/Buildable.hs

 -- Copyright   : (c) 2011 MailRank, Inc.
 --
 -- License     : BSD-style
--- Maintainer  : bos@mailrank.com
+-- Maintainer  : bos@serpentine.com
 -- Stability   : experimental
 -- Portability : GHC
 --

File Data/Text/Format.hs

-{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE OverloadedStrings, RelaxedPolyRec #-}
 
 -- |
 -- Module      : Data.Text.Format
 -- Copyright   : (c) 2011 MailRank, Inc.
 --
 -- License     : BSD-style
--- Maintainer  : bos@mailrank.com
+-- Maintainer  : bos@serpentine.com
 -- Stability   : experimental
 -- Portability : GHC
 --
     , expt
     , fixed
     , prec
+    , shortest
     ) where
 
 import Control.Monad.IO.Class (MonadIO(liftIO))
 
 -- | Render a format string and arguments to a 'Builder'.
 build :: Params ps => Format -> ps -> Builder
-build fmt ps = zipParams fmt (crack fmt) (buildParams ps)
+build fmt ps = zipParams (crack fmt) (buildParams ps)
 {-# INLINE build #-}
 
-zipParams :: Format -> [Builder] -> [Builder] -> Builder
-zipParams fmt xs = go xs
+zipParams :: [Builder] -> [Builder] -> Builder
+zipParams fragments params = go fragments params
   where go (f:fs) (y:ys) = f <> y <> go fs ys
         go [f] []        = f
         go _ _ = error . LT.unpack $ format
                  "Data.Text.Format.build: {} sites, but {} parameters"
-                 (ST.count "{}" (fromFormat fmt), length xs)
+                 (length fragments - 1, length params)
 
 crack :: Format -> [Builder]
 crack = map fromText . ST.splitOn "{}" . fromFormat
 right k c =
     fromLazyText . LT.justifyLeft (fromIntegral k) c . toLazyText . B.build
 
--- ^ Render a floating point number, with the given number of digits
+-- | Render a floating point number, with the given number of digits
 -- of precision.  Uses decimal notation for values between @0.1@ and
 -- @9,999,999@, and scientific notation otherwise.
 prec :: (Real a) =>
     forall d x. prec d (x::Double) = B.build (C.toPrecision d x) #-}
 prec digits = B.build . C.toPrecision digits . realToFrac
 
--- ^ Render a floating point number using normal notation, with the
+-- | Render a floating point number using normal notation, with the
 -- given number of decimal places.
 fixed :: (Real a) =>
          Int
 {-# RULES "fixed/Double"
     forall d x. fixed d (x::Double) = B.build (C.toFixed d x) #-}
 
--- ^ Render a floating point number using scientific/engineering
+-- | Render a floating point number using scientific/engineering
 -- notation (e.g. @2.3e123@), with the given number of decimal places.
 expt :: (Real a) =>
         Int
 {-# RULES "expt/Double"
     forall d x. expt d (x::Double) = B.build (C.toExponential d x) #-}
 
--- ^ Render an integer using hexadecimal notation.  (No leading "0x"
+-- | Render a floating point number using the smallest number of
+-- digits that correctly represent it.
+shortest :: (Real a) => a -> Builder
+shortest = B.build . C.toShortest . realToFrac
+{-# RULES "shortest/Double"
+    forall x. shortest (x::Double) = B.build (C.toShortest x) #-}
+
+-- | Render an integer using hexadecimal notation.  (No leading "0x"
 -- is added.)
 hex :: Integral a => a -> Builder
 hex = B.build . Hex

File Data/Text/Format/Functions.hs

 -- Copyright   : (c) 2011 MailRank, Inc.
 --
 -- License     : BSD-style
--- Maintainer  : bos@mailrank.com
+-- Maintainer  : bos@serpentine.com
 -- Stability   : experimental
 -- Portability : GHC
 --

File Data/Text/Format/Int.hs

 -- Module:      Data.Text.Format.Int
 -- Copyright:   (c) 2011 MailRank, Inc.
 -- License:     BSD3
--- Maintainer:  Bryan O'Sullivan <bos@mailrank.com>
+-- Maintainer:  Bryan O'Sullivan <bos@serpentine.com>
 -- Stability:   experimental
 -- Portability: portable
 --

File Data/Text/Format/Params.hs

 -- Copyright   : (c) 2011 MailRank, Inc.
 --
 -- License     : BSD-style
--- Maintainer  : bos@mailrank.com
+-- Maintainer  : bos@serpentine.com
 -- Stability   : experimental
 -- Portability : GHC
 --

File Data/Text/Format/Types.hs

 -- Copyright   : (c) 2011 MailRank, Inc.
 --
 -- License     : BSD-style
--- Maintainer  : bos@mailrank.com
+-- Maintainer  : bos@serpentine.com
 -- Stability   : experimental
 -- Portability : GHC
 --

File Data/Text/Format/Types/Internal.hs

 -- Copyright   : (c) 2011 MailRank, Inc.
 --
 -- License     : BSD-style
--- Maintainer  : bos@mailrank.com
+-- Maintainer  : bos@serpentine.com
 -- Stability   : experimental
 -- Portability : GHC
 --

File README.markdown

 and other improvements.
 
 Please report bugs via the
-[github issue tracker](https://github.com/mailrank/text-format/issues).
+[github issue tracker](https://github.com/bos/text-format/issues).
 
-Master [git repository](https://github.com/mailrank/text-format):
+Master [git repository](https://github.com/bos/text-format):
 
-* `git clone git://github.com/mailrank/text-format.git`
+* `git clone git://github.com/bos/text-format.git`
 
 There's also a [Mercurial mirror](https://bitbucket.org/bos/text-format):
 
 -------
 
 This library is written and maintained by Bryan O'Sullivan,
-<bos@mailrank.com>.
+<bos@serpentine.com>.

File benchmarks/Benchmarks.hs

 printf2 :: (P.PrintfArg a, P.PrintfArg b) => String -> (a,b) -> String
 printf2 f (a,b) = P.printf f a b
 
+printf3 :: (P.PrintfArg a, P.PrintfArg b, P.PrintfArg c) =>
+           String -> (a,b,c) -> String
+printf3 f (a,b,c) = P.printf f a b c
+
 main = defaultMain [
          bgroup "arity" [
            bench "0" $ nf (format "hi") ()
          , bench "format2" $ nf (format "hi mom {} {}\n") (pi::Double, "yeah"::T.Text)
          , bench "printf2" $ nf (printf2 "hi mom %f %s\n") (pi::Double, "yeah"::String)
          , bench "show2" $ nf (\(d,s) -> "hi mom " ++ show d ++ " " ++ show s ++ "\n") (pi::Double, "yeah"::String)
+         , bench "format3" $ nf (format "hi mom {} {} {}\n") (pi::Double, "yeah"::T.Text, 21212121::Int)
+         , bench "printf3" $ nf (printf3 "hi mom %f %s %d\n") (pi::Double, "yeah"::String, 21212121::Int)
+         , bench "show3" $ nf (\(d,s,i) -> "hi mom " ++ show d ++ " " ++ show s ++ "\n") (pi::Double, "yeah"::String, 21212121::Int)
          ]
        , bgroup "types" [
            bench "unit" $ nf (format "hi") ()

File benchmarks/Simple.hs

   let t = T.format "hi mom {}\n" (Only i)
   L.putStr . encodeUtf8 $ t
 
+bigint count = counting count $ \i x -> do
+  let t = T.format "hi mom {}\n" (Only (i+100000))
+  L.putStr . encodeUtf8 $ t
+
 double count = counting count $ \i x -> do
   let t = T.format "hi mom {}\n" (Only (fromIntegral i * dpi))
   L.putStr . encodeUtf8 $ t
              ("double":_) -> double
              ("p6":_) -> p6
              ("int":_)    -> int
+             ("bigint":_) -> bigint
              ("one":_)    -> one
              ("two":_)    -> two
              ("three":_)  -> three

File text-format.cabal

 name:           text-format
-version:        0.3.0.2
+version:        0.3.0.6
 license:        BSD3
 license-file:   LICENSE
-homepage:       https://github.com/mailrank/text-format
-bug-reports:    https://github.com/mailrank/text-format/issues
+homepage:       https://github.com/bos/text-format
+bug-reports:    https://github.com/bos/text-format/issues
 category:       Text
-author:         Bryan O'Sullivan <bos@mailrank.com>
-maintainer:     Bryan O'Sullivan <bos@mailrank.com>
+author:         Bryan O'Sullivan <bos@serpentine.com>
+maintainer:     Bryan O'Sullivan <bos@serpentine.com>
 stability:      experimental
 tested-with:    GHC == 7.0.3
 synopsis:       Text formatting
     base == 4.*,
     double-conversion >= 0.2.0.0,
     ghc-prim,
-    integer-gmp,
     old-locale,
     text >= 0.11.0.8,
     time,
   cpp-options: -DINTEGER_GMP
 
   if impl(ghc >= 6.11)
-    build-depends: integer-gmp >= 0.2 && < 0.3
+    build-depends: integer-gmp >= 0.2 && < 0.4
 
   if impl(ghc >= 6.9) && impl(ghc < 6.11)
     build-depends: integer >= 0.1 && < 0.2
 
 source-repository head
   type:     git
-  location: https://github.com/mailrank/text-format
+  location: https://github.com/bos/text-format
 
 source-repository head
   type:     mercurial