percent-format: simple printf-style string formatting

[ bsd3, library, testing ] [ Propose Tags ]

The Text.PercentFormat library provides printf-style string formatting. It provides a % operator (as in Ruby or Python) and uses the old C-printf-style format you know and love.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.0.1, 0.0.2, 0.0.4
Dependencies base (>=4 && <5) [details]
License BSD-3-Clause
Author Rudy Matela <rudy@matela.com.br>
Maintainer Rudy Matela <rudy@matela.com.br>
Category Testing
Home page https://github.com/rudymatela/percent-format#readme
Source repo head: git clone https://github.com/rudymatela/percent-format
this: git clone https://github.com/rudymatela/percent-format(tag v0.0.2)
Uploaded by rudymatela at 2021-06-14T17:32:04Z
Distributions LTSHaskell:0.0.4, NixOS:0.0.4, Stackage:0.0.4
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 1236 total (20 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2021-06-14 [all 1 reports]

Readme for percent-format-0.0.2

[back to package description]

PercentFormat -- C-like printf-style string formatting for Haskell

PercentFormat's Build Status PercentFormat on Hackage PercentFormat on Stackage LTS PercentFormat on Stackage Nightly

The Text.PercentFormat library provides printf-style string formatting. It provides a % operator (as in Ruby or Python) and uses the old C-printf-style format you know and love.

This library differs from Text.Printf in that it does not rely on custom typeclasses -- it works on anything that is a Show instance.

Formatting one value:

> import Text.PercentFormat
> "Hello %s!" -% "World"
"Hello World!"

Formatting three values, tuple style, using -%%%:

> "load average: %1.2f %1.2f %1.2f" -%%% (0.00, 0.066, 0.11)
"load average: 0.00 0.07 0.11"

Formatting three values, chain style, using % and -%:

> "load average: %1.2f %1.2f %1.2f" % 0.00 % 0.066 -% 0.11
"load average: 0.00 0.07 0.11"

To produce a string with a percent sign (%), use two percent signs (%%):

> "memory usage: %i%%" -% 13
"memory usage: 13%"

Percent signs are duplicated when using the % operator to allow chaining:

> "percent sign: %s, memory usage: %i%%" % "%" % 87
"percent sign: %%, memory usage: 87%%"

Always use the -% operator when formatting the last value to remove duplicate % signs:

> "percent sign: %s, memory usage: %i%%" % "%" -% 87
"percent sign: %, memory usage: 87%"

To print, just prefix you format expression with putStrLn $:

> putStrLn $ "Hello %s!" -% "World"
Hello World!

For more information and a detailed list of options, see PercentFormat's Haddock Documentation.

PercentFormat is a work in progress. Any help or pull requests are welcome. See PercentFormat's TO DO list for ideas on how to contribute.

Installing

To install the latest PercentFormat version from Hackage, just run:

$ cabal update
$ cabal install percent-format