public static void WriteEscapedJavaScriptString([Nullable(1)] TextWriter writer, string s, char delimiter, bool appendDelimiters, [Nullable(1)] bool[] charEscapeFlags, StringEscapeHandling stringEscapeHandling, IArrayPool <char> bufferPool, ref char[] writeBuffer) { if (appendDelimiters) { writer.Write(delimiter); } if (!StringUtils.IsNullOrEmpty(s)) { int num = JavaScriptUtils.FirstCharToEscape(s, charEscapeFlags, stringEscapeHandling); if (num == -1) { writer.Write(s); } else { if (num != 0) { if (writeBuffer == null || writeBuffer.Length < num) { writeBuffer = BufferUtils.EnsureBufferSize(bufferPool, num, writeBuffer); } s.CopyTo(0, writeBuffer, 0, num); writer.Write(writeBuffer, 0, num); } int num2; for (int i = num; i < s.Length; i++) { char c = s[i]; if ((int)c >= charEscapeFlags.Length || charEscapeFlags[(int)c]) { string text; if (c <= '\\') { switch (c) { case '\b': text = "\\b"; break; case '\t': text = "\\t"; break; case '\n': text = "\\n"; break; case '\v': goto IL_10D; case '\f': text = "\\f"; break; case '\r': text = "\\r"; break; default: if (c != '\\') { goto IL_10D; } text = "\\\\"; break; } } else if (c != '\u0085') { if (c != '\u2028') { if (c != '\u2029') { goto IL_10D; } text = "\\u2029"; } else { text = "\\u2028"; } } else { text = "\\u0085"; } IL_185: if (text == null) { goto IL_229; } bool flag = string.Equals(text, "!", StringComparison.Ordinal); if (i > num) { num2 = i - num + (flag ? 6 : 0); int num3 = flag ? 6 : 0; if (writeBuffer == null || writeBuffer.Length < num2) { char[] array = BufferUtils.RentBuffer(bufferPool, num2); if (flag) { Array.Copy(writeBuffer, array, 6); } BufferUtils.ReturnBuffer(bufferPool, writeBuffer); writeBuffer = array; } s.CopyTo(num, writeBuffer, num3, num2 - num3); writer.Write(writeBuffer, num3, num2 - num3); } num = i + 1; if (!flag) { writer.Write(text); goto IL_229; } writer.Write(writeBuffer, 0, 6); goto IL_229; IL_10D: if ((int)c >= charEscapeFlags.Length) { if (stringEscapeHandling != StringEscapeHandling.EscapeNonAscii) { text = null; goto IL_185; } } if (c == '\'' && stringEscapeHandling != StringEscapeHandling.EscapeHtml) { text = "\\'"; goto IL_185; } if (c == '"' && stringEscapeHandling != StringEscapeHandling.EscapeHtml) { text = "\\\""; goto IL_185; } if (writeBuffer == null || writeBuffer.Length < 6) { writeBuffer = BufferUtils.EnsureBufferSize(bufferPool, 6, writeBuffer); } StringUtils.ToCharAsUnicode(c, writeBuffer); text = "!"; goto IL_185; } IL_229 :; } num2 = s.Length - num; if (num2 > 0) { if (writeBuffer == null || writeBuffer.Length < num2) { writeBuffer = BufferUtils.EnsureBufferSize(bufferPool, num2, writeBuffer); } s.CopyTo(num, writeBuffer, 0, num2); writer.Write(writeBuffer, 0, num2); } } } if (appendDelimiters) { writer.Write(delimiter); } }