private void ReadColumnLine(String8 line) { // Skip empty lines if (line.Length == 0) { return; } // Skip record separator, continuation lines, comments, and grouping lines byte first = line[0]; if (first == UTF8.CR || first == UTF8.Space || first == UTF8.Pound || first == UTF8.Dash) { return; } // Find the column name part of the line String8 columnName = line.BeforeFirst(UTF8.Colon); // If we haven't seen this column name before, add it to our collection if (!columnName.IsEmpty() && !_columnIndices8.ContainsKey(columnName)) { int columnIndex = _columnIndices8.Count; _columnIndices8[_columnNamesBlock.GetCopy(columnName)] = columnIndex; string columnNameString = columnName.ToString(); _columnNames.Add(columnNameString); _columnIndices[columnNameString] = columnIndex; } }
public void String8_BeforeFirstAfterFirst() { string binaryName = "System.Collections.Generic.List!"; String8 binaryName8 = binaryName.TestConvert(); Assert.AreEqual("System", binaryName8.BeforeFirst((byte)'.').ToString()); Assert.AreEqual("Collections.Generic.List!", binaryName8.AfterFirst((byte)'.').ToString()); Assert.AreEqual(binaryName8, binaryName8.BeforeFirst((byte)'|').ToString()); Assert.AreEqual(binaryName8, binaryName8.AfterFirst((byte)'|').ToString()); Assert.AreEqual(string.Empty, String8.Empty.BeforeFirst((byte)'.').ToString()); Assert.AreEqual(string.Empty, String8.Empty.AfterFirst((byte)'.').ToString()); Assert.AreEqual(string.Empty, String8.Empty.BeforeFirst((byte)'S').ToString()); Assert.AreEqual(string.Empty, String8.Empty.AfterFirst((byte)'!').ToString()); TrySplitOnFirst(String8.Empty, (byte)'.', "", ""); TrySplitOnFirst(binaryName8, (byte)'@', "", ""); TrySplitOnFirst(binaryName8, (byte)'.', "System", "Collections.Generic.List!"); TrySplitOnFirst(binaryName8, (byte)'!', "System.Collections.Generic.List", ""); TrySplitOnFirst(binaryName8, (byte)'S', "", "ystem.Collections.Generic.List!"); }
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); }