01: /*
02: * @(#)string.java 1.2 04/12/06
03: *
04: * Copyright (c) 1997-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.lib;
10:
11: import pnuts.lang.*;
12:
13: /*
14: * function string(obj)
15: */
16: public class string extends PnutsFunction {
17:
18: public string() {
19: super ("string");
20: }
21:
22: public boolean defined(int narg) {
23: return (narg == 1);
24: }
25:
26: protected Object exec(Object[] args, Context context) {
27: if (args.length == 1) {
28: Object arg = args[0];
29: if (arg == null) {
30: return "";
31: } else {
32: return String.valueOf(arg);
33: }
34: } else {
35: undefined(args, context);
36: return null;
37: }
38: }
39:
40: public String toString() {
41: return "function string(obj)";
42: }
43: }
|