Category talk:Wren-fmt: Difference between revisions
Content added Content deleted
(→Source code: Several improvements including support for formatting a sequence of values.) |
m (→Source code: Removed some surplus whitespace.) |
||
Line 259: | Line 259: | ||
} |
} |
||
if (len == 0) return (v is String) ? v : "%(v)" |
if (len == 0) return (v is String) ? v : "%(v)" |
||
if (len == 1) cc = cc + cc |
if (len == 1) cc = cc + cc |
||
return "%(cc[0])%(v)%(cc[1])" |
return "%(cc[0])%(v)%(cc[1])" |
||
} |
} |
||
// Convenience version of the above which uses double quotes as the embedding characters. |
// Convenience version of the above which uses double quotes as the embedding characters. |
||
static q(v) { "\"%(v)\"" } |
static q(v) { "\"%(v)\"" } |
||
// Pads a number 'n' with leading spaces to a minimum width 'w' and a precision of 'p' decimal places. |
// Pads a number 'n' with leading spaces to a minimum width 'w' and a precision of 'p' decimal places. |
||
// Precision is restricted to 14 places though entering a higher figure is not an error. |
// Precision is restricted to 14 places though entering a higher figure is not an error. |
||
Line 331: | Line 331: | ||
// Works like 'fc' except replaces any trailing zeros after the decimal point with spaces. |
// Works like 'fc' except replaces any trailing zeros after the decimal point with spaces. |
||
// If the resulting string would end with a decimal point, a zero is first added back. |
// If the resulting string would end with a decimal point, a zero is first added back. |
||
static gc(w, n, p) { |
static gc(w, n, p) { |
||
var f = fc(w, n, p) |
var f = fc(w, n, p) |
||
Line 381: | Line 381: | ||
(fn == "dp") ? dp(w, e) : |
(fn == "dp") ? dp(w, e) : |
||
(fn == "dm") ? dm(w, e) : |
(fn == "dm") ? dm(w, e) : |
||
(fn == "dc") ? dc(w, e) : |
(fn == "dc") ? dc(w, e) : |
||
(fn == "fc") ? fc(w, e, p) : |
(fn == "fc") ? fc(w, e, p) : |
||
(gn == "gc") ? gc(w, e, p) : Fiber.abort("Method not recognized.") |
(gn == "gc") ? gc(w, e, p) : Fiber.abort("Method not recognized.") |
||
l[i] = q(l[i], cc) |
l[i] = q(l[i], cc) |
||
} |
} |
||
return q(l.join(sep), bb) |
return q(l.join(sep), bb) |
||
} |
} |
||
Line 393: | Line 393: | ||
static v(fn, w, seq, p, sep, bb) { v(fn, w, seq, p, sep, bb, "") } |
static v(fn, w, seq, p, sep, bb) { v(fn, w, seq, p, sep, bb, "") } |
||
static v(fn, w, seq, p) { v(fn, w, seq, p, ", ", "[]", "") } |
static v(fn, w, seq, p) { v(fn, w, seq, p, ", ", "[]", "") } |
||
static v(fn, w, seq) { v(fn, w, seq, precision, ", ", "[]", "") } |
static v(fn, w, seq) { v(fn, w, seq, precision, ", ", "[]", "") } |
||
} |
} |
||