Beispiel #1
0
        public static bool TryParseBoolean(ReadOnlySpan <byte> text, out bool value, out int bytesConsumed, SymbolTable symbolTable = null)
        {
            symbolTable = symbolTable ?? SymbolTable.InvariantUtf8;

            bytesConsumed = 0;
            value         = default;

            if (symbolTable == SymbolTable.InvariantUtf8)
            {
                return(Utf8Parser.TryParse(text, out value, out bytesConsumed));
            }
            if (symbolTable == SymbolTable.InvariantUtf16)
            {
                ReadOnlySpan <char> textChars = MemoryMarshal.Cast <byte, char>(text);
                bool result = Utf16Parser.TryParseBoolean(textChars, out value, out int charactersConsumed);
                bytesConsumed = charactersConsumed * sizeof(char);
                return(result);
            }

            return(false);
        }