Ejemplo n.º 1
0
        bool IsNewLine(BlockReader blockReader, LineEndings lineEndings, ICharacterReader charReader, long position, out long begin, out long end)
        {
            begin = -1;
            end   = -1;

            uint v = blockReader.ReadValue(position);

            if (v == LineEndings.CR)
            {
                begin     = position;
                position += blockReader.MinCodePointSize;
                end       = position;
                if (position < blockReader.StreamLength)
                {
                    v = blockReader.ReadValue(position);
                    if (v == LineEndings.LF)
                    {
                        end += blockReader.MinCodePointSize;
                    }
                }
                return(true);
            }
            else if (v == LineEndings.LF)
            {
                begin     = position;
                end       = position + blockReader.MinCodePointSize;
                position -= blockReader.MinCodePointSize;
                if (position >= 0)
                {
                    v = blockReader.ReadValue(position);
                    if (v == LineEndings.CR)
                    {
                        begin = position;
                    }
                }
                return(true);
            }
            else
            {
                if (charReader.TryReadCharacter(blockReader, position, v, out uint ch, out long first, out long last))
                {
                    if (lineEndings.IsLNewLine(ch))
                    {
                        begin = blockReader.PositionFirstByte(first);
                        end   = blockReader.PositionFirstByte(last) + blockReader.MinCodePointSize;
                        return(true);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 2
0
            // Reserved:       0b1101_1000_0000_0000 - 0b1101_1111_1111_1111

            // High surrogate: 0b1101_1000_0000_0000 - 0b1101_1011_1111_1111
            // Low surrogate:  0b1101_1100_0000_0000 - 0b1101_1111_1111_1111

            public bool TryReadCharacter(BlockReader blockReader, long position, out uint character, out long posFirstByte, out long posLastByte)
            {
                if (!(blockReader is BlockReader16))
                {
                    throw new ArgumentException($"Type of '{nameof(blockReader)}' should be '{typeof(BlockReader16).Name}'");
                }

                character    = 0;
                posFirstByte = -1;
                posLastByte  = -1;

                //position -= position & 0b1;
                position = blockReader.PositionFirstByte(position);

                if (position < 0 || position + 1 >= blockReader.StreamLength)
                {
                    return(false);
                }

                uint val = blockReader.ReadValue(position);

                if (val < 0b1101_1000_0000_0000 || val >= 0b1110_0000_0000_0000)
                {
                    character    = val;
                    posFirstByte = position;
                    posLastByte  = position + 1;
                    return(true);
                }
Ejemplo n.º 3
0
            public bool TryReadCharacter(BlockReader blockReader, long position, out uint character, out long posFirstByte, out long posLastByte)
            {
                if (!(blockReader is BlockReader32))
                {
                    throw new ArgumentException($"Type of '{nameof(blockReader)}' should be '{typeof(BlockReader32).Name}'");
                }

                character    = 0;
                posFirstByte = -1;
                posLastByte  = -1;

                position = blockReader.PositionFirstByte(position);

                if (position < 0 || position + 3 >= blockReader.StreamLength)
                {
                    return(false);
                }

                character    = blockReader.ReadValue(position);
                posFirstByte = position;
                posLastByte  = position + 3;
                return(true);
            }