FormatValue() public abstract method

Formats the value and returns the number of spaces that were inserted before the number so exactly FormattedLength characters were written to dest
public abstract FormatValue ( StringBuilder dest, dnSpy.Contracts.Hex.HexBytes hexBytes, long valueIndex, HexValueFormatterFlags flags ) : int
dest StringBuilder Destination string builder
hexBytes dnSpy.Contracts.Hex.HexBytes Bytes
valueIndex long Index of value in
flags HexValueFormatterFlags Flags
return int
コード例 #1
0
        HexCell[] WriteValues(HexBytes hexBytes, HexSpan visibleBytesSpan, out VST.Span fullSpan, out VST.Span visibleSpan)
        {
            Debug.Assert(showValues);
            cellList.Clear();
            int fullStart = CurrentTextIndex;

            ulong cellCount = bytesPerLine / (ulong)valueFormatter.ByteCount;
            var   flags     = valuesLowerCaseHex ? HexValueFormatterFlags.LowerCaseHex : HexValueFormatterFlags.None;
            var   pos       = visibleBytesSpan.Start;
            var   end       = visibleBytesSpan.Start + bytesPerLine;
            int?  visStart  = null;
            int?  visEnd    = null;
            int   cellPos   = 0;

            for (ulong i = 0; i < cellCount; i++)
            {
                if (i != 0)
                {
                    stringBuilder.Append(' ');
                }
                int groupIndex = (cellPos / groupSizeInBytes) & 1;

                HexBufferSpan bufferSpan;
                int           cellStart = CurrentTextIndex;
                int           spaces;
                if (visibleBytesSpan.Contains(pos))
                {
                    if (visStart == null)
                    {
                        visStart = CurrentTextIndex;
                    }
                    long valueIndex = (long)(pos - visibleBytesSpan.Start).ToUInt64();
                    spaces = valueFormatter.FormatValue(stringBuilder, hexBytes, valueIndex, flags);
                    var endPos = HexPosition.Min(endPosition, pos + (ulong)valueFormatter.ByteCount);
                    bufferSpan = new HexBufferSpan(new HexBufferPoint(buffer, pos), new HexBufferPoint(buffer, endPos));
                }
                else
                {
                    if (visStart != null && visEnd == null)
                    {
                        visEnd = CurrentTextIndex;
                    }
                    stringBuilder.Append(' ', valueFormatter.FormattedLength);
                    spaces     = valueFormatter.FormattedLength;
                    bufferSpan = default;
                }
                if (cellStart + valueFormatter.FormattedLength != CurrentTextIndex)
                {
                    throw new InvalidOperationException();
                }
                var      textSpan = VST.Span.FromBounds(cellStart + spaces, CurrentTextIndex);
                var      cellSpan = VST.Span.FromBounds(cellStart, CurrentTextIndex);
                VST.Span separatorSpan;
                if (i + 1 < cellCount)
                {
                    separatorSpan = new VST.Span(CurrentTextIndex, 1);
                }
                else
                {
                    separatorSpan = new VST.Span(CurrentTextIndex, 0);
                }
                var cellFullSpan = VST.Span.FromBounds(cellStart, separatorSpan.End);
                cellList.Add(new HexCell((int)i, groupIndex, bufferSpan, textSpan, cellSpan, separatorSpan, cellFullSpan));

                pos     += (ulong)valueFormatter.ByteCount;
                cellPos += valueFormatter.ByteCount;
            }
            if (pos != end)
            {
                throw new InvalidOperationException();
            }
            if (visStart != null && visEnd == null)
            {
                visEnd = CurrentTextIndex;
            }

            visibleSpan                       = visStart == null ? default : VST.Span.FromBounds(visStart.Value, visEnd.Value);
                                     fullSpan = VST.Span.FromBounds(fullStart, CurrentTextIndex);
                                     if (ValuesSpan != fullSpan)
                                     {
                                         throw new InvalidOperationException();
                                     }
                                     return(cellList.ToArray());
        }