/* * SplitCmd.java * * Copyright (c) 1997 Sun Microsystems, Inc. * * See the file "license.terms" for information on usage and * redistribution of this file, and for a DISCLAIMER OF ALL * WARRANTIES. * * RCS: @(#) $Id: SplitCmd.java,v 1.1.1.1 1998/10/14 21:09:19 cvsadmin Exp $ * */ package tcl.lang; /** * This class implements the built-in "split" command in Tcl. */ class SplitCmd implements Command { /** * Default characters for splitting up strings. */ private static char defSplitChars[] = {' ', '\n', '\t', '\r'}; /** * This procedure is invoked to process the "split" Tcl * command. See Tcl user documentation for details. * * @param interp the current interpreter. * @param argv command arguments. * @exception TclException If incorrect number of arguments. */ public void cmdProc(Interp interp, TclObject argv[]) throws TclException { char splitChars[] = null; String string; if (argv.length == 2) { splitChars = defSplitChars; } else if (argv.length == 3) { splitChars = argv[2].toString().toCharArray(); } else { throw new TclNumArgsException(interp, 1, argv, "string ?splitChars?"); } string = argv[1].toString(); int len = string.length(); int num = splitChars.length; /* * Handle the special case of splitting on every character. */ if (num == 0) { TclObject list = TclList.newInstance(); list.preserve(); try { for (int i=0; i