示例#1
0
        public override int FormatValue(StringBuilder dest, HexBytes hexBytes, long valueIndex, HexValueFormatterFlags flags)
        {
            int b = hexBytes.TryReadByte(valueIndex);

            if (b < 0)
            {
                return(WriteInvalid(dest));
            }
            return(WriteFormattedValue(dest, b.ToString(culture)));
        }
示例#2
0
        public override int FormatValue(StringBuilder dest, HexBytes hexBytes, long valueIndex, HexValueFormatterFlags flags)
        {
            int b = hexBytes.TryReadByte(valueIndex);

            if (b < 0)
            {
                return(WriteInvalid(dest));
            }
            WriteHexByte(dest, flags, (byte)b);
            return(0);
        }
示例#3
0
        public override int FormatValue(StringBuilder dest, HexBytes hexBytes, long valueIndex, HexValueFormatterFlags flags)
        {
            int b = hexBytes.TryReadByte(valueIndex);

            if (b < 0)
            {
                return(WriteInvalid(dest));
            }
            for (int i = 0; i < 8; i++, b <<= 1)
            {
                dest.Append((b & 0x80) != 0 ? '1' : '0');
            }
            return(0);
        }
示例#4
0
        HexCell[] WriteAscii(HexBytes hexBytes, HexSpan visibleBytesSpan, out VST.Span fullSpan, out VST.Span visibleSpan)
        {
            Debug.Assert(showAscii);
            cellList.Clear();
            int fullStart = CurrentTextIndex;

            int?visStart = null;
            int?visEnd   = null;
            var pos      = visibleBytesSpan.Start;
            int cellPos  = 0;

            for (ulong i = 0; i < bytesPerLine; i++, pos++)
            {
                int groupIndex = (cellPos / groupSizeInBytes) & 1;

                HexBufferSpan bufferSpan;
                int           cellStart = CurrentTextIndex;
                if (visibleBytesSpan.Contains(pos))
                {
                    if (visStart == null)
                    {
                        visStart = CurrentTextIndex;
                    }
                    long index = (long)(pos - visibleBytesSpan.Start).ToUInt64();
                    int  b     = hexBytes.TryReadByte(index);
                    if (b < 0)
                    {
                        stringBuilder.Append('?');
                    }
                    else if (b < 0x20 || b > 0x7E)
                    {
                        stringBuilder.Append('.');
                    }
                    else
                    {
                        stringBuilder.Append((char)b);
                    }
                    bufferSpan = new HexBufferSpan(buffer, new HexSpan(pos, 1));
                }
                else
                {
                    if (visStart != null && visEnd == null)
                    {
                        visEnd = CurrentTextIndex;
                    }
                    stringBuilder.Append(' ');
                    bufferSpan = default;
                }
                var cellSpan      = VST.Span.FromBounds(cellStart, CurrentTextIndex);
                var separatorSpan = new VST.Span(cellSpan.End, 0);
                cellList.Add(new HexCell((int)i, groupIndex, bufferSpan, cellSpan, cellSpan, separatorSpan, cellSpan));

                cellPos++;
            }
            if ((ulong)fullStart + bytesPerLine != (ulong)CurrentTextIndex)
            {
                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 (AsciiSpan != fullSpan)
                                     {
                                         throw new InvalidOperationException();
                                     }
                                     return(cellList.ToArray());
        }