-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from sveinungf/dev/array-of-value-writers
Get cell value writers from indexing into a static array
- Loading branch information
Showing
10 changed files
with
98 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace SpreadCheetah.CellValueWriters; | ||
|
||
internal enum CellWriterType : byte | ||
{ | ||
Null, | ||
Integer, | ||
Float, | ||
Double, | ||
DateTime, | ||
NullDateTime, | ||
TrueBoolean, | ||
FalseBoolean, | ||
String | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,43 @@ | ||
using SpreadCheetah.CellValueWriters; | ||
using SpreadCheetah.Styling.Internal; | ||
|
||
namespace SpreadCheetah.CellWriters; | ||
|
||
internal sealed class CellWriter(CellWriterState state, DefaultStyling? defaultStyling) | ||
: BaseCellWriter<Cell>(state, defaultStyling) | ||
{ | ||
protected override bool TryWriteCell(in Cell cell) => cell switch | ||
protected override bool TryWriteCell(in Cell cell) | ||
{ | ||
{ Formula: { } formula } => cell.DataCell.Writer.TryWriteCell(formula.FormulaText, cell.DataCell, cell.StyleId, DefaultStyling, Buffer), | ||
{ StyleId: not null } => cell.DataCell.Writer.TryWriteCell(cell.DataCell, cell.StyleId, Buffer), | ||
_ => cell.DataCell.Writer.TryWriteCell(cell.DataCell, DefaultStyling, Buffer) | ||
}; | ||
var writer = CellValueWriter.GetWriter(cell.DataCell.Type); | ||
return cell switch | ||
{ | ||
{ Formula: { } formula } => writer.TryWriteCell(formula.FormulaText, cell.DataCell, cell.StyleId, DefaultStyling, Buffer), | ||
{ StyleId: not null } => writer.TryWriteCell(cell.DataCell, cell.StyleId, Buffer), | ||
_ => writer.TryWriteCell(cell.DataCell, DefaultStyling, Buffer) | ||
}; | ||
} | ||
|
||
protected override bool WriteStartElement(in Cell cell) => cell switch | ||
protected override bool WriteStartElement(in Cell cell) | ||
{ | ||
{ Formula: not null } => cell.DataCell.Writer.WriteFormulaStartElement(cell.StyleId, DefaultStyling, Buffer), | ||
{ StyleId: not null } => cell.DataCell.Writer.WriteStartElement(cell.StyleId, Buffer), | ||
_ => cell.DataCell.Writer.WriteStartElement(Buffer) | ||
}; | ||
var writer = CellValueWriter.GetWriter(cell.DataCell.Type); | ||
return cell switch | ||
{ | ||
{ Formula: not null } => writer.WriteFormulaStartElement(cell.StyleId, DefaultStyling, Buffer), | ||
{ StyleId: not null } => writer.WriteStartElement(cell.StyleId, Buffer), | ||
_ => writer.WriteStartElement(Buffer) | ||
}; | ||
} | ||
|
||
protected override bool TryWriteEndElement(in Cell cell) | ||
{ | ||
return cell.DataCell.Writer.TryWriteEndElement(cell, Buffer); | ||
var writer = CellValueWriter.GetWriter(cell.DataCell.Type); | ||
return writer.TryWriteEndElement(cell, Buffer); | ||
} | ||
|
||
protected override bool FinishWritingCellValue(in Cell cell, ref int cellValueIndex) | ||
{ | ||
return cell.Formula is { } formula | ||
? FinishWritingFormulaCellValue(cell, formula.FormulaText, ref cellValueIndex) | ||
: cell.DataCell.Writer.WriteValuePieceByPiece(cell.DataCell, Buffer, ref cellValueIndex); | ||
: CellValueWriter.GetWriter(cell.DataCell.Type).WriteValuePieceByPiece(cell.DataCell, Buffer, ref cellValueIndex); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.