tcl.lang.cmd
Class FormatCmd

java.lang.Object
  extended by tcl.lang.cmd.FormatCmd
All Implemented Interfaces:
Command

public class FormatCmd
extends Object
implements Command

This class implements the built-in "format" command in Tcl.


Constructor Summary
FormatCmd()
           
 
Method Summary
 void cmdProc(Interp interp, TclObject[] argv)
          This procedure is invoked to process the "format" Tcl command.
static String toString(double dblValue, int precision, int base)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FormatCmd

public FormatCmd()
Method Detail

cmdProc

public void cmdProc(Interp interp,
                    TclObject[] argv)
             throws TclException
This procedure is invoked to process the "format" Tcl command. See the user documentation for details on what it does. The first argument to the cmdProc is the formatString. The cmdProc simply copies all the chars into the sbuf until a '%' is found. At this point the cmdProc parces the formatString and determines the format parameters. The parcing of the formatString can be broken into six possible phases: Phase 0 - Simply Print: If the next char is % Phase 1 - XPG3 Position Specifier: If the format [1-n]$ is used Phase 2 - A Set of Flags: One or more of the following + - [space] 0 # Phase 3 - A Minimun Field Width Either [integer] or * Phase 4 - A Precision If the format .[integer] or .* Phase 5 - A Length Modifier If h is present Phase 6 - A Conversion Character If one of the following is used d u i o x X c s f E g G Any phase can skip ahead one or more phases, but are not allowed to move back to previous phases. Once the parameters are determined the cmdProc calls one of three private methods that returns a fully formatted string. This loop occurs for ever '%' in the formatString.

Specified by:
cmdProc in interface Command
Parameters:
interp - The interpreter for setting the results and which contains the context
argv - the argument list for the command; objv[0[ is the command name itself
Throws:
TclException - on any errors

toString

public static String toString(double dblValue,
                              int precision,
                              int base)


Copyright © 2015. All rights reserved.