示例#1
0
        private bool TryReadMacsBugSymbol(out string symbol)
        {
            var  offset = rdr.Offset;
            byte b;

            symbol = null;
            if (!rdr.TryReadByte(out b))
            {
                return(false);
            }
            int symLength = 0;

            // May have read the length byte.
            if (b == 0x80)
            {
                // long symbol: next byte is the 8-bit length.
                if (!rdr.TryReadByte(out b) || b == 0)
                {
                    rdr.Offset = offset;
                    return(false);
                }
                symLength = b;
            }
            else if (0x81 <= b && b < 0xA0)
            {
                symLength = b - 0x80;
            }
            else
            {
                rdr.Offset = offset;
                return(false);
            }

            // Now try reading `symLength` valid 8-bit chars.
            var symOffset = rdr.Offset;
            var sb        = new StringBuilder();

            for (int i = 0; i < symLength; ++i)
            {
                if (!rdr.TryReadByte(out b))
                {
                    rdr.Offset = offset;
                    return(false);
                }
                sb.Append((char)b);
            }
            if ((rdr.Offset & 1) == 1)
            {
                ++rdr.Offset;
            }
            symbol = sb.ToString();
            if (!this.reValidVariableLengthProcedureName.IsMatch(symbol))
            {
                symbol     = null;
                rdr.Offset = offset;
                return(false);
            }
            return(true);
        }