Category talk:Wren-fmt: Difference between revisions
Content deleted Content added
→Source code: Added 'repeat' format. |
→Source code: Added 'yes/no' format. |
||
Line 367: | Line 367: | ||
// 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)\"" } |
||
// Maps the boolean value 'b' to "yes" if true or "no" if false |
|||
// and then applies the 's' format to the result. |
|||
static y(w, b) { Fmt.s(w, b ? "yes" : "no") } |
|||
// Formats a number 'n' (using 'h' format) to a maximum precision of 14 decimal places. |
// Formats a number 'n' (using 'h' format) to a maximum precision of 14 decimal places. |
||
Line 626: | Line 630: | ||
(fn == "u") ? u(w, v) : |
(fn == "u") ? u(w, v) : |
||
(fn == "q") ? q(v) : |
(fn == "q") ? q(v) : |
||
(fn == "y") ? y(w, v) : |
|||
(fn == "e") ? e(w, v, p) : |
(fn == "e") ? e(w, v, p) : |
||
(fn == "E") ? Fmt.E(w, v, p) : |
(fn == "E") ? Fmt.E(w, v, p) : |
||
Line 752: | Line 757: | ||
// $[flag][width][.precision][letter] of which all bracketed items except [letter] are optional. |
// $[flag][width][.precision][letter] of which all bracketed items except [letter] are optional. |
||
// The letter must be one of the 'short' methods: |
// The letter must be one of the 'short' methods: |
||
// a, b, c, d, e, E, f, F, g, h, i, I, j, k, l, m, n, N, o, O, P, q, r, R, s, S, t, u, x, X or z. |
// a, b, c, d, e, E, f, F, g, h, i, I, j, k, l, m, n, N, o, O, P, q, r, R, s, S, t, u, x, X, y or z. |
||
// If present, the flag (there can only be one) must be one of the following: |
// If present, the flag (there can only be one) must be one of the following: |
||
// + always prints a + or - sign ('dp', 'fp', 'gp' or 'hp' methods) |
// + always prints a + or - sign ('dp', 'fp', 'gp' or 'hp' methods) |
||
Line 822: | Line 827: | ||
var fn = "" |
var fn = "" |
||
var ds = "" |
var ds = "" |
||
if (" |
if ("abcdeEfFghiIjklmnNoOPqrRsStuxXyz".codePoints.contains(cp)) { // format letter |
||
fn = Conv.itoc(cp) |
fn = Conv.itoc(cp) |
||
} else if (cp == 42) { // star |
} else if (cp == 42) { // star |
||
Line 857: | Line 862: | ||
if (fn == "") { |
if (fn == "") { |
||
if (!" |
if (!"abcdeEfFghiIjklmnNoOPqrRsStuxXyz".codePoints.contains(cp)) { |
||
Fiber.abort("Unrecognized character in format string.") |
Fiber.abort("Unrecognized character in format string.") |
||
} |
} |