Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge

  • Loading branch information...
commit 2f72ec88ef716edf4e25b6a056115e2c007de747 2 parents d059cd6 + 31dd6d0
@bos authored
View
4 .hgtags
@@ -3,3 +3,7 @@
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
View
2  Data/Text/Buildable.hs
@@ -5,7 +5,7 @@
-- Copyright : (c) 2011 MailRank, Inc.
--
-- License : BSD-style
--- Maintainer : bos@mailrank.com
+-- Maintainer : bos@serpentine.com
-- Stability : experimental
-- Portability : GHC
--
View
28 Data/Text/Format.hs
@@ -1,11 +1,11 @@
-{-# 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
--
@@ -32,6 +32,7 @@ module Data.Text.Format
, expt
, fixed
, prec
+ , shortest
) where
import Control.Monad.IO.Class (MonadIO(liftIO))
@@ -59,16 +60,16 @@ import qualified Data.Text.Lazy.IO as LT
-- | 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
@@ -101,7 +102,7 @@ right :: B.Buildable a => Int -> Char -> a -> Builder
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) =>
@@ -112,7 +113,7 @@ 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
@@ -122,7 +123,7 @@ fixed decs = B.build . C.toFixed decs . realToFrac
{-# 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
@@ -132,7 +133,14 @@ expt decs = B.build . C.toExponential decs . realToFrac
{-# 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
View
2  Data/Text/Format/Functions.hs
@@ -5,7 +5,7 @@
-- Copyright : (c) 2011 MailRank, Inc.
--
-- License : BSD-style
--- Maintainer : bos@mailrank.com
+-- Maintainer : bos@serpentine.com
-- Stability : experimental
-- Portability : GHC
--
View
2  Data/Text/Format/Int.hs
@@ -3,7 +3,7 @@
-- 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
--
View
2  Data/Text/Format/Params.hs
@@ -3,7 +3,7 @@
-- Copyright : (c) 2011 MailRank, Inc.
--
-- License : BSD-style
--- Maintainer : bos@mailrank.com
+-- Maintainer : bos@serpentine.com
-- Stability : experimental
-- Portability : GHC
--
View
2  Data/Text/Format/Types.hs
@@ -5,7 +5,7 @@
-- Copyright : (c) 2011 MailRank, Inc.
--
-- License : BSD-style
--- Maintainer : bos@mailrank.com
+-- Maintainer : bos@serpentine.com
-- Stability : experimental
-- Portability : GHC
--
View
2  Data/Text/Format/Types/Internal.hs
@@ -5,7 +5,7 @@
-- Copyright : (c) 2011 MailRank, Inc.
--
-- License : BSD-style
--- Maintainer : bos@mailrank.com
+-- Maintainer : bos@serpentine.com
-- Stability : experimental
-- Portability : GHC
--
View
8 README.markdown
@@ -9,11 +9,11 @@ We are happy to receive bug reports, fixes, documentation enhancements,
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):
@@ -25,4 +25,4 @@ Authors
-------
This library is written and maintained by Bryan O'Sullivan,
-<bos@mailrank.com>.
+<bos@serpentine.com>.
View
7 benchmarks/Benchmarks.hs
@@ -12,6 +12,10 @@ printf1 f a = P.printf f a
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") ()
@@ -30,6 +34,9 @@ main = defaultMain [
, 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") ()
View
5 benchmarks/Simple.hs
@@ -33,6 +33,10 @@ int count = counting count $ \i x -> do
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
@@ -85,6 +89,7 @@ main = do
("double":_) -> double
("p6":_) -> p6
("int":_) -> int
+ ("bigint":_) -> bigint
("one":_) -> one
("two":_) -> two
("three":_) -> three
View
15 text-format.cabal
@@ -1,12 +1,12 @@
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
@@ -43,7 +43,6 @@ library
base == 4.*,
double-conversion >= 0.2.0.0,
ghc-prim,
- integer-gmp,
old-locale,
text >= 0.11.0.8,
time,
@@ -58,14 +57,14 @@ library
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
Please sign in to comment.
Something went wrong with that request. Please try again.