pike.git / lib / modules / ADT.pmod / Table.pmod

version» Context lines:

pike.git/lib/modules/ADT.pmod/Table.pmod:1:   // Table.pmod by Fredrik Noring, 1998 - // $Id: Table.pmod,v 1.24 2002/09/21 15:08:31 mast Exp $ + // $Id: Table.pmod,v 1.25 2002/10/12 12:10:40 grubba Exp $      #pike __REAL_VERSION__   #define TABLE_ERR(msg) error("(Table) "+msg+"\n")      //! ADT.Table is a generic module for manipulating tables.   //!   //! Each table contains one or several columns.   //! Each column is associated with a name, the column name.   //! Optionally, one can provide a column type. The Table module can do a number   //! of operations on a given table, like computing the sum of a column,
pike.git/lib/modules/ADT.pmod/Table.pmod:453:    //! This method returns a table represented in ASCII suitable for human eyes.    //! @[options] is an optional mapping. If the keyword @tt{"indent"@} is used    //! with a number, the table will be indented with that number of space    //! characters.       string encode(object t, void|mapping options)    {    options = options || ([]);    mapping sizes = ([]);    array fields = indices(t); -  string indent = String.strmult(" ", options->indent); +  string indent = " " * options->indent;       t = t->copy(({ fields }) + values(t));    for(int field = 0; field < sizeof(fields); field++)    t = (t->map(lambda(mixed m, int field, mapping sizes)    {    m = (string)m;    sizes[field] = max(sizeof(m), sizes[field]);    return m;    },    field, field, sizes)->    map(lambda(string s, string size, int num)    {    return sprintf("%"+(num?"":"-")+size+"s", s);    },    field, (string)sizes[field],    (t->type(field)||([]))->type == "num"));       string l = (indent+"-"+    Array.map(values(sizes),    lambda(int n) -  { return String.strmult("-", n); })*"---"+"-"); +  { return "-" * n; })*"---"+"-");    array table = values(t);    return (indent+" "+table[0]*" "+"\n"+l+"\n"+    Array.map(table[1..], lambda(array row, string indent)    { return indent+" "+row*" "; },    indent)*"\n"+(sizeof(table)>1?"\n":"")+l+"\n");    }   //! @ignore   }();   //! @endignore