Пример #1
0
    public async ValueTask WriteStringAsync(StringBuilder sb, Stream stream, CancellationToken token)
    {
        var remaining = FreeCapacity;
        var value     = sb.ToString();

        // Try with an approximate cell value length
        var bytesNeeded = value.Length * Utf8Helper.MaxBytePerChar;

        if (bytesNeeded > remaining)
        {
            // Try with a more accurate cell value length
            bytesNeeded = Utf8Helper.GetByteCount(value);
        }

        if (bytesNeeded > remaining)
        {
            await FlushToStreamAsync(stream, token).ConfigureAwait(false);
        }

        // Write whole value if it fits in the buffer
        if (bytesNeeded <= _buffer.Length)
        {
            _index += Utf8Helper.GetBytes(value, GetSpan());
            return;
        }

        // Otherwise, write value piece by piece
        var valueIndex = 0;

        while (!WriteLongString(value.AsSpan(), ref valueIndex))
        {
            await FlushToStreamAsync(stream, token).ConfigureAwait(false);
        }
    }
Пример #2
0
    private static int GetSheetElementByteCount(string path, int sheetId)
    {
        var sheetIdDigits = sheetId.GetNumberOfDigits();

        return(SheetStart.Length
               + Utf8Helper.GetByteCount(path)
               + BetweenPathAndRelationId.Length
               + SharedMetadata.RelationIdPrefix.Length
               + sheetIdDigits
               + RelationEnd.Length);
    }
Пример #3
0
 private static int GetSheetElementByteCount(string path)
 {
     return(SheetStart.Length
            + Utf8Helper.GetByteCount(path)
            + SheetEnd.Length);
 }