private unsafe bool TryParseTokenUnsafe()

in Microsoft.Shared.Dna.Json/JsonParser.cs [1466:1524]


        private unsafe bool TryParseTokenUnsafe(out long value)
        {
            value = default(long);
            long accumulator = 0L;
            int first = this.TokenSegment.Offset;
            int last = first + this.TokenSegment.Count;
            byte digit = default(byte);
            fixed (char* payloadPointer = this.TokenSegment.String)
            {
                char* cp = payloadPointer + first;
                if (*cp == JsonConstants.NegativeSign)
                {
                    for (int i = first + 1; i < last; i++)
                    {
                        cp = payloadPointer + i;
                        if (JsonParser.TryConvertDecimal(*cp, out digit))
                        {
                            try
                            {
                                accumulator = checked((accumulator * JsonConstants.DecimalRadix) - digit);
                            }
                            catch (OverflowException)
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                }
                else
                {
                    for (int i = first; i < last; i++)
                    {
                        cp = payloadPointer + i;
                        if (JsonParser.TryConvertDecimal(*cp, out digit))
                        {
                            try
                            {
                                accumulator = checked((accumulator * JsonConstants.DecimalRadix) + digit);
                            }
                            catch (OverflowException)
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                }
            }

            value = accumulator;
            return true;
        }