Пример #1
0
        public override HexBufferLine GetLineFromPosition(HexBufferPoint position)
        {
            position = FilterAndVerify(position);
            ResetBuilderFields();

            var linePosition  = startPosition + (position.Position - startPosition).ToUInt64() / bytesPerLine * bytesPerLine;
            var lineEnd       = HexPosition.Min(linePosition + bytesPerLine, endPosition);
            var lineSpan      = HexSpan.FromBounds(linePosition, lineEnd);
            var logicalOffset = ToLogicalPosition(lineSpan.Start);

            var hexBytes = buffer.ReadHexBytes(lineSpan.Start, (long)lineSpan.Length.ToUInt64());

            var offsetSpan        = default(VST.Span);
            var fullValuesSpan    = default(VST.Span);
            var visibleValuesSpan = default(VST.Span);
            var fullAsciiSpan     = default(VST.Span);
            var visibleAsciiSpan  = default(VST.Span);

            var valueCells = Array.Empty <HexCell>();
            var asciiCells = Array.Empty <HexCell>();

            bool needSep = false;

            foreach (var column in columnOrder)
            {
                switch (column)
                {
                case HexColumnType.Offset:
                    if (showOffset)
                    {
                        if (needSep)
                        {
                            stringBuilder.Append(' ');
                        }
                        needSep = true;
                        WriteOffset(logicalOffset, out offsetSpan);
                    }
                    break;

                case HexColumnType.Values:
                    if (showValues)
                    {
                        if (needSep)
                        {
                            stringBuilder.Append(' ');
                        }
                        needSep    = true;
                        valueCells = WriteValues(hexBytes, lineSpan, out fullValuesSpan, out visibleValuesSpan);
                    }
                    break;

                case HexColumnType.Ascii:
                    if (showAscii)
                    {
                        if (needSep)
                        {
                            stringBuilder.Append(' ');
                        }
                        needSep    = true;
                        asciiCells = WriteAscii(hexBytes, lineSpan, out fullAsciiSpan, out visibleAsciiSpan);
                    }
                    break;

                default:
                    throw new InvalidOperationException();
                }
            }

            var text = stringBuilder.ToString();

            if (text.Length != CharsPerLine)
            {
                throw new InvalidOperationException();
            }
            var valueCellColl = valueCells.Length == 0 ? HexCellCollection.Empty : new HexCellCollection(valueCells);
            var asciiCellColl = asciiCells.Length == 0 ? HexCellCollection.Empty : new HexCellCollection(asciiCells);
            var lineNumber    = GetLineNumberFromPosition(new HexBufferPoint(Buffer, lineSpan.Start));
            var res           = new HexBufferLineImpl(this, lineNumber, columnOrder, new HexBufferSpan(buffer, lineSpan), hexBytes, text, showOffset, showValues, showAscii, logicalOffset, valueCellColl, asciiCellColl, offsetSpan, fullValuesSpan, visibleValuesSpan, fullAsciiSpan, visibleAsciiSpan);

            ResetBuilderFields();
            return(res);
        }