Beispiel #1
0
 public StringBuffer(IArrayPool <char> bufferPool, int initalSize)
 {
     Class6.yDnXvgqzyB5jw();
     this(BufferUtils.RentBuffer(bufferPool, initalSize));
 }
Beispiel #2
0
        public static void WriteEscapedJavaScriptString(TextWriter writer, string s, char delimiter, bool appendDelimiters, bool[] charEscapeFlags, StringEscapeHandling stringEscapeHandling, IArrayPool <char> bufferPool, ref char[] writeBuffer)
        {
            int    length;
            char   chr;
            string str;

            if (appendDelimiters)
            {
                writer.Write(delimiter);
            }
            if (!string.IsNullOrEmpty(s))
            {
                int escape = JavaScriptUtils.FirstCharToEscape(s, charEscapeFlags, stringEscapeHandling);
                if (escape != -1)
                {
                    if (escape != 0)
                    {
                        if (writeBuffer == null || (int)writeBuffer.Length < escape)
                        {
                            writeBuffer = BufferUtils.EnsureBufferSize(bufferPool, escape, writeBuffer);
                        }
                        s.CopyTo(0, writeBuffer, 0, escape);
                        writer.Write(writeBuffer, 0, escape);
                    }
                    for (int i = escape; i < s.Length; i++)
                    {
                        chr = s[i];
                        if (chr >= (char)((int)charEscapeFlags.Length) || charEscapeFlags[chr])
                        {
                            if (chr <= '\\')
                            {
                                switch (chr)
                                {
                                case '\b':
                                {
                                    str = "\\b";
                                    break;
                                }

                                case '\t':
                                {
                                    str = "\\t";
                                    break;
                                }

                                case '\n':
                                {
                                    str = "\\n";
                                    break;
                                }

                                case '\v':
                                {
                                    goto Label0;
                                }

                                case '\f':
                                {
                                    str = "\\f";
                                    break;
                                }

                                case '\r':
                                {
                                    str = "\\r";
                                    break;
                                }

                                default:
                                {
                                    if (chr == '\\')
                                    {
                                        str = "\\\\";
                                        break;
                                    }
                                    else
                                    {
                                        goto Label0;
                                    }
                                }
                                }
                            }
                            else if (chr == '\u0085')
                            {
                                str = "\\u0085";
                            }
                            else if (chr == '\u2028')
                            {
                                str = "\\u2028";
                            }
                            else
                            {
                                if (chr != '\u2029')
                                {
                                    goto Label0;
                                }
                                str = "\\u2029";
                            }
Label1:
                            if (str != null)
                            {
                                bool flag = string.Equals(str, "!");
                                if (i > escape)
                                {
                                    length = i - escape + (flag ? 6 : 0);
                                    int num = (flag ? 6 : 0);
                                    if (writeBuffer == null || (int)writeBuffer.Length < length)
                                    {
                                        char[] chrArray = BufferUtils.RentBuffer(bufferPool, length);
                                        if (flag)
                                        {
                                            Array.Copy(writeBuffer, chrArray, 6);
                                        }
                                        BufferUtils.ReturnBuffer(bufferPool, writeBuffer);
                                        writeBuffer = chrArray;
                                    }
                                    s.CopyTo(escape, writeBuffer, num, length - num);
                                    writer.Write(writeBuffer, num, length - num);
                                }
                                escape = i + 1;
                                if (flag)
                                {
                                    writer.Write(writeBuffer, 0, 6);
                                }
                                else
                                {
                                    writer.Write(str);
                                }
                            }
                        }
                    }
                    length = s.Length - escape;
                    if (length > 0)
                    {
                        if (writeBuffer == null || (int)writeBuffer.Length < length)
                        {
                            writeBuffer = BufferUtils.EnsureBufferSize(bufferPool, length, writeBuffer);
                        }
                        s.CopyTo(escape, writeBuffer, 0, length);
                        writer.Write(writeBuffer, 0, length);
                    }
                }
                else
                {
                    writer.Write(s);
                }
            }
            if (appendDelimiters)
            {
                writer.Write(delimiter);
            }
            return;

Label0:
            if (chr >= (char)((int)charEscapeFlags.Length))
            {
                if (stringEscapeHandling == StringEscapeHandling.EscapeNonAscii)
                {
                    goto Label3;
                }
                str = null;
                goto Label1;
            }
            if (chr == '\'' && stringEscapeHandling != StringEscapeHandling.EscapeHtml)
            {
                str = "\\'";
                goto Label1;
            }
            else if (chr != '\"' || stringEscapeHandling == StringEscapeHandling.EscapeHtml)
            {
                if (writeBuffer == null || (int)writeBuffer.Length < 6)
                {
                    writeBuffer = BufferUtils.EnsureBufferSize(bufferPool, 6, writeBuffer);
                }
                StringUtils.ToCharAsUnicode(chr, writeBuffer);
                str = "!";
                goto Label1;
            }
            else
            {
                str = "\\\"";
                goto Label1;
            }
        }
