Category talk:Wren-fmt: Difference between revisions

Content added Content deleted
m (→‎Source code: Change to comment.)
(→‎Source code: Added 'repeat' format.)
Line 421: Line 421:
// two or three element list. Forms the plural by just adding "s" to l[1] if 'l' is a two element list.
// two or three element list. Forms the plural by just adding "s" to l[1] if 'l' is a two element list.
static P(w, l) { s(w, Conv.plural(l[0], l[1], l.count == 2 ? l[1] + "s" : l[2])) }
static P(w, l) { s(w, Conv.plural(l[0], l[1], l.count == 2 ? l[1] + "s" : l[2])) }

// Repeats 'v', a string or value, 'n' times.
static R(n, v) { (v is String) ? v * n : v.toString * n }

// 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 631: Line 634:
(fn == "F") ? Fmt.F(w, v) :
(fn == "F") ? Fmt.F(w, v) :
(fn == "P") ? Fmt.P(w, v) :
(fn == "P") ? Fmt.P(w, v) :
(fn == "R") ? Fmt.R(w, v) :
(fn == "f") ? f(w, v, p) :
(fn == "f") ? f(w, v, p) :
(fn == "g") ? g(w, v, p) :
(fn == "g") ? g(w, v, p) :
Line 748: Line 752:
// $[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, 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 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 818: Line 822:
var fn = ""
var fn = ""
var ds = ""
var ds = ""
if ("abcdeEfFghiIjklmnNoOPqrsStuxXz".codePoints.contains(cp)) { // format letter
if ("abcdeEfFghiIjklmnNoOPqrRsStuxXz".codePoints.contains(cp)) { // format letter
fn = Conv.itoc(cp)
fn = Conv.itoc(cp)
} else if (cp == 42) { // star
} else if (cp == 42) { // star
Line 853: Line 857:


if (fn == "") {
if (fn == "") {
if (!"abcdeEfFghiIjklmnNoOPqrsStuxXz".codePoints.contains(cp)) {
if (!"abcdeEfFghiIjklmnNoOPqrRsStuxXz".codePoints.contains(cp)) {
Fiber.abort("Unrecognized character in format string.")
Fiber.abort("Unrecognized character in format string.")
}
}
Line 882: Line 886:
if (next < a.count) {
if (next < a.count) {
var e = a[next]
var e = a[next]
if ((e is Sequence) && !(e is String) && !"nuFP".contains(fn)) {
if ((e is Sequence) && !(e is String) && !"nuFPR".contains(fn)) {
if (hash && "btodxX".contains(fn[0])) {
if (hash && "btodxX".contains(fn[0])) {
var rr = []
var rr = []