Category talk:Wren-fmt: Difference between revisions

→‎Source code: Added Fmt.u method for Unicode codepoint lists. Removed type aliases which are no longer needed.
(→‎Source code: Added a note to slwrite method about printing a literal dollar symbol.)
(→‎Source code: Added Fmt.u method for Unicode codepoint lists. Removed type aliases which are no longer needed.)
Line 299:
// Applies the 's' format to the kind (i.e. type) of 'v'.
static k(w, v) { s(w, v.type) }
 
// Converts a list of Unicode code points to a string and then applies the 's' format to it.
static u(w, v) {
if (!(v is List)) Fiber.abort("Second argument must be list of code points.")
var str = ""
for (c in v) str = str + String.fromCodePoint(c)
return s(w, str)
}
 
// Embeds a string or value 'v' in 'cc', a string with no more than two characters.
Line 512 ⟶ 520:
(fn == "n") ? n(w, v) :
(fn == "k") ? k(w, v) :
(fn == "u") ? u(w, v) :
(fn == "q") ? q(v) :
(fn == "e") ? e(w, v, p) :
Line 603 ⟶ 612:
// $[flag][width][.precision][letter] of which all bracketed items except [letter] are optional.
// The letter must be one of the 'short' methods:
// a, b, c, d, e, E, f, g, h, i, k, m, n, o, q, r, s, t, u, x, X or z.
// 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)
Line 673 ⟶ 682:
var fn = ""
var ds = ""
if ("abcdeEfghikmnoqrstxXzabcdeEfghikmnoqrstuxXz".codePoints.contains(cp)) { // format letter
fn = Conv.itoc(cp)
} else if (cp == 42) { // star
Line 708 ⟶ 717:
 
if (fn == "") {
if (!"abcdeEfghikmnoqrstxXzabcdeEfghikmnoqrstuxXz".codePoints.contains(cp)) {
Fiber.abort("Unrecognized character in format string.")
}
Line 735 ⟶ 744:
if (next < a.count) {
var e = a[next]
if ((e is Sequence) && !(e is String) && fn != "n" && fn != "u") {
if (hash && "btodxX".contains(fn[0])) {
var rr = []
Line 834 ⟶ 843:
static mprint(m, w) { mprint(m, w, precision, "|") }
static mprint(m) { mprint(m, 0, precision, "|") }
}</lang>
}
 
// Type aliases for classes in case of any name clashes with other modules.
var Fmt_Conv = Conv
var Fmt_Fmt = Fmt</lang>
9,492

edits