protected override String8Set SplitCells(String8 row, PartialArray <int> cellPositionArray) { // Remove trailing '\r' to handle '\r\n' and '\n' line endings uniformly if (row.EndsWith(UTF8.CR)) { row = row.Substring(0, row.Length - 1); } return(row.SplitAndDecodeCsvCells(cellPositionArray)); }
public void String8_StartsWithEndsWith() { string collections = "Collections"; String8 collections8 = collections.TestConvert(); string collectionsCasing = "coLLecTionS"; String8 collectionsCasing8 = collectionsCasing.TestConvert(); Assert.IsFalse(String8.Empty.StartsWith(UTF8.Space)); Assert.IsFalse(String8.Empty.EndsWith(UTF8.Space)); Assert.IsTrue(collections8.StartsWith((byte)'C')); Assert.IsFalse(collections8.StartsWith((byte)'c')); Assert.IsFalse(collections8.StartsWith(UTF8.Newline)); Assert.IsTrue(collections8.EndsWith((byte)'s')); Assert.IsFalse(collections8.EndsWith((byte)'S')); Assert.IsFalse(collections8.EndsWith(UTF8.Newline)); Assert.IsFalse(String8.Empty.StartsWith(collections8)); Assert.IsFalse(String8.Empty.EndsWith(collections8)); Assert.IsFalse(String8.Empty.StartsWith(collections8, true)); Assert.IsFalse(String8.Empty.EndsWith(collections8, true)); Assert.IsTrue(collections8.EndsWith(collections8)); Assert.IsTrue(collections8.EndsWith(collections8.Substring(1))); Assert.IsTrue(collections8.EndsWith(collections8.Substring(8))); Assert.IsFalse(collections8.EndsWith(collectionsCasing8)); Assert.IsTrue(collections8.EndsWith(collectionsCasing8, true)); Assert.IsTrue(collections8.StartsWith(collections8)); Assert.IsTrue(collections8.StartsWith(collections8.Substring(0, collections8.Length - 1))); Assert.IsTrue(collections8.StartsWith(collections8.Substring(0, 3))); Assert.IsFalse(collections8.StartsWith(collectionsCasing8)); Assert.IsTrue(collections8.StartsWith(collectionsCasing8, true)); }
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); }