percent-format: simple printf-style string formatting

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain]

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]

Properties

Versions0.0.1, 0.0.1
Change logNone available
Dependenciesbase (==4.*) [details]
LicenseBSD-3-Clause
AuthorRudy Matela <rudy@matela.com.br>
MaintainerRudy Matela <rudy@matela.com.br>
CategoryTesting
Home pagehttps://github.com/rudymatela/percent-format#readme
Source repositoryhead: git clone https://github.com/rudymatela/percent-format
this: git clone https://github.com/rudymatela/percent-format(tag v0.0.1)
UploadedTue Jul 31 20:36:40 UTC 2018 by rudymatela

Modules

[Index]

Downloads

Maintainers' corner

For package maintainers and hackage trustees


Readme for percent-format-0.0.1

[back to package description]

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

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:

> "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:

> "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!