Skip to content

Commit

Permalink
Use string interpolation handler in WorksheetEndXml
Browse files Browse the repository at this point in the history
  • Loading branch information
sveinungf committed Dec 22, 2024
1 parent eeaba9c commit a284bac
Showing 1 changed file with 9 additions and 41 deletions.
50 changes: 9 additions & 41 deletions SpreadCheetah/MetadataXml/WorksheetEndXml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using SpreadCheetah.CellReferences;
using SpreadCheetah.Helpers;
using SpreadCheetah.Validations;

namespace SpreadCheetah.MetadataXml;
Expand Down Expand Up @@ -87,32 +86,14 @@ public bool MoveNext()

private readonly bool TryWriteAutoFilter()
{
if (_autoFilterRange is not { } range) return true;

var span = _buffer.GetSpan();
var written = 0;

if (!"<autoFilter ref=\""u8.TryCopyTo(span, ref written)) return false;
if (!SpanHelper.TryWrite(range, span, ref written)) return false;
if (!"\"></autoFilter>"u8.TryCopyTo(span, ref written)) return false;

_buffer.Advance(written);
return true;
return _autoFilterRange is not { } range
|| _buffer.TryWrite($"{"<autoFilter ref=\""u8}{range}{"\"></autoFilter>"u8}");
}

private readonly bool TryWriteCellMergesStart()
{
if (_cellMerges.IsEmpty) return true;

var span = _buffer.GetSpan();
var written = 0;

if (!"<mergeCells count=\""u8.TryCopyTo(span, ref written)) return false;
if (!SpanHelper.TryWrite(_cellMerges.Length, span, ref written)) return false;
if (!"\">"u8.TryCopyTo(span, ref written)) return false;

_buffer.Advance(written);
return true;
return _cellMerges.IsEmpty
|| _buffer.TryWrite($"{"<mergeCells count=\""u8}{_cellMerges.Length}{"\">"u8}");
}

private bool TryWriteCellMerges()
Expand All @@ -123,14 +104,10 @@ private bool TryWriteCellMerges()
for (; _nextIndex < cellMerges.Length; ++_nextIndex)
{
var cellMerge = cellMerges[_nextIndex];
var span = _buffer.GetSpan();
var written = 0;

if (!"<mergeCell ref=\""u8.TryCopyTo(span, ref written)) return false;
if (!SpanHelper.TryWrite(cellMerge.Reference, span, ref written)) return false;
if (!"\"/>"u8.TryCopyTo(span, ref written)) return false;

_buffer.Advance(written);
var success = _buffer.TryWrite($"{"<mergeCell ref=\""u8}{cellMerge.Reference}{"\"/>"u8}");
if (!success)
return false;
}

_nextIndex = 0;
Expand All @@ -142,17 +119,8 @@ private readonly bool TryWriteCellMergesEnd()

private readonly bool TryWriteValidationsStart()
{
if (_validations.IsEmpty) return true;

var span = _buffer.GetSpan();
var written = 0;

if (!"<dataValidations count=\""u8.TryCopyTo(span, ref written)) return false;
if (!SpanHelper.TryWrite(_validations.Length, span, ref written)) return false;
if (!"\">"u8.TryCopyTo(span, ref written)) return false;

_buffer.Advance(written);
return true;
return _validations.IsEmpty
|| _buffer.TryWrite($"{"<dataValidations count=\""u8}{_validations.Length}{"\">"u8}");
}

private bool TryWriteValidations()
Expand Down

0 comments on commit a284bac

Please sign in to comment.