System.Text.Utf8.Utf8Encoder.TryDecodeCodePointBackwards C# (CSharp) Метод

TryDecodeCodePointBackwards() приватный Метод

private TryDecodeCodePointBackwards ( Span buffer, UnicodeCodePoint &codePoint, int &encodedBytes ) : bool
buffer Span
codePoint UnicodeCodePoint
encodedBytes int
Результат bool
        public static bool TryDecodeCodePointBackwards(Span<byte> buffer, out UnicodeCodePoint codePoint, out int encodedBytes)
        {
            if (TryFindEncodedCodePointBytesCountGoingBackwards(buffer, out encodedBytes))
            {
                int realEncodedBytes;
                // TODO: Inline decoding, as the invalid surrogate check can be done faster
                bool ret = TryDecodeCodePoint(buffer.Slice(buffer.Length - encodedBytes), out codePoint, out realEncodedBytes);
                if (ret && encodedBytes != realEncodedBytes)
                {
                    // invalid surrogate character
                    // we know the character length by iterating on surrogate characters from the end
                    // but the first byte of the character has also encoded length
                    // seems like the lengths don't match
                    return false;
                }
                return true;
            }

            codePoint = default(UnicodeCodePoint);
            encodedBytes = default(int);
            return false;
        }
        #endregion