gnu.iou
Class format

java.lang.Object
  |
  +--gnu.iou.format

public abstract class format
extends java.lang.Object

Tool parses string with '%format%' replaceable tokens, inserts arguments. Syntax- compatible with cog template (as a subfeature of "cog/build"), but does not interface to cog template features from here.

A "format" directive can optionally index the "argv" with a "%format[idx]%" syntax, where "idx" is an index into "argv". In this case the running "argc" index into "argv" is not incremented.

A "format" directive can optionally apply processing commands to the target string with a "%format(cmd args)%" syntax, where "cmd" is interpreted by the "cmd" function, see "pad" and "col", below.

By default, each instance of a "%format%" directive uses and increments an internal index into the "argv". Each call to the "format" function gets a fresh internal "argv" index, "argc".

Author:
John Pritchard (john@syntelos.org)
See Also:
cmd(gnu.iou.linebuf, int, java.lang.String, java.lang.String, java.lang.String[][], int, int), pad(gnu.iou.linebuf, int, java.lang.String, int, boolean), col(gnu.iou.linebuf, int, java.lang.String, int, int), #format(java.lang.String,java.lang.String[]), #format(java.lang.String,java.lang.String), #format(java.lang.String[][],java.lang.String[]), #format(java.lang.String[][],java.lang.String[],java.lang.String)

Constructor Summary
format()
           
 
Method Summary
static void cmd(linebuf editbuf, int lidx, java.lang.String cmd, java.lang.String target, java.lang.String[][] srcary, int srci, int srcii)
          Interprets format "(cmd args)" functions.
static void col(linebuf editbuf, int lidx, java.lang.String s, int col0, int cwide)
          Wrap string into column using return elements for lines and the ASCII SPACE character for offsetting.
static java.lang.String format(java.lang.String[][] templ_srcary, java.lang.String[] argv)
          Replace instances of "%format%" with elements of "argv".
static java.lang.String format(java.lang.String[][] srcary, java.lang.String[] argv, java.lang.String format_key)
          User format key replaces the default "format" string.
static java.lang.String format(java.lang.String templ_src, java.lang.String arg)
          Format with one argument, creates stringary for you.
static java.lang.String format(java.lang.String templ_src, java.lang.String[] argv)
          General user interface parses src for "%format%" elements.
static void main(java.lang.String[] argv)
          Command line filter tool applies its arguments to the `format'ed input stream.
static void pad(linebuf editbuf, int lidx, java.lang.String s, int len, boolean leftj)
          Pad with space, or truncate to length.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

format

public format()
Method Detail

format

public static java.lang.String format(java.lang.String templ_src,
                                      java.lang.String[] argv)
                               throws java.lang.IllegalArgumentException
General user interface parses src for "%format%" elements.
Parameters:
templ_src - Source to be parsed by 'utl/templ' for "%...%" directives.
argv - Arguments to "%format%" directives (dynamic replacement text).
Throws:
java.lang.IllegalArgumentException - For "%format%" syntax errors, or "argv" array indexing (bounds) errors.

format

public static java.lang.String format(java.lang.String templ_src,
                                      java.lang.String arg)
                               throws java.lang.IllegalArgumentException
Format with one argument, creates stringary for you.

format

public static java.lang.String format(java.lang.String[][] templ_srcary,
                                      java.lang.String[] argv)
                               throws java.lang.IllegalArgumentException
Replace instances of "%format%" with elements of "argv".
Parameters:
srcary - Source parsed by 'utl/templ' for "%...%" directives.
argv - Arguments to "%format%" directives (dynamic replacement text).
Throws:
java.lang.IllegalArgumentException - For "%format%" syntax errors, or "argv" array indexing (bounds) errors.

format

public static java.lang.String format(java.lang.String[][] srcary,
                                      java.lang.String[] argv,
                                      java.lang.String format_key)
                               throws java.lang.IllegalArgumentException
User format key replaces the default "format" string.
Parameters:
srcary - Source parsed by 'utl/templ' for "%...%" directives.
argv - Arguments to format directives (dynamic replacement text).
format_key - Optional string to identify format operators. Default "format".
Throws:
java.lang.IllegalArgumentException - For format syntax errors, or "argv" array indexing (bounds) errors.

cmd

public static final void cmd(linebuf editbuf,
                             int lidx,
                             java.lang.String cmd,
                             java.lang.String target,
                             java.lang.String[][] srcary,
                             int srci,
                             int srcii)
Interprets format "(cmd args)" functions.
Parameters:
editbuf - Buffer to write into
lidx - Buffer line index for this operation
cmd - The "(cmd args)" string
target - The argv element applied to this command
srcary - The full text used in error reporting
srci - The full text primary index used in error reporting
srcii - The full text secondary index used in error reporting
See Also:
pad(gnu.iou.linebuf, int, java.lang.String, int, boolean), col(gnu.iou.linebuf, int, java.lang.String, int, int)

pad

public static final void pad(linebuf editbuf,
                             int lidx,
                             java.lang.String s,
                             int len,
                             boolean leftj)
Pad with space, or truncate to length.
Parameters:
editbuf - Buffer to write into
lidx - Buffer line index for this operation
s - String
len - Length of output
leftj - Left or right justified.
See Also:
cmd(gnu.iou.linebuf, int, java.lang.String, java.lang.String, java.lang.String[][], int, int)

col

public static final void col(linebuf editbuf,
                             int lidx,
                             java.lang.String s,
                             int col0,
                             int cwide)
Wrap string into column using return elements for lines and the ASCII SPACE character for offsetting.
Parameters:
editbuf - Buffer to write column into
lidx - Buffer first- line index.
s - String source to fit into column
col0 - Column specification for first column index
cwide - Column specification for width
See Also:
cmd(gnu.iou.linebuf, int, java.lang.String, java.lang.String, java.lang.String[][], int, int)

main

public static void main(java.lang.String[] argv)
Command line filter tool applies its arguments to the `format'ed input stream.