StrFormat.jl

Extends StrLiterals.jl with formatting capabilities
Author JuliaString
Popularity
6 Stars
Updated Last
2 Years Ago
Started In
May 2018

StrFormat

contributions welcome

Julia Version Unit Tests Coverage
Julia Latest

The following extra format sequences (see StrLiterals for the full specification) are added:

  • \%<ccc><formatcode>(arguments) is interpolated as a call to cfmt("<cccc><formatcode>",arguments), where <ccc><formatcode> is a C-style format string.

  • \%(arguments) is interpolated as a call to fmt(arguments). This is especially useful when defaults have been set for the type of the first argument.

  • fmt_default!{T}(::Type{T}, syms::Symbol...; kwargs...) sets the defaults for a particular type.

  • fmt_default!(syms::Symbol...; kwargs...) sets the defaults for all types.

Symbols that can currently be used are: :ljust or :left, :rjust or :right, :commas, :zpad or :zeropad, and :ipre or :prefix.

  • reset!{T}(::Type{T}) resets the defaults for a particular type.
  • defaultSpec(x) will return the defaults for the type of x, and
  • defaultSpec{T}(::Type{T}) will return the defaults for the given type.

There is currently support for Python style formatting, although that is a work-in-progress, and I am intending to improve the syntax to make it as close as possible to Python's 3.6 format strings. Currently, the syntax is \{<formatstring>}(expression), however I plan on changing it shortly to \{expression} (equivalent to pyfmt("", expression), and \{expression;formatstring} (equivalent to pyfmt("formatstring", expression).

Used By Packages