internal static string Encode5987(string input) { StringBuilder stringBuilder = StringBuilderCache.Acquire(16); byte[] numArray = ArrayPool <byte> .Shared.Rent(Encoding.UTF8.GetMaxByteCount(input.Length)); int bytes = Encoding.UTF8.GetBytes(input, 0, input.Length, numArray, 0); stringBuilder.Append("utf-8''"); for (int index = 0; index < bytes; ++index) { byte c = numArray[index]; if (c > (byte)127) { HeaderUtilities.AddHexEscaped(c, stringBuilder); } else if (!HttpRuleParser.IsTokenChar((char)c) || c == (byte)42 || (c == (byte)39 || c == (byte)37)) { HeaderUtilities.AddHexEscaped(c, stringBuilder); } else { stringBuilder.Append((char)c); } } Array.Clear((Array)numArray, 0, bytes); ArrayPool <byte> .Shared.Return(numArray, false); return(StringBuilderCache.GetStringAndRelease(stringBuilder)); }