in src/Elastic.Apm/Libraries/Newtonsoft.Json/JsonTextReader.cs [543:662]
private object? ReadStringValue(ReadType readType)
{
EnsureBuffer();
MiscellaneousUtils.Assert(CharBuffer != null);
switch (_currentState)
{
case State.PostValue:
if (ParsePostValue(true)) return null;
goto case State.Start;
case State.Start:
case State.Property:
case State.Array:
case State.ArrayStart:
case State.Constructor:
case State.ConstructorStart:
while (true)
{
var currentChar = CharBuffer[CharPos];
switch (currentChar)
{
case '\0':
if (ReadNullChar())
{
SetToken(JsonToken.None, null, false);
return null;
}
break;
case '"':
case '\'':
ParseString(currentChar, readType);
return FinishReadQuotedStringValue(readType);
case '-':
if (EnsureChars(1, true) && CharBuffer[CharPos + 1] == 'I')
return ParseNumberNegativeInfinity(readType);
else
{
ParseNumber(readType);
return Value;
}
case '.':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
if (readType != ReadType.ReadAsString)
{
CharPos++;
throw CreateUnexpectedCharacterException(currentChar);
}
ParseNumber(ReadType.ReadAsString);
return Value;
case 't':
case 'f':
if (readType != ReadType.ReadAsString)
{
CharPos++;
throw CreateUnexpectedCharacterException(currentChar);
}
var expected = currentChar == 't' ? JsonConvert.True : JsonConvert.False;
if (!MatchValueWithTrailingSeparator(expected)) throw CreateUnexpectedCharacterException(CharBuffer[CharPos]);
SetToken(JsonToken.String, expected);
return expected;
case 'I':
return ParseNumberPositiveInfinity(readType);
case 'N':
return ParseNumberNaN(readType);
case 'n':
HandleNull();
return null;
case '/':
ParseComment(false);
break;
case ',':
ProcessValueComma();
break;
case ']':
CharPos++;
if (_currentState == State.Array || _currentState == State.ArrayStart || _currentState == State.PostValue)
{
SetToken(JsonToken.EndArray);
return null;
}
throw CreateUnexpectedCharacterException(currentChar);
case StringUtils.CarriageReturn:
ProcessCarriageReturn(false);
break;
case StringUtils.LineFeed:
ProcessLineFeed();
break;
case ' ':
case StringUtils.Tab:
// eat
CharPos++;
break;
default:
CharPos++;
if (!char.IsWhiteSpace(currentChar)) throw CreateUnexpectedCharacterException(currentChar);
// eat
break;
}
}
case State.Finished:
ReadFinished();
return null;
default:
throw JsonReaderException.Create(this, "Unexpected state: {0}.".FormatWith(CultureInfo.InvariantCulture, CurrentState));
}
}