Beispiel #3
0
        public static void WriteEscapedJavaScriptString(TextWriter writer, string s, char delimiter, bool appendDelimiters,
                                                        bool[] charEscapeFlags, StringEscapeHandling stringEscapeHandling, IArrayPool <char> bufferPool, ref char[] writeBuffer)
        {
            // leading delimiter
            if (appendDelimiters)
            {
                writer.Write(delimiter);
            }

            if (s != null)
            {
                int lastWritePosition = 0;

                for (int i = 0; i < s.Length; i++)
                {
                    var c = s[i];

                    if (c < charEscapeFlags.Length && !charEscapeFlags[c])
                    {
                        continue;
                    }

                    string escapedValue;

                    switch (c)
                    {
                    case '\t':
                        escapedValue = @"\t";
                        break;

                    case '\n':
                        escapedValue = @"\n";
                        break;

                    case '\r':
                        escapedValue = @"\r";
                        break;

                    case '\f':
                        escapedValue = @"\f";
                        break;

                    case '\b':
                        escapedValue = @"\b";
                        break;

                    case '\\':
                        escapedValue = @"\\";
                        break;

                    case '\u0085':     // Next Line
                        escapedValue = @"\u0085";
                        break;

                    case '\u2028':     // Line Separator
                        escapedValue = @"\u2028";
                        break;

                    case '\u2029':     // Paragraph Separator
                        escapedValue = @"\u2029";
                        break;

                    default:
                        if (c < charEscapeFlags.Length || stringEscapeHandling == StringEscapeHandling.EscapeNonAscii)
                        {
                            if (c == '\'' && stringEscapeHandling != StringEscapeHandling.EscapeHtml)
                            {
                                escapedValue = @"\'";
                            }
                            else if (c == '"' && stringEscapeHandling != StringEscapeHandling.EscapeHtml)
                            {
                                escapedValue = @"\""";
                            }
                            else
                            {
                                if (writeBuffer == null || writeBuffer.Length < UnicodeTextLength)
                                {
                                    writeBuffer = BufferUtils.EnsureBufferSize(bufferPool, UnicodeTextLength, writeBuffer);
                                }

                                StringUtils.ToCharAsUnicode(c, writeBuffer);

                                // slightly hacky but it saves multiple conditions in if test
                                escapedValue = EscapedUnicodeText;
                            }
                        }
                        else
                        {
                            escapedValue = null;
                        }
                        break;
                    }

                    if (escapedValue == null)
                    {
                        continue;
                    }

                    bool isEscapedUnicodeText = string.Equals(escapedValue, EscapedUnicodeText);

                    if (i > lastWritePosition)
                    {
                        int length = i - lastWritePosition + ((isEscapedUnicodeText) ? UnicodeTextLength : 0);
                        int start  = (isEscapedUnicodeText) ? UnicodeTextLength : 0;

                        if (writeBuffer == null || writeBuffer.Length < length)
                        {
                            char[] newBuffer = BufferUtils.RentBuffer(bufferPool, length);

                            // the unicode text is already in the buffer
                            // copy it over when creating new buffer
                            if (isEscapedUnicodeText)
                            {
                                Array.Copy(writeBuffer, newBuffer, UnicodeTextLength);
                            }

                            BufferUtils.ReturnBuffer(bufferPool, writeBuffer);

                            writeBuffer = newBuffer;
                        }

                        s.CopyTo(lastWritePosition, writeBuffer, start, length - start);

                        // write unchanged chars before writing escaped text
                        writer.Write(writeBuffer, start, length - start);
                    }

                    lastWritePosition = i + 1;
                    if (!isEscapedUnicodeText)
                    {
                        writer.Write(escapedValue);
                    }
                    else
                    {
                        writer.Write(writeBuffer, 0, UnicodeTextLength);
                    }
                }

                if (lastWritePosition == 0)
                {
                    // no escaped text, write entire string
                    writer.Write(s);
                }
                else
                {
                    int length = s.Length - lastWritePosition;

                    if (writeBuffer == null || writeBuffer.Length < length)
                    {
                        writeBuffer = BufferUtils.EnsureBufferSize(bufferPool, length, writeBuffer);
                    }

                    s.CopyTo(lastWritePosition, writeBuffer, 0, length);

                    // write remaining text
                    writer.Write(writeBuffer, 0, length);
                }
            }

            // trailing delimiter
            if (appendDelimiters)
            {
                writer.Write(delimiter);
            }
        }
        public static void WriteEscapedJavaScriptString(TextWriter writer, string?s, char delimiter, bool appendDelimiters,
                                                        bool[] charEscapeFlags, StringEscapeHandling stringEscapeHandling, IArrayPool <char>?bufferPool, ref char[]?writeBuffer)
        {
            // leading delimiter
            if (appendDelimiters)
            {
                writer.Write(delimiter);
            }

            if (!StringUtils.IsNullOrEmpty(s))
            {
                int lastWritePosition = FirstCharToEscape(s, charEscapeFlags, stringEscapeHandling);
                if (lastWritePosition == -1)
                {
                    writer.Write(s);
                }
                else
                {
                    if (lastWritePosition != 0)
                    {
                        if (writeBuffer == null || writeBuffer.Length < lastWritePosition)
                        {
                            writeBuffer = BufferUtils.EnsureBufferSize(bufferPool, lastWritePosition, writeBuffer);
                        }

                        // write unchanged chars at start of text.
                        s.CopyTo(0, writeBuffer, 0, lastWritePosition);
                        writer.Write(writeBuffer, 0, lastWritePosition);
                    }

                    int length;
                    for (int i = lastWritePosition; i < s.Length; i++)
                    {
                        char c = s[i];

                        if (c < charEscapeFlags.Length && !charEscapeFlags[c])
                        {
                            continue;
                        }

                        string?escapedValue;

                        switch (c)
                        {
                        case '\t':
                            escapedValue = @"\t";
                            break;

                        case '\n':
                            escapedValue = @"\n";
                            break;

                        case '\r':
                            escapedValue = @"\r";
                            break;

                        case '\f':
                            escapedValue = @"\f";
                            break;

                        case '\b':
                            escapedValue = @"\b";
                            break;

                        case '\\':
                            escapedValue = @"\\";
                            break;

                        case '\u0085':     // Next Line
                            escapedValue = @"\u0085";
                            break;

                        case '\u2028':     // Line Separator
                            escapedValue = @"\u2028";
                            break;

                        case '\u2029':     // Paragraph Separator
                            escapedValue = @"\u2029";
                            break;

                        default:
                            if (c < charEscapeFlags.Length || stringEscapeHandling == StringEscapeHandling.EscapeNonAscii)
                            {
                                if (c == '\'' && stringEscapeHandling != StringEscapeHandling.EscapeHtml)
                                {
                                    escapedValue = @"\'";
                                }
                                else if (c == '"' && stringEscapeHandling != StringEscapeHandling.EscapeHtml)
                                {
                                    escapedValue = @"\""";
                                }
                                else
                                {
                                    if (writeBuffer == null || writeBuffer.Length < UnicodeTextLength)
                                    {
                                        writeBuffer = BufferUtils.EnsureBufferSize(bufferPool, UnicodeTextLength, writeBuffer);
                                    }

                                    StringUtils.ToCharAsUnicode(c, writeBuffer !);

                                    // slightly hacky but it saves multiple conditions in if test
                                    escapedValue = EscapedUnicodeText;
                                }
                            }
                            else
                            {
                                escapedValue = null;
                            }
                            break;
                        }

                        if (escapedValue == null)
                        {
                            continue;
                        }

                        bool isEscapedUnicodeText = string.Equals(escapedValue, EscapedUnicodeText, StringComparison.Ordinal);

                        if (i > lastWritePosition)
                        {
                            length = i - lastWritePosition + ((isEscapedUnicodeText) ? UnicodeTextLength : 0);
                            int start = (isEscapedUnicodeText) ? UnicodeTextLength : 0;

                            if (writeBuffer == null || writeBuffer.Length < length)
                            {
                                char[] newBuffer = BufferUtils.RentBuffer(bufferPool, length);

                                // the unicode text is already in the buffer
                                // copy it over when creating new buffer
                                if (isEscapedUnicodeText)
                                {
                                    MiscellaneousUtils.Assert(writeBuffer != null, "Write buffer should never be null because it is set when the escaped unicode text is encountered.");

                                    Array.Copy(writeBuffer, newBuffer, UnicodeTextLength);
                                }

                                BufferUtils.ReturnBuffer(bufferPool, writeBuffer);

                                writeBuffer = newBuffer;
                            }

                            s.CopyTo(lastWritePosition, writeBuffer, start, length - start);

                            // write unchanged chars before writing escaped text
                            writer.Write(writeBuffer, start, length - start);
                        }

                        lastWritePosition = i + 1;
                        if (!isEscapedUnicodeText)
                        {
                            writer.Write(escapedValue);
                        }
                        else
                        {
                            writer.Write(writeBuffer, 0, UnicodeTextLength);
                        }
                    }

                    MiscellaneousUtils.Assert(lastWritePosition != 0);
                    length = s.Length - lastWritePosition;
                    if (length > 0)
                    {
                        if (writeBuffer == null || writeBuffer.Length < length)
                        {
                            writeBuffer = BufferUtils.EnsureBufferSize(bufferPool, length, writeBuffer);
                        }

                        s.CopyTo(lastWritePosition, writeBuffer, 0, length);

                        // write remaining text
                        writer.Write(writeBuffer, 0, length);
                    }
                }
            }

            // trailing delimiter
            if (appendDelimiters)
            {
                writer.Write(delimiter);
            }
        }
