After reverting https://github.com/dotnet/coreclr/pull/2617, which resulted in backslash escapes being included incorrectly, replaces it with a simpler fix that avoids the same allocations and copies by simply passing in the overarching StringBuilder. The call sites throw away the StringBuilder if an exception occurs, so we can simply write to it directly rather than first writing to a temporary and then dumping that temporary into the overarching result.
//
// The pos should point to a quote character. This method will
- // get the string encloed by the quote character.
+ // append to the result StringBuilder the string encloed by the quote character.
//
internal static int ParseQuoteString(String format, int pos, StringBuilder result)
{
break;
case '\'':
case '\"':
- StringBuilder enquotedString = new StringBuilder();
- tokenLen = ParseQuoteString(format, i, enquotedString);
- result.Append(enquotedString);
+ tokenLen = ParseQuoteString(format, i, result);
break;
case '%':
// Optional format character.
break;
case '\'':
case '\"':
- StringBuilder enquotedString = new StringBuilder();
- tokenLen = DateTimeFormat.ParseQuoteString(format, i, enquotedString);
- result.Append(enquotedString);
+ tokenLen = DateTimeFormat.ParseQuoteString(format, i, result);
break;
case '%':
// Optional format character.