01: /*
02: * @(#)sprintf.java 1.2 04/12/06
03: *
04: * Copyright (c) 2002-2004 Sun Microsystems, Inc. All Rights Reserved.
05: *
06: * See the file "LICENSE.txt" for information on usage and redistribution
07: * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
08: */
09: package org.pnuts.text;
10:
11: import pnuts.lang.*;
12:
13: public class sprintf extends PnutsFunction {
14:
15: public sprintf() {
16: super ("sprintf");
17: }
18:
19: public boolean defined(int nargs) {
20: return nargs > 0;
21: }
22:
23: protected Object exec(Object[] args, Context context) {
24: int nargs = args.length;
25: if (nargs == 0) {
26: undefined(args, context);
27: return null;
28: }
29: Object[] fargs = new Object[nargs - 1];
30: System.arraycopy(args, 1, fargs, 0, nargs - 1);
31: return new PrintfFormat((String) args[0]).sprintf(fargs);
32: }
33: }
|