Beispiel #5
0
 public StringBuffer(IArrayPool <char> bufferPool, int initalSize) : this(BufferUtils.RentBuffer(bufferPool, initalSize))
 {
 }
        public static void WriteEscapedJavaScriptString(TextWriter writer, string s, char delimiter, bool appendDelimiters, bool[] charEscapeFlags, StringEscapeHandling stringEscapeHandling, IArrayPool <char> bufferPool, ref char[] writeBuffer)
        {
            if (appendDelimiters)
            {
                writer.Write(delimiter);
            }
            if (s != null)
            {
                int sourceIndex = 0;
                for (int i = 0; i < s.Length; i++)
                {
                    char index = s[i];
                    if ((index >= charEscapeFlags.Length) || charEscapeFlags[index])
                    {
                        string str;
                        switch (index)
                        {
                        case '\x0085':
                            str = @"\u0085";
                            break;

                        case '\u2028':
                            str = @"\u2028";
                            break;

                        case '\u2029':
                            str = @"\u2029";
                            break;

                        case '\b':
                            str = @"\b";
                            break;

                        case '\t':
                            str = @"\t";
                            break;

                        case '\n':
                            str = @"\n";
                            break;

                        case '\f':
                            str = @"\f";
                            break;

                        case '\r':
                            str = @"\r";
                            break;

                        case '\\':
                            str = @"\\";
                            break;

                        default:
                            if ((index < charEscapeFlags.Length) || (stringEscapeHandling == StringEscapeHandling.EscapeNonAscii))
                            {
                                if ((index == '\'') && (stringEscapeHandling != StringEscapeHandling.EscapeHtml))
                                {
                                    str = @"\'";
                                }
                                else if ((index == '"') && (stringEscapeHandling != StringEscapeHandling.EscapeHtml))
                                {
                                    str = "\\\"";
                                }
                                else
                                {
                                    if ((writeBuffer == null) || (writeBuffer.Length < 6))
                                    {
                                        writeBuffer = BufferUtils.EnsureBufferSize(bufferPool, 6, writeBuffer);
                                    }
                                    StringUtils.ToCharAsUnicode(index, writeBuffer);
                                    str = "!";
                                }
                            }
                            else
                            {
                                str = null;
                            }
                            break;
                        }
                        if (str != null)
                        {
                            bool flag = string.Equals(str, "!");
                            if (i > sourceIndex)
                            {
                                int minSize          = (i - sourceIndex) + (flag ? 6 : 0);
                                int destinationIndex = flag ? 6 : 0;
                                if ((writeBuffer == null) || (writeBuffer.Length < minSize))
                                {
                                    char[] destinationArray = BufferUtils.RentBuffer(bufferPool, minSize);
                                    if (flag)
                                    {
                                        Array.Copy(writeBuffer, destinationArray, 6);
                                    }
                                    BufferUtils.ReturnBuffer(bufferPool, writeBuffer);
                                    writeBuffer = destinationArray;
                                }
                                s.CopyTo(sourceIndex, writeBuffer, destinationIndex, minSize - destinationIndex);
                                writer.Write(writeBuffer, destinationIndex, minSize - destinationIndex);
                            }
                            sourceIndex = i + 1;
                            if (!flag)
                            {
                                writer.Write(str);
                            }
                            else
                            {
                                writer.Write(writeBuffer, 0, 6);
                            }
                        }
                    }
                }
                if (sourceIndex == 0)
                {
                    writer.Write(s);
                }
                else
                {
                    int size = s.Length - sourceIndex;
                    if ((writeBuffer == null) || (writeBuffer.Length < size))
                    {
                        writeBuffer = BufferUtils.EnsureBufferSize(bufferPool, size, writeBuffer);
                    }
                    s.CopyTo(sourceIndex, writeBuffer, 0, size);
                    writer.Write(writeBuffer, 0, size);
                }
            }
            if (appendDelimiters)
            {
                writer.Write(delimiter);
            }
        }
Beispiel #7
0
 // Token: 0x0600104A RID: 4170 RVA: 0x0001240C File Offset: 0x0001060C
 public StringBuffer(IArrayPool <char> bufferPool, int initalSize)
 {
     this = new StringBuffer(BufferUtils.RentBuffer(bufferPool, initalSize));
 }
Beispiel #8
0
        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);
            }
        }