in src/Microsoft.Azure.Relay/WebSockets/NetStandard20/AuthenticationHelper.Digest.cs [396:465]
private string GetNextValue(string data, int currentIndex, bool expectQuotes, out int parsedIndex)
{
Debug.Assert(currentIndex < data.Length && !CharIsSpaceOrTab(data[currentIndex]));
// If quoted value, skip first quote.
bool quotedValue = false;
if (data[currentIndex] == '"')
{
quotedValue = true;
currentIndex++;
}
if (expectQuotes && !quotedValue)
{
parsedIndex = currentIndex;
return null;
}
StringBuilder sb = StringBuilderCache.Acquire();
while (currentIndex < data.Length && ((quotedValue && data[currentIndex] != '"') || (!quotedValue && data[currentIndex] != ',')))
{
sb.Append(data[currentIndex]);
currentIndex++;
if (currentIndex == data.Length)
break;
if (!quotedValue && CharIsSpaceOrTab(data[currentIndex]))
break;
if (quotedValue && data[currentIndex] == '"' && data[currentIndex - 1] == '\\')
{
// Include the escaped quote.
sb.Append(data[currentIndex]);
currentIndex++;
}
}
// Skip the quote.
if (quotedValue)
currentIndex++;
// Skip any whitespace.
while (currentIndex < data.Length && CharIsSpaceOrTab(data[currentIndex]))
currentIndex++;
// Return if this is last value.
if (currentIndex == data.Length)
{
parsedIndex = currentIndex;
return StringBuilderCache.GetStringAndRelease(sb);
}
// A key-value pair should end with ','
if (data[currentIndex++] != ',')
{
parsedIndex = currentIndex;
return null;
}
// Skip space and tab
while (currentIndex < data.Length && CharIsSpaceOrTab(data[currentIndex]))
{
currentIndex++;
}
// Set parsedIndex to current valid char.
parsedIndex = currentIndex;
return StringBuilderCache.GetStringAndRelease(sb);
}