Skip to content

Commit

Permalink
Rename some static ReadOnlySpan<byte>
Browse files Browse the repository at this point in the history
  • Loading branch information
sveinungf committed Dec 26, 2023
1 parent eb4bea9 commit 30915a0
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ public override bool TryWriteCellWithReference(in DataCell cell, StyleId styleId
public override bool WriteFormulaStartElement(StyleId? styleId, DefaultStyling? defaultStyling, SpreadsheetBuffer buffer)
{
return styleId is { } style
? buffer.TryWrite($"{BeginStyledBooleanCell}{style.Id}{FormulaCellHelper.EndStyleBeginFormula}")
? buffer.TryWrite($"{BeginStyledBooleanCell}{style.Id}{FormulaCellHelper.EndQuoteBeginFormula}")
: buffer.TryWrite($"{BeginBooleanFormulaCell}");
}

public override bool WriteFormulaStartElementWithReference(StyleId? styleId, DefaultStyling? defaultStyling, CellWriterState state)
{
return styleId is { } style
? state.Buffer.TryWrite($"{state}{EndReferenceBeginStyled}{style.Id}{FormulaCellHelper.EndStyleBeginFormula}")
? state.Buffer.TryWrite($"{state}{EndReferenceBeginStyled}{style.Id}{FormulaCellHelper.EndQuoteBeginFormula}")
: state.Buffer.TryWrite($"{state}{EndReferenceBeginFormula}");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public override bool TryWriteCell(string formulaText, in DataCell cachedValue, S
if (styleId is { } style)
{
return buffer.TryWrite(
$"{BeginStyledBooleanCell}{style}{FormulaCellHelper.EndStyleBeginFormula}" +
$"{BeginStyledBooleanCell}{style}{FormulaCellHelper.EndQuoteBeginFormula}" +
$"{formulaText}" +
$"{EndFormulaFalseBooleanValue}");
}
Expand All @@ -50,7 +50,7 @@ public override bool TryWriteCellWithReference(string formulaText, in DataCell c
if (styleId is { } style)
{
return state.Buffer.TryWrite(
$"{state}{EndReferenceBeginStyled}{style.Id}{FormulaCellHelper.EndStyleBeginFormula}" +
$"{state}{EndReferenceBeginStyled}{style.Id}{FormulaCellHelper.EndQuoteBeginFormula}" +
$"{formulaText}" +
$"{EndFormulaFalseBooleanValue}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public override bool TryWriteCell(string formulaText, in DataCell cachedValue, S
if (styleId is { } style)
{
return buffer.TryWrite(
$"{BeginStyledBooleanCell}{style}{FormulaCellHelper.EndStyleBeginFormula}" +
$"{BeginStyledBooleanCell}{style}{FormulaCellHelper.EndQuoteBeginFormula}" +
$"{formulaText}" +
$"{EndFormulaTrueBooleanValue}");
}
Expand All @@ -50,7 +50,7 @@ public override bool TryWriteCellWithReference(string formulaText, in DataCell c
if (styleId is { } style)
{
return state.Buffer.TryWrite(
$"{state}{EndReferenceBeginStyled}{style.Id}{FormulaCellHelper.EndStyleBeginFormula}" +
$"{state}{EndReferenceBeginStyled}{style.Id}{FormulaCellHelper.EndQuoteBeginFormula}" +
$"{formulaText}" +
$"{EndFormulaTrueBooleanValue}");
}
Expand Down
20 changes: 10 additions & 10 deletions SpreadCheetah/CellValueWriters/NullValueWriterBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal abstract class NullValueWriterBase : CellValueWriter
protected abstract int GetStyleId(StyleId styleId);

private static ReadOnlySpan<byte> NullDataCell => "<c/>"u8;
private static ReadOnlySpan<byte> EndStyleNullValue => "\"/>"u8; // TODO: Rename
private static ReadOnlySpan<byte> EndQuoteNullValue => "\"/>"u8;
private static ReadOnlySpan<byte> EndFormulaEndCell => "</f></c>"u8;

protected static bool TryWriteCell(SpreadsheetBuffer buffer)
Expand All @@ -19,15 +19,15 @@ protected static bool TryWriteCell(SpreadsheetBuffer buffer)

protected static bool TryWriteCell(int styleId, SpreadsheetBuffer buffer)
{
return buffer.TryWrite($"{StyledCellHelper.BeginStyledNumberCell}{styleId}{EndStyleNullValue}");
return buffer.TryWrite($"{StyledCellHelper.BeginStyledNumberCell}{styleId}{EndQuoteNullValue}");
}

protected static bool TryWriteCell(string formulaText, int? styleId, SpreadsheetBuffer buffer)
{
if (styleId is { } style)
{
return buffer.TryWrite(
$"{StyledCellHelper.BeginStyledNumberCell}{style}{FormulaCellHelper.EndStyleBeginFormula}" +
$"{StyledCellHelper.BeginStyledNumberCell}{style}{FormulaCellHelper.EndQuoteBeginFormula}" +
$"{formulaText}" +
$"{EndFormulaEndCell}");
}
Expand All @@ -45,7 +45,7 @@ public override bool TryWriteCell(in DataCell cell, StyleId styleId, Spreadsheet

protected static bool TryWriteCellWithReference(CellWriterState state)
{
return state.Buffer.TryWrite($"{state}{EndStyleNullValue}");
return state.Buffer.TryWrite($"{state}{EndQuoteNullValue}");
}

public override bool TryWriteCellWithReference(in DataCell cell, StyleId styleId, CellWriterState state)
Expand All @@ -55,21 +55,21 @@ public override bool TryWriteCellWithReference(in DataCell cell, StyleId styleId

protected static bool TryWriteCellWithReference(int styleId, CellWriterState state)
{
return state.Buffer.TryWrite($"{state}{StyledCellHelper.EndReferenceBeginStyleId}{styleId}{EndStyleNullValue}");
return state.Buffer.TryWrite($"{state}{StyledCellHelper.EndReferenceBeginStyleId}{styleId}{EndQuoteNullValue}");
}

protected static bool TryWriteCellWithReference(string formulaText, int? styleId, CellWriterState state)
{
if (styleId is { } style)
{
return state.Buffer.TryWrite(
$"{state}{StyledCellHelper.EndReferenceBeginStyleId}{style}{FormulaCellHelper.EndStyleBeginFormula}" +
$"{state}{StyledCellHelper.EndReferenceBeginStyleId}{style}{FormulaCellHelper.EndQuoteBeginFormula}" +
$"{formulaText}" +
$"{EndFormulaEndCell}");
}

return state.Buffer.TryWrite(
$"{state}{FormulaCellHelper.EndStyleBeginFormula}" +
$"{state}{FormulaCellHelper.EndQuoteBeginFormula}" +
$"{formulaText}" +
$"{EndFormulaEndCell}");
}
Expand All @@ -84,15 +84,15 @@ public override bool TryWriteEndElement(in Cell cell, SpreadsheetBuffer buffer)
protected static bool WriteFormulaStartElement(int? styleId, SpreadsheetBuffer buffer)
{
return styleId is { } style
? buffer.TryWrite($"{StyledCellHelper.BeginStyledNumberCell}{style}{FormulaCellHelper.EndStyleBeginFormula}")
? buffer.TryWrite($"{StyledCellHelper.BeginStyledNumberCell}{style}{FormulaCellHelper.EndQuoteBeginFormula}")
: buffer.TryWrite($"{FormulaCellHelper.BeginNumberFormulaCell}");
}

protected static bool WriteFormulaStartElementWithReference(int? styleId, CellWriterState state)
{
return styleId is { } style
? state.Buffer.TryWrite($"{state}{StyledCellHelper.EndReferenceBeginStyleId}{style}{FormulaCellHelper.EndStyleBeginFormula}")
: state.Buffer.TryWrite($"{state}{FormulaCellHelper.EndStyleBeginFormula}");
? state.Buffer.TryWrite($"{state}{StyledCellHelper.EndReferenceBeginStyleId}{style}{FormulaCellHelper.EndQuoteBeginFormula}")
: state.Buffer.TryWrite($"{state}{FormulaCellHelper.EndQuoteBeginFormula}");
}

public override bool WriteStartElement(SpreadsheetBuffer buffer) => TryWriteCell(buffer);
Expand Down
12 changes: 6 additions & 6 deletions SpreadCheetah/CellValueWriters/Number/DoubleCellValueWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public override bool TryWriteCell(in DataCell cell, DefaultStyling? defaultStyli
public override bool TryWriteCell(in DataCell cell, StyleId styleId, SpreadsheetBuffer buffer)
{
return buffer.TryWrite(
$"{StyledCellHelper.BeginStyledNumberCell}{styleId.Id}{EndStyleBeginValue}" +
$"{StyledCellHelper.BeginStyledNumberCell}{styleId.Id}{EndQuoteBeginValue}" +
$"{cell.NumberValue.DoubleValue}" +
$"{EndDefaultCell}");
}
Expand All @@ -25,7 +25,7 @@ public override bool TryWriteCell(string formulaText, in DataCell cachedValue, S
if (styleId is { } style)
{
return buffer.TryWrite(
$"{StyledCellHelper.BeginStyledNumberCell}{style.Id}{FormulaCellHelper.EndStyleBeginFormula}" +
$"{StyledCellHelper.BeginStyledNumberCell}{style.Id}{FormulaCellHelper.EndQuoteBeginFormula}" +
$"{formulaText}" +
$"{FormulaCellHelper.EndFormulaBeginCachedValue}" +
$"{cachedValue.NumberValue.DoubleValue}" +
Expand All @@ -43,15 +43,15 @@ public override bool TryWriteCell(string formulaText, in DataCell cachedValue, S
public override bool TryWriteCellWithReference(in DataCell cell, DefaultStyling? defaultStyling, CellWriterState state)
{
return state.Buffer.TryWrite(
$"{state}{EndStyleBeginValue}" +
$"{state}{EndQuoteBeginValue}" +
$"{cell.NumberValue.DoubleValue}" +
$"{EndDefaultCell}");
}

public override bool TryWriteCellWithReference(in DataCell cell, StyleId styleId, CellWriterState state)
{
return state.Buffer.TryWrite(
$"{state}{StyledCellHelper.EndReferenceBeginStyleId}{styleId.Id}{EndStyleBeginValue}" +
$"{state}{StyledCellHelper.EndReferenceBeginStyleId}{styleId.Id}{EndQuoteBeginValue}" +
$"{cell.NumberValue.DoubleValue}" +
$"{EndDefaultCell}");
}
Expand All @@ -61,15 +61,15 @@ public override bool TryWriteCellWithReference(string formulaText, in DataCell c
if (styleId is { } style)
{
return state.Buffer.TryWrite(
$"{state}{StyledCellHelper.EndReferenceBeginStyleId}{style.Id}{FormulaCellHelper.EndStyleBeginFormula}" +
$"{state}{StyledCellHelper.EndReferenceBeginStyleId}{style.Id}{FormulaCellHelper.EndQuoteBeginFormula}" +
$"{formulaText}" +
$"{FormulaCellHelper.EndFormulaBeginCachedValue}" +
$"{cachedValue.NumberValue.DoubleValue}" +
$"{FormulaCellHelper.EndCachedValueEndCell}");
}

return state.Buffer.TryWrite(
$"{state}{FormulaCellHelper.EndStyleBeginFormula}" +
$"{state}{FormulaCellHelper.EndQuoteBeginFormula}" +
$"{formulaText}" +
$"{FormulaCellHelper.EndFormulaBeginCachedValue}" +
$"{cachedValue.NumberValue.DoubleValue}" +
Expand Down
12 changes: 6 additions & 6 deletions SpreadCheetah/CellValueWriters/Number/FloatCellValueWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public override bool TryWriteCell(in DataCell cell, DefaultStyling? defaultStyli
public override bool TryWriteCell(in DataCell cell, StyleId styleId, SpreadsheetBuffer buffer)
{
return buffer.TryWrite(
$"{StyledCellHelper.BeginStyledNumberCell}{styleId.Id}{EndStyleBeginValue}" +
$"{StyledCellHelper.BeginStyledNumberCell}{styleId.Id}{EndQuoteBeginValue}" +
$"{cell.NumberValue.FloatValue}" +
$"{EndDefaultCell}");
}
Expand All @@ -25,7 +25,7 @@ public override bool TryWriteCell(string formulaText, in DataCell cachedValue, S
if (styleId is { } style)
{
return buffer.TryWrite(
$"{StyledCellHelper.BeginStyledNumberCell}{style.Id}{FormulaCellHelper.EndStyleBeginFormula}" +
$"{StyledCellHelper.BeginStyledNumberCell}{style.Id}{FormulaCellHelper.EndQuoteBeginFormula}" +
$"{formulaText}" +
$"{FormulaCellHelper.EndFormulaBeginCachedValue}" +
$"{cachedValue.NumberValue.FloatValue}" +
Expand All @@ -43,15 +43,15 @@ public override bool TryWriteCell(string formulaText, in DataCell cachedValue, S
public override bool TryWriteCellWithReference(in DataCell cell, DefaultStyling? defaultStyling, CellWriterState state)
{
return state.Buffer.TryWrite(
$"{state}{EndStyleBeginValue}" +
$"{state}{EndQuoteBeginValue}" +
$"{cell.NumberValue.FloatValue}" +
$"{EndDefaultCell}");
}

public override bool TryWriteCellWithReference(in DataCell cell, StyleId styleId, CellWriterState state)
{
return state.Buffer.TryWrite(
$"{state}{StyledCellHelper.EndReferenceBeginStyleId}{styleId.Id}{EndStyleBeginValue}" +
$"{state}{StyledCellHelper.EndReferenceBeginStyleId}{styleId.Id}{EndQuoteBeginValue}" +
$"{cell.NumberValue.FloatValue}" +
$"{EndDefaultCell}");
}
Expand All @@ -61,15 +61,15 @@ public override bool TryWriteCellWithReference(string formulaText, in DataCell c
if (styleId is { } style)
{
return state.Buffer.TryWrite(
$"{state}{StyledCellHelper.EndReferenceBeginStyleId}{style.Id}{FormulaCellHelper.EndStyleBeginFormula}" +
$"{state}{StyledCellHelper.EndReferenceBeginStyleId}{style.Id}{FormulaCellHelper.EndQuoteBeginFormula}" +
$"{formulaText}" +
$"{FormulaCellHelper.EndFormulaBeginCachedValue}" +
$"{cachedValue.NumberValue.FloatValue}" +
$"{FormulaCellHelper.EndCachedValueEndCell}");
}

return state.Buffer.TryWrite(
$"{state}{FormulaCellHelper.EndStyleBeginFormula}" +
$"{state}{FormulaCellHelper.EndQuoteBeginFormula}" +
$"{formulaText}" +
$"{FormulaCellHelper.EndFormulaBeginCachedValue}" +
$"{cachedValue.NumberValue.FloatValue}" +
Expand Down
12 changes: 6 additions & 6 deletions SpreadCheetah/CellValueWriters/Number/IntegerCellValueWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public override bool TryWriteCell(in DataCell cell, DefaultStyling? defaultStyli
public override bool TryWriteCell(in DataCell cell, StyleId styleId, SpreadsheetBuffer buffer)
{
return buffer.TryWrite(
$"{StyledCellHelper.BeginStyledNumberCell}{styleId.Id}{EndStyleBeginValue}" +
$"{StyledCellHelper.BeginStyledNumberCell}{styleId.Id}{EndQuoteBeginValue}" +
$"{cell.NumberValue.IntValue}" +
$"{EndDefaultCell}");
}
Expand All @@ -25,7 +25,7 @@ public override bool TryWriteCell(string formulaText, in DataCell cachedValue, S
if (styleId is { } style)
{
return buffer.TryWrite(
$"{StyledCellHelper.BeginStyledNumberCell}{style.Id}{FormulaCellHelper.EndStyleBeginFormula}" +
$"{StyledCellHelper.BeginStyledNumberCell}{style.Id}{FormulaCellHelper.EndQuoteBeginFormula}" +
$"{formulaText}" +
$"{FormulaCellHelper.EndFormulaBeginCachedValue}" +
$"{cachedValue.NumberValue.IntValue}" +
Expand All @@ -43,15 +43,15 @@ public override bool TryWriteCell(string formulaText, in DataCell cachedValue, S
public override bool TryWriteCellWithReference(in DataCell cell, DefaultStyling? defaultStyling, CellWriterState state)
{
return state.Buffer.TryWrite(
$"{state}{EndStyleBeginValue}" +
$"{state}{EndQuoteBeginValue}" +
$"{cell.NumberValue.IntValue}" +
$"{EndDefaultCell}");
}

public override bool TryWriteCellWithReference(in DataCell cell, StyleId styleId, CellWriterState state)
{
return state.Buffer.TryWrite(
$"{state}{StyledCellHelper.EndReferenceBeginStyleId}{styleId.Id}{EndStyleBeginValue}" +
$"{state}{StyledCellHelper.EndReferenceBeginStyleId}{styleId.Id}{EndQuoteBeginValue}" +
$"{cell.NumberValue.IntValue}" +
$"{EndDefaultCell}");
}
Expand All @@ -61,15 +61,15 @@ public override bool TryWriteCellWithReference(string formulaText, in DataCell c
if (styleId is { } style)
{
return state.Buffer.TryWrite(
$"{state}{StyledCellHelper.EndReferenceBeginStyleId}{style.Id}{FormulaCellHelper.EndStyleBeginFormula}" +
$"{state}{StyledCellHelper.EndReferenceBeginStyleId}{style.Id}{FormulaCellHelper.EndQuoteBeginFormula}" +
$"{formulaText}" +
$"{FormulaCellHelper.EndFormulaBeginCachedValue}" +
$"{cachedValue.NumberValue.IntValue}" +
$"{FormulaCellHelper.EndCachedValueEndCell}");
}

return state.Buffer.TryWrite(
$"{state}{FormulaCellHelper.EndStyleBeginFormula}" +
$"{state}{FormulaCellHelper.EndQuoteBeginFormula}" +
$"{formulaText}" +
$"{FormulaCellHelper.EndFormulaBeginCachedValue}" +
$"{cachedValue.NumberValue.IntValue}" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal abstract class NumberCellValueWriterBase : CellValueWriter
protected abstract int GetStyleId(StyleId styleId);

protected static ReadOnlySpan<byte> BeginDataCell => "<c><v>"u8;
protected static ReadOnlySpan<byte> EndStyleBeginValue => "\"><v>"u8; // TODO: Rename
protected static ReadOnlySpan<byte> EndQuoteBeginValue => "\"><v>"u8;
protected static ReadOnlySpan<byte> EndDefaultCell => "</v></c>"u8;

public override bool WriteStartElement(SpreadsheetBuffer buffer)
Expand All @@ -20,32 +20,32 @@ public override bool WriteStartElement(SpreadsheetBuffer buffer)
public override bool WriteStartElement(StyleId styleId, SpreadsheetBuffer buffer)
{
var style = GetStyleId(styleId);
return buffer.TryWrite($"{StyledCellHelper.BeginStyledNumberCell}{style}{EndStyleBeginValue}");
return buffer.TryWrite($"{StyledCellHelper.BeginStyledNumberCell}{style}{EndQuoteBeginValue}");
}

public override bool WriteStartElementWithReference(CellWriterState state)
{
return state.Buffer.TryWrite($"{state}{EndStyleBeginValue}");
return state.Buffer.TryWrite($"{state}{EndQuoteBeginValue}");
}

public override bool WriteStartElementWithReference(StyleId styleId, CellWriterState state)
{
var style = GetStyleId(styleId);
return state.Buffer.TryWrite($"{state}{StyledCellHelper.EndReferenceBeginStyleId}{style}{EndStyleBeginValue}");
return state.Buffer.TryWrite($"{state}{StyledCellHelper.EndReferenceBeginStyleId}{style}{EndQuoteBeginValue}");
}

protected static bool WriteFormulaStartElement(int? styleId, SpreadsheetBuffer buffer)
{
return styleId is { } style
? buffer.TryWrite($"{StyledCellHelper.BeginStyledNumberCell}{style}{FormulaCellHelper.EndStyleBeginFormula}")
? buffer.TryWrite($"{StyledCellHelper.BeginStyledNumberCell}{style}{FormulaCellHelper.EndQuoteBeginFormula}")
: buffer.TryWrite($"{FormulaCellHelper.BeginNumberFormulaCell}");
}

protected static bool WriteFormulaStartElementWithReference(int? styleId, CellWriterState state)
{
return styleId is { } style
? state.Buffer.TryWrite($"{state}{StyledCellHelper.EndReferenceBeginStyleId}{style}{FormulaCellHelper.EndStyleBeginFormula}")
: state.Buffer.TryWrite($"{state}{FormulaCellHelper.EndStyleBeginFormula}");
? state.Buffer.TryWrite($"{state}{StyledCellHelper.EndReferenceBeginStyleId}{style}{FormulaCellHelper.EndQuoteBeginFormula}")
: state.Buffer.TryWrite($"{state}{FormulaCellHelper.EndQuoteBeginFormula}");
}

public override bool CanWriteValuePieceByPiece(in DataCell cell) => true;
Expand Down
Loading

0 comments on commit 30915a0

Please sign in to comment.