/// <summary> /// Move the reader to the next row. This must be called before /// reading the first row. /// </summary> /// <returns>True if another row exists, False if the TSV is out of content</returns> public virtual bool NextRow() { String8 row = _reader.NextRow(); if (row.IsEmpty()) { return(false); } // Split the line into cells _currentRowColumns = SplitCells(row, _cellPositionArray); this.RowCountRead++; // Allocate a set of reusable String8TabularValues to avoid per-cell-value allocation or boxing. if (_valueBoxes == null || _valueBoxes.Length < _currentRowColumns.Count) { _valueBoxes = new String8TabularValue[_currentRowColumns.Count]; for (int i = 0; i < _valueBoxes.Length; ++i) { _valueBoxes[i] = new String8TabularValue(); } } return(true); }
private void ReadColumns(Stream stream) { // Make a reader to split the input on newlines BufferedRowReader reader = new BufferedRowReader(stream, (block, array) => block.Split(UTF8.Newline, array)); // Scan the lines for column names (something before a colon) while (true) { String8 line = reader.NextRow(); if (line.IsEmpty()) { break; } ReadColumnLine(line); } // Reset the stream for the second read stream.Seek(0, SeekOrigin.Begin); }
public bool NextRow() { _currentRowBlock.Clear(); String8 row = _reader.NextRow(); if (row.IsEmpty()) { return(false); } // Clear values for row for (int i = 0; i < _currentRowValues.Length; ++i) { _currentRowValues[i].SetValue(String8.Empty); } // Read available complete lines String8 currentPropertyName = String8.Empty; String8 currentPropertyValue = String8.Empty; bool currentIsBase64 = false; for (; _nextLineIndex < _blockLines.Count; ++_nextLineIndex) { String8 line = _blockLines[_nextLineIndex]; // Skip comment lines and grouping lines if (line.StartsWith(UTF8.Pound) || line.StartsWith(UTF8.Dash)) { continue; } // Trim trailing CR, if found if (line.EndsWith(UTF8.CR)) { line = line.Substring(0, line.Length - 1); } // An empty line or out of lines for the row range if (line.Length == 0 || line.Index >= row.Index + row.Length) { break; } // Look for a wrapped line if (line[0] == UTF8.Space) { // If found, concatenate the value after the space onto the value so far line = line.Substring(1); currentPropertyValue = _currentRowBlock.Concatenate(currentPropertyValue, String8.Empty, line); } else { // Set or Append the value just completed SetColumnValue(currentPropertyName, currentPropertyValue, currentIsBase64); // Split the property name and value [value is after colon and optional space] currentPropertyName = line.BeforeFirst(UTF8.Colon); currentPropertyValue = line.Substring(currentPropertyName.Length + 1); if (currentPropertyValue.StartsWith(UTF8.Space)) { currentPropertyValue = currentPropertyValue.Substring(1); } // Determine if the value is encoded currentIsBase64 = (line[currentPropertyName.Length + 1] == UTF8.Colon); if (currentIsBase64) { currentPropertyValue = currentPropertyValue.Substring(1); } } } // Set the last property value SetColumnValue(currentPropertyName, currentPropertyValue, currentIsBase64); // The next row starts after the row separator line _nextLineIndex++; this.RowCountRead++; return(true); }