Esempio n. 1
0
        public override void ExitRow([NotNull] CSVParser.RowContext context)
        {
            //skip header
            if (context.col == 0)
            {
                return;
            }

            index++;

            var separator = context.children.Count(x => x.GetText().Equals(";"));

            //riga vuota
            if (context.fields == 0)
            {
                LogRows.Add(new KeyValuePair <int, string>(index, "Riga vuota"));
                r.Delete(context.start, context.stop);
            }
            //separatori in eccesso a fine riga
            else if (separator >= context.fields)
            {
                LogRows.Add(new KeyValuePair <int, string>(index, "Separatori in eccesso alla fine della riga"));

                //cancello i separatori in eccesso alla fine della riga
                for (int i = context.fields; i <= separator; i++)
                {
                    r.Delete(context.SEP(i - 1).Symbol);
                }
            }
            else if (separator < context.col - 1)
            {
                shortRows = true;
                LogRows.Add(new KeyValuePair <int, string>(index, "Riga troppo corta"));
            }
        }
Esempio n. 2
0
 public override void EnterRow(CSVParser.RowContext context)
 {
     if (_isHeader)
     {
         return;
     }
     Records.Add(new Dictionary <string, string>());
 }
Esempio n. 3
0
        public override ParserNode VisitRow(CSVParser.RowContext context)
        {
            var node = GetNode(context, ROW, ParserNode.ParserNavigationTypeEnum.FirstChild);

            if (node.Start == node.End)
            {
                return(null);
            }
            foreach (var cell in context.cell())
            {
                Visit(cell).Parent = node;
            }
            return(node);
        }
Esempio n. 4
0
        public DataItem VisitRow(List <string> names, CSVParser.RowContext context)
        {
            DataObject item = new DataObject();

            if (names.Count != context.field().Length)
            {
                throw new Exception("Wrong number of elements");
            }

            for (int a = 0; a < names.Count; a++)
            {
                item.AddField(names[a], new DataValue()
                {
                    Text = CleanField(context.field()[a].GetText())
                });
            }

            return(item);
        }
Esempio n. 5
0
 /// <summary>
 /// Exit a parse tree produced by <see cref="CSVParser.row"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitRow([NotNull] CSVParser.RowContext context)
 {
 }