/// <summary> /// Exit the Row /// </summary> /// <param name="ctx"></param> public override void ExitRow(otCSVParser.RowContext ctx) { // return if we are leaving a header if (ctx.Parent.RuleIndex == otCSVParser.RULE_header) { // remove last element if this is null if (String.IsNullOrEmpty(_currentRowFieldValues[_currentRowFieldValues.Count - 1])) { _currentRowFieldValues.RemoveAt(_currentRowFieldValues.Count - 1); } return; } // else String[] _row = null; // no _header ? if (_header.Count > 0) { _row = new String [_header.Count]; } int i = 0; // build and add - lose additional fields if we donot have them foreach (string v in _currentRowFieldValues) { // resize if no header if (_header == null && (_row == null || _row.GetUpperBound(0) < i)) { Array.Resize <String>(ref _row, i + 1); } // check array if (_row != null && _row.GetUpperBound(0) >= i) { _row[i] = v; } i++; } // add the row _rows.Add(_row); }
/// <summary> /// enter new row /// </summary> /// <param name="ctx"></param> public override void EnterRow([Antlr4.Runtime.Misc.NotNull] otCSVParser.RowContext context) { _currentRowFieldValues = new List <String>(); }