in src/Elastic.Apm/Libraries/Newtonsoft.Json/Linq/JsonPath/JPath.cs [88:175]
private bool ParsePath(List<PathFilter> filters, int currentPartStartIndex, bool query)
{
var scan = false;
var followingIndexer = false;
var followingDot = false;
var ended = false;
while (_currentIndex < _expression.Length && !ended)
{
var currentChar = _expression[_currentIndex];
switch (currentChar)
{
case '[':
case '(':
if (_currentIndex > currentPartStartIndex)
{
var member = _expression.Substring(currentPartStartIndex, _currentIndex - currentPartStartIndex);
if (member == "*") member = null;
filters.Add(CreatePathFilter(member, scan));
scan = false;
}
filters.Add(ParseIndexer(currentChar, scan));
scan = false;
_currentIndex++;
currentPartStartIndex = _currentIndex;
followingIndexer = true;
followingDot = false;
break;
case ']':
case ')':
ended = true;
break;
case ' ':
if (_currentIndex < _expression.Length) ended = true;
break;
case '.':
if (_currentIndex > currentPartStartIndex)
{
var member = _expression.Substring(currentPartStartIndex, _currentIndex - currentPartStartIndex);
if (member == "*") member = null;
filters.Add(CreatePathFilter(member, scan));
scan = false;
}
if (_currentIndex + 1 < _expression.Length && _expression[_currentIndex + 1] == '.')
{
scan = true;
_currentIndex++;
}
_currentIndex++;
currentPartStartIndex = _currentIndex;
followingIndexer = false;
followingDot = true;
break;
default:
if (query && (currentChar == '=' || currentChar == '<' || currentChar == '!' || currentChar == '>' || currentChar == '|'
|| currentChar == '&'))
ended = true;
else
{
if (followingIndexer) throw new JsonException("Unexpected character following indexer: " + currentChar);
_currentIndex++;
}
break;
}
}
var atPathEnd = _currentIndex == _expression.Length;
if (_currentIndex > currentPartStartIndex)
{
var member = _expression.Substring(currentPartStartIndex, _currentIndex - currentPartStartIndex).TrimEnd();
if (member == "*") member = null;
filters.Add(CreatePathFilter(member, scan));
}
else
{
// no field name following dot in path and at end of base path/query
if (followingDot && (atPathEnd || query)) throw new JsonException("Unexpected end while parsing path.");
}
return atPathEnd;
}