File: format.js

package info (click to toggle)
gjs 1.86.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,724 kB
  • sloc: cpp: 39,075; javascript: 30,720; ansic: 15,971; sh: 1,759; python: 772; xml: 135; makefile: 40
file content (29 lines) | stat: -rw-r--r-- 970 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
// SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
// SPDX-FileCopyrightText: 2012 Red Hat, Inc.
// SPDX-FileCopyrightText: 2012 Giovanni Campagna <scampa.giovanni@gmail.com>

/* exported format, printf, vprintf */

var {vprintf} = imports._format;

function printf(fmt, ...args) {
    print(vprintf(fmt, args));
}

/*
 * This function is intended to extend the String object and provide a
 * String.format API for string formatting.
 * It has to be set up using String.prototype.format = Format.format;
 * Usage:
 * "somestring %s %d".format('hello', 5);
 * It supports %s, %d, %x and %f.
 * For %f it also supports precisions like "%.2f".format(1.526).
 * All specifiers can be prefixed with a minimum field width, e.g.
 * "%5s".format("foo").
 * Unless the width is prefixed with '0', the formatted string will be padded
 * with spaces.
 */
function format(...args) {
    return vprintf(this, args);
}