System.Xml.XmlBufferReader.Equals2 C# (CSharp) Méthode

Equals2() public méthode

public Equals2 ( int offset1, int length1, string s2 ) : bool
offset1 int
length1 int
s2 string
Résultat bool
        unsafe public bool Equals2(int offset1, int length1, string s2)
        {
            int byteLength = length1;
            int charLength = s2.Length;

            // N Unicode chars will be represented in at least N bytes, but
            // no more than N * 3 bytes.  If the byte count falls outside of this
            // range, then the strings cannot be equal.
            if (byteLength < charLength || byteLength > charLength * maxBytesPerChar)
                return false;

            byte[] buffer = _buffer;
            if (length1 < 8)
            {
                int length = Math.Min(byteLength, charLength);
                int offset = offset1;
                for (int i = 0; i < length; i++)
                {
                    byte b = buffer[offset + i];
                    if (b >= 0x80)
                        return XmlConverter.ToString(buffer, offset1, length1) == s2;
                    if (s2[i] != (char)b)
                        return false;
                }
                return byteLength == charLength;
            }
            else
            {
                int length = Math.Min(byteLength, charLength);
                fixed (byte* _pb = &buffer[offset1])
                {
                    byte* pb = _pb;
                    byte* pbMax = pb + length;
                    fixed (char* _pch = s2)
                    {
                        char* pch = _pch;
                        // Try to do the fast comparison in ASCII space
                        int t = 0;
                        while (pb < pbMax && *pb < 0x80)
                        {
                            t = *pb - (byte)*pch;
                            // The code generated is better if we break out then return
                            if (t != 0)
                                break;
                            pb++;
                            pch++;
                        }
                        if (t != 0)
                            return false;
                        if (pb == pbMax)
                            return (byteLength == charLength);
                    }
                }
                return XmlConverter.ToString(buffer, offset1, length1) == s2;
            }
        }

Same methods

XmlBufferReader::Equals2 ( int key1, XmlDictionaryString xmlString2 ) : bool
XmlBufferReader::Equals2 ( int key1, int key2, XmlBufferReader bufferReader2 ) : bool
XmlBufferReader::Equals2 ( int offset1, int length1, XmlBufferReader bufferReader2, int offset2, int length2 ) : bool
XmlBufferReader::Equals2 ( int offset1, int length1, byte buffer2 ) : bool
XmlBufferReader::Equals2 ( int offset1, int length1, int offset2, int length2 ) : bool

Usage Example

        public bool Equals([NotNullWhen(true)] PrefixHandle?prefix2)
        {
            if (prefix2 is null)
            {
                return(false);
            }
            PrefixHandleType type1 = _type;
            PrefixHandleType type2 = prefix2._type;

            if (type1 != type2)
            {
                return(false);
            }
            if (type1 != PrefixHandleType.Buffer)
            {
                return(true);
            }
            if (_bufferReader == prefix2._bufferReader)
            {
                return(_bufferReader.Equals2(_offset, _length, prefix2._offset, prefix2._length));
            }
            else
            {
                return(_bufferReader.Equals2(_offset, _length, prefix2._bufferReader, prefix2._offset, prefix2._length));
            }
        }
All Usage Examples Of System.Xml.XmlBufferReader::Equals2