01: /*
02: * JoinCmd.java
03: *
04: * Copyright (c) 1997 Cornell University.
05: * Copyright (c) 1997 Sun Microsystems, Inc.
06: *
07: * See the file "license.terms" for information on usage and
08: * redistribution of this file, and for a DISCLAIMER OF ALL
09: * WARRANTIES.
10: *
11: * RCS: @(#) $Id: JoinCmd.java,v 1.1.1.1 1998/10/14 21:09:18 cvsadmin Exp $
12: *
13: */
14:
15: package tcl.lang;
16:
17: /**
18: * This class implements the built-in "join" command in Tcl.
19: */
20: class JoinCmd implements Command {
21:
22: /**
23: * See Tcl user documentation for details.
24: */
25: public void cmdProc(Interp interp, TclObject argv[])
26: throws TclException {
27: String sep = null;
28:
29: if (argv.length == 2) {
30: sep = null;
31: } else if (argv.length == 3) {
32: sep = argv[2].toString();
33: } else {
34: throw new TclNumArgsException(interp, 1, argv,
35: "list ?joinString?");
36: }
37: TclObject list = argv[1];
38: int size = TclList.getLength(interp, list);
39:
40: if (size == 0) {
41: interp.resetResult();
42: return;
43: }
44:
45: StringBuffer sbuf = new StringBuffer(TclList.index(interp,
46: list, 0).toString());
47:
48: for (int i = 1; i < size; i++) {
49: if (sep == null) {
50: sbuf.append(' ');
51: } else {
52: sbuf.append(sep);
53: }
54: sbuf.append(TclList.index(interp, list, i).toString());
55: }
56: interp.setResult(sbuf.toString());
57: }
58: }
|