public DummyData(LineConstructor constructor, Encoding encoding, byte[] separator) { someField = default; extraFields = default; SetFromLineConstructor(constructor, encoding, separator); }
private unsafe void SetFromLineConstructor(LineConstructor constructor, Encoding encoding, byte[] separator) { fixed(byte *from = constructor.buffer) { var start = from; var length = constructor.length; var column = 0; while (true) { var line = new ReadOnlySpan <byte>(start, length); var next = line.IndexOf(separator); if (next == -1) { if (line.IndexOf(Constants.CarriageReturn) > -1) { C = new StringField(start, length - 2, encoding); } else if (line.IndexOf(Constants.LineFeed) > -1) { C = new StringField(start, length - 1, encoding); } else { C = new StringField(start, length, encoding); } break; } var consumed = next + separator.Length; length -= next + separator.Length; switch (column) { case 0: A = new StringField(start, next, encoding); break; case 1: B = new StringField(start, next, encoding); break; case 2: C = new StringField(start, next, encoding); break; default: ExtraFields = ExtraFields.Initialized ? ExtraFields.AddLength(next) : new StringField(start, next, encoding); break; } start += consumed; column++; } } }
public RowLayout(LineConstructor constructor, Encoding encoding, byte[] separator) { A = default; B = default; C = default; ExtraFields = default; SetFromLineConstructor(constructor, encoding, separator); }
public PersonLayout(LineConstructor constructor, Encoding encoding, byte[] separator) { Name = default; Welcome = default; ExtraFields = default; Fields = 0; LineNumber = constructor.lineNumber; SetFromLineConstructor(constructor, encoding, separator); }
public unsafe void SetFromLineConstructor(LineConstructor constructor, Encoding encoding, byte[] separator) { fixed(byte *from = constructor.buffer) { var start = from; var length = constructor.length; var fields = 0; while (true) { var line = new ReadOnlySpan <byte>(start, length); var next = line.IndexOf(separator); if (next == -1) { if (line.IndexOf((byte)'\r') > -1) { length -= 2; } else if (line.IndexOf((byte)'\n') > -1) { length -= 1; } next = length; } var consumed = next + separator.Length; length -= next + separator.Length; switch (fields) { case 0: Name = new StringField(start, next, encoding); break; case 1: Welcome = new StringField(start, next, encoding); break; default: ExtraFields = ExtraFields.Initialized ? ExtraFields.AddLength(next) : new StringField(start, next, encoding); break; } start += consumed; fields++; if (length < 1) { Fields = fields; break; } } } }