Ejemplo n.º 1
0
        public void Format(RCCube source)
        {
            if (source.Count == 0)
            {
                if (_args.Syntax == "RCL")
                {
                    _builder.Append("[]");
                }
                return;
            }
            _names     = new List <string> ();
            _columns   = new List <List <string> > ();
            _max       = new List <int> ();
            _leftAlign = new List <bool> ();
            int  tcols    = 0;
            bool useGRows = false;

            if (source.Axis.Has("G") && _args.Showt)
            {
                _names.Add("G");
                _columns.Add(new List <string> ());
                _max.Add(MIN_WIDTH);
                _leftAlign.Add(false);
                ++tcols;
                useGRows = true;
            }
            if (source.Axis.Has("E") && _args.Showt)
            {
                _names.Add("E");
                _columns.Add(new List <string> ());
                _max.Add(MIN_WIDTH);
                _leftAlign.Add(false);
                ++tcols;
            }
            if (source.Axis.Has("T") && _args.Showt)
            {
                _names.Add("T");
                _columns.Add(new List <string> ());
                _max.Add(MIN_WIDTH);
                _leftAlign.Add(false);
                ++tcols;
            }
            if (source.Axis.Has("S"))
            {
                _names.Add("S");
                _columns.Add(new List <string> ());
                _max.Add(MIN_WIDTH);
                _leftAlign.Add(true);
                ++tcols;
            }
            for (int i = 0; i < source.Cols; ++i)
            {
                string name = source.ColumnAt(i);
                char   type = source.GetTypeCode(name);
                _names.Add(source.NameAt(i));
                _columns.Add(new List <string> ());
                _max.Add(MIN_WIDTH);
                _leftAlign.Add(type == 'y' || type == 's');
            }
            // Populate _columns and _max.
            if (_args.CanonicalCubes)
            {
                source.VisitCellsCanonical(this, 0, source.Axis.Count);
            }
            else
            {
                source.VisitCellsForward(this, 0, source.Axis.Count);
            }
            if (_args.Syntax == "RCL")
            {
                FormatRC(tcols);
            }
            else if (_args.Syntax == "HTML")
            {
                FormatHtml(tcols, useGRows);
            }
            else if (_args.Syntax == "CSV")
            {
                FormatCsv(tcols, useGRows, CSV_ESCAPE_CHARS, true);
            }
            else if (_args.Syntax == "LOG")
            {
                FormatCsv(tcols, useGRows, LOG_ESCAPE_CHARS, false);
            }
            else
            {
                throw new Exception("Unknown syntax for format:" + _args.Syntax);
            }
        }