예제 #1
0
        public void Write(int ucs32Literal, IFallback fallback)
        {
            int count = 1;

            if (ucs32Literal > 65535)
            {
                if (fallback != null && fallback is HtmlWriter)
                {
                    uint num  = (uint)ucs32Literal;
                    int  num2 = (num < 10U) ? 1 : ((num < 100U) ? 2 : ((num < 1000U) ? 3 : ((num < 10000U) ? 4 : ((num < 100000U) ? 5 : ((num < 1000000U) ? 6 : 7)))));
                    int  num3 = 2 + num2;
                    this.stringBuffer[0]    = '&';
                    this.stringBuffer[1]    = '#';
                    this.stringBuffer[num3] = ';';
                    while (num != 0U)
                    {
                        uint num4 = num % 10U;
                        this.stringBuffer[--num3] = (char)(num4 + 48U);
                        num /= 10U;
                    }
                    count = 3 + num2;
                    this.Write(this.stringBuffer, 0, count, null);
                    return;
                }
                this.stringBuffer[0] = ParseSupport.HighSurrogateCharFromUcs4(ucs32Literal);
                this.stringBuffer[1] = ParseSupport.LowSurrogateCharFromUcs4(ucs32Literal);
                count = 2;
            }
            else
            {
                this.stringBuffer[0] = (char)ucs32Literal;
            }
            this.Write(this.stringBuffer, 0, count, fallback);
        }
예제 #2
0
        internal ITextSinkEx WriteAttributeName()
        {
            InternalDebug.Assert(this.outputState >= OutputState.WritingTagName);

            if (this.outputState != OutputState.WritingAttributeName)
            {
                if (this.outputState > OutputState.BeforeAttribute)
                {
                    this.OutputAttributeEnd();
                }
#if false
                if (this.lineLength > 255 && this.autoNewLines)
                {
                    if (this.lineLength > this.longestLineLength)
                    {
                        this.longestLineLength = this.lineLength;
                    }

                    this.output.Write("\r\n");
                    this.lineLength = 0;
                }
#endif
                this.output.Write(' ');
                this.lineLength++;
            }

            this.outputState = OutputState.WritingAttributeName;

            this.fallback = null;
            return(this);
        }
예제 #3
0
        internal ITextSinkEx WriteUnstructuredTagContent()
        {
            InternalDebug.Assert(this.outputState == OutputState.WritingUnstructuredTagContent);

            this.fallback = null;
            return(this);
        }
예제 #4
0
 public void Write(string text, int offset, int count, IFallback fallback)
 {
     if (stringBuffer.Length < count)
     {
         stringBuffer = new char[count * 2];
     }
     text.CopyTo(offset, stringBuffer, 0, count);
     Write(stringBuffer, 0, count, fallback);
 }
예제 #5
0
        internal ITextSinkEx WriteTagName()
        {
            InternalDebug.Assert(this.outputState == OutputState.TagStarted ||
                                 this.outputState == OutputState.WritingTagName);

            this.outputState = OutputState.WritingTagName;

            this.fallback = null;
            return(this);
        }
예제 #6
0
 internal ITextSinkEx WriteAttributeValue()
 {
     if (outputState != OutputState.WritingAttributeValue)
     {
         output.Write("=\"");
         lineLength += 2;
     }
     outputState = OutputState.WritingAttributeValue;
     fallback    = this;
     return(this);
 }
        public override void Write(char[] buffer, int offset, int count, IFallback fallback)
        {
            if (fallback == null && !this.lineModeEncoding && this.lineBufferCount + count <= this.lineBuffer.Length - this.minCharsEncode)
            {
                if (count == 1)
                {
                    this.lineBuffer[this.lineBufferCount++] = buffer[offset];
                    return;
                }
                else if (count < 16)
                {
                    if (0 != (count & 8))
                    {
                        this.lineBuffer[this.lineBufferCount]     = buffer[offset];
                        this.lineBuffer[this.lineBufferCount + 1] = buffer[offset + 1];
                        this.lineBuffer[this.lineBufferCount + 2] = buffer[offset + 2];
                        this.lineBuffer[this.lineBufferCount + 3] = buffer[offset + 3];
                        this.lineBuffer[this.lineBufferCount + 4] = buffer[offset + 4];
                        this.lineBuffer[this.lineBufferCount + 5] = buffer[offset + 5];
                        this.lineBuffer[this.lineBufferCount + 6] = buffer[offset + 6];
                        this.lineBuffer[this.lineBufferCount + 7] = buffer[offset + 7];
                        this.lineBufferCount += 8;
                        offset += 8;
                    }

                    if (0 != (count & 4))
                    {
                        this.lineBuffer[this.lineBufferCount]     = buffer[offset];
                        this.lineBuffer[this.lineBufferCount + 1] = buffer[offset + 1];
                        this.lineBuffer[this.lineBufferCount + 2] = buffer[offset + 2];
                        this.lineBuffer[this.lineBufferCount + 3] = buffer[offset + 3];
                        this.lineBufferCount += 4;
                        offset += 4;
                    }

                    if (0 != (count & 2))
                    {
                        this.lineBuffer[this.lineBufferCount]     = buffer[offset];
                        this.lineBuffer[this.lineBufferCount + 1] = buffer[offset + 1];
                        this.lineBufferCount += 2;
                        offset += 2;
                    }

                    if (0 != (count & 1))
                    {
                        this.lineBuffer[this.lineBufferCount++] = buffer[offset];
                    }

                    return;
                }
            }

            WriteComplete(buffer, offset, count, fallback);
        }
예제 #8
0
 public void Write(int ucs32Literal, IFallback fallback)
 {
     if (ucs32Literal > 65535)
     {
         stringBuffer[0] = ParseSupport.HighSurrogateCharFromUcs4(ucs32Literal);
         stringBuffer[1] = ParseSupport.LowSurrogateCharFromUcs4(ucs32Literal);
     }
     else
     {
         stringBuffer[0] = (char)ucs32Literal;
     }
     Write(stringBuffer, 0, (ucs32Literal > 65535) ? 2 : 1, fallback);
 }
예제 #9
0
        public void Write(int ucs32Literal, IFallback fallback)
        {
            if (ucs32Literal > 0xFFFF)
            {
                this.stringBuffer[0] = ParseSupport.HighSurrogateCharFromUcs4(ucs32Literal);
                this.stringBuffer[1] = ParseSupport.LowSurrogateCharFromUcs4(ucs32Literal);
            }
            else
            {
                this.stringBuffer[0] = (char)ucs32Literal;
            }

            this.Write(this.stringBuffer, 0, ucs32Literal > 0xFFFF ? 2 : 1, fallback);
        }
예제 #10
0
 internal ITextSinkEx WriteText()
 {
     if (outputState != OutputState.OutsideTag)
     {
         WriteTagEnd();
     }
     allowWspBeforeFollowingTag = false;
     if (lastWhitespace)
     {
         OutputLastWhitespace('\u3000');
     }
     fallback = this;
     return(this);
 }
예제 #11
0
 public override void Write(char[] buffer, int offset, int count, IFallback fallback)
 {
     if (fallback == null && !lineModeEncoding && lineBufferCount + count <= lineBuffer.Length - minCharsEncode)
     {
         if (count == 1)
         {
             lineBuffer[lineBufferCount++] = buffer[offset];
             return;
         }
         if (count < 16)
         {
             if ((count & 8) != 0)
             {
                 lineBuffer[lineBufferCount]     = buffer[offset];
                 lineBuffer[lineBufferCount + 1] = buffer[offset + 1];
                 lineBuffer[lineBufferCount + 2] = buffer[offset + 2];
                 lineBuffer[lineBufferCount + 3] = buffer[offset + 3];
                 lineBuffer[lineBufferCount + 4] = buffer[offset + 4];
                 lineBuffer[lineBufferCount + 5] = buffer[offset + 5];
                 lineBuffer[lineBufferCount + 6] = buffer[offset + 6];
                 lineBuffer[lineBufferCount + 7] = buffer[offset + 7];
                 lineBufferCount += 8;
                 offset          += 8;
             }
             if ((count & 4) != 0)
             {
                 lineBuffer[lineBufferCount]     = buffer[offset];
                 lineBuffer[lineBufferCount + 1] = buffer[offset + 1];
                 lineBuffer[lineBufferCount + 2] = buffer[offset + 2];
                 lineBuffer[lineBufferCount + 3] = buffer[offset + 3];
                 lineBufferCount += 4;
                 offset          += 4;
             }
             if ((count & 2) != 0)
             {
                 lineBuffer[lineBufferCount]     = buffer[offset];
                 lineBuffer[lineBufferCount + 1] = buffer[offset + 1];
                 lineBufferCount += 2;
                 offset          += 2;
             }
             if ((count & 1) != 0)
             {
                 lineBuffer[lineBufferCount++] = buffer[offset];
             }
             return;
         }
     }
     WriteComplete(buffer, offset, count, fallback);
 }
예제 #12
0
 internal ITextSinkEx WriteAttributeName()
 {
     if (outputState != OutputState.WritingAttributeName)
     {
         if (outputState > OutputState.BeforeAttribute)
         {
             OutputAttributeEnd();
         }
         output.Write(' ');
         lineLength++;
     }
     outputState = OutputState.WritingAttributeName;
     fallback    = null;
     return(this);
 }
예제 #13
0
        internal ITextSinkEx WriteAttributeValue()
        {
            InternalDebug.Assert(this.outputState >= OutputState.WritingAttributeName);

            if (this.outputState != OutputState.WritingAttributeValue)
            {
                this.output.Write("=\"");
                this.lineLength += 2;
            }

            this.outputState = OutputState.WritingAttributeValue;

            this.fallback = this;
            return(this);
        }
예제 #14
0
        internal ITextSinkEx WriteText()
        {
            if (this.outputState != OutputState.OutsideTag)
            {
                this.WriteTagEnd();
            }

            this.allowWspBeforeFollowingTag = false;

            if (this.lastWhitespace)
            {
                InternalDebug.Assert(ParseSupport.FarEastNonHanguelChar('\x3000'));
                this.OutputLastWhitespace('\x3000');
            }

            this.fallback = this;
            return(this);
        }
예제 #15
0
        private static bool IsUnsafeCharacter(
            char ch,
            byte[] unsafeAsciiMap,
            byte unsafeAsciiMask,
            bool hasUnsafeUnicode,
            bool isFirstChar,
            IFallback fallback)
        {
            if (unsafeAsciiMap == null)
            {
                return(false);
            }

            var result = ((ch >= unsafeAsciiMap.Length) ? false : (unsafeAsciiMap[(int)ch] & unsafeAsciiMask) != 0);

            result = result || (hasUnsafeUnicode && ch >= 0x7F && fallback.IsUnsafeUnicode(ch, isFirstChar));
            return(result);
        }
예제 #16
0
        public override void Write(char[] buffer, int offset, int count, IFallback fallback)
        {
            InternalDebug.Assert(!endOfFile);

            byte unsafeAsciiMask  = 0;
            var  unsafeAsciiMap   = fallback == null ? null : fallback.GetUnsafeAsciiMap(out unsafeAsciiMask);
            var  hasUnsafeUnicode = fallback == null ? false : fallback.HasUnsafeUnicode();

            if (cache.Length != 0 || canRestart)
            {
                while (count != 0)
                {
                    char[] cacheBuffer;
                    int    cacheOffset;
                    int    cacheSpace;

                    if (fallback != null)
                    {
                        cache.GetBuffer(FallbackExpansionMax, out cacheBuffer, out cacheOffset, out cacheSpace);

                        var cacheOffsetStart = cacheOffset;

                        for (; 0 != count && cacheSpace != 0; count--, offset++)
                        {
                            var ch = buffer[offset];

                            if (IsUnsafeCharacter(ch, unsafeAsciiMap, unsafeAsciiMask, hasUnsafeUnicode, isFirstChar, fallback))
                            {
                                var cacheOffsetSave = cacheOffset;

                                if (!fallback.FallBackChar(ch, cacheBuffer, ref cacheOffset, cacheOffset + cacheSpace))
                                {
                                    break;
                                }
                                cacheSpace -= (cacheOffset - cacheOffsetSave);
                            }
                            else
                            {
                                cacheBuffer[cacheOffset++] = ch;
                                cacheSpace--;
                            }
                            isFirstChar = false;
                        }



                        cache.Commit(cacheOffset - cacheOffsetStart);
                    }
                    else
                    {
                        var minSpace = Math.Min(count, 256);

                        cache.GetBuffer(minSpace, out cacheBuffer, out cacheOffset, out cacheSpace);

                        var countToCopy = Math.Min(cacheSpace, count);

                        Buffer.BlockCopy(buffer, offset * 2, cacheBuffer, cacheOffset * 2, countToCopy * 2);

                        isFirstChar = false;
                        cache.Commit(countToCopy);

                        offset += countToCopy;
                        count  -= countToCopy;
                    }
                }
            }
            else if (pullSink != null)
            {
                char[] pullBuffer;
                int    pullOffset;
                int    pullSpace;

                pullSink.GetOutputBuffer(out pullBuffer, out pullOffset, out pullSpace);

                if (pullSpace != 0)
                {
                    if (fallback != null)
                    {
                        var pullStartOffset = pullOffset;

                        for (; 0 != count && 0 != pullSpace; count--, offset++)
                        {
                            var ch = buffer[offset];

                            if (IsUnsafeCharacter(ch, unsafeAsciiMap, unsafeAsciiMask, hasUnsafeUnicode, isFirstChar, fallback))
                            {
                                var pullOffsetSave = pullOffset;

                                if (!fallback.FallBackChar(ch, pullBuffer, ref pullOffset, pullOffset + pullSpace))
                                {
                                    break;
                                }

                                pullSpace -= (pullOffset - pullOffsetSave);
                            }
                            else
                            {
                                pullBuffer[pullOffset++] = ch;
                                pullSpace--;
                            }
                            isFirstChar = false;
                        }

                        pullSink.ReportOutput(pullOffset - pullStartOffset);
                    }
                    else
                    {
                        var countToCopy = Math.Min(pullSpace, count);

                        Buffer.BlockCopy(buffer, offset * 2, pullBuffer, pullOffset * 2, countToCopy * 2);

                        isFirstChar = false;
                        count      -= countToCopy;
                        offset     += countToCopy;

                        pullSink.ReportOutput(countToCopy);

                        pullOffset += countToCopy;
                        pullSpace  -= countToCopy;
                    }
                }



                while (count != 0)
                {
                    char[] cacheBuffer;
                    int    cacheOffset;
                    int    cacheSpace;

                    if (fallback != null)
                    {
                        cache.GetBuffer(FallbackExpansionMax, out cacheBuffer, out cacheOffset, out cacheSpace);

                        var cacheOffsetStart = cacheOffset;

                        for (; 0 != count && cacheSpace != 0; count--, offset++)
                        {
                            var ch = buffer[offset];

                            if (IsUnsafeCharacter(ch, unsafeAsciiMap, unsafeAsciiMask, hasUnsafeUnicode, isFirstChar, fallback))
                            {
                                var cacheOffsetSave = cacheOffset;

                                if (!fallback.FallBackChar(ch, cacheBuffer, ref cacheOffset, cacheOffset + cacheSpace))
                                {
                                    break;
                                }

                                cacheSpace -= (cacheOffset - cacheOffsetSave);
                            }
                            else
                            {
                                cacheBuffer[cacheOffset++] = ch;
                                cacheSpace--;
                            }
                            isFirstChar = false;
                        }



                        cache.Commit(cacheOffset - cacheOffsetStart);
                    }
                    else
                    {
                        var minSpace = Math.Min(count, 256);

                        cache.GetBuffer(minSpace, out cacheBuffer, out cacheOffset, out cacheSpace);

                        var countToCopy = Math.Min(cacheSpace, count);

                        Buffer.BlockCopy(buffer, offset * 2, cacheBuffer, cacheOffset * 2, countToCopy * 2);
                        isFirstChar = false;

                        cache.Commit(countToCopy);

                        offset += countToCopy;
                        count  -= countToCopy;
                    }
                }



                while (pullSpace != 0 && cache.Length != 0)
                {
                    char[] outputBuffer;
                    int    outputOffset;
                    int    outputCount;

                    cache.GetData(out outputBuffer, out outputOffset, out outputCount);

                    var countToCopy = Math.Min(outputCount, pullSpace);

                    Buffer.BlockCopy(outputBuffer, outputOffset * 2, pullBuffer, pullOffset * 2, countToCopy * 2);

                    cache.ReportRead(countToCopy);

                    pullSink.ReportOutput(countToCopy);

                    pullOffset += countToCopy;
                    pullSpace  -= countToCopy;
                }
            }
            else
            {
                if (fallback != null)
                {
                    char[] cacheBuffer;
                    int    cacheOffset;
                    int    cacheSpace;



                    cache.GetBuffer(1024, out cacheBuffer, out cacheOffset, out cacheSpace);

                    var cacheOffsetStart = cacheOffset;
                    var cacheSpaceStart  = cacheSpace;

                    while (count != 0)
                    {
                        for (; 0 != count && cacheSpace != 0; count--, offset++)
                        {
                            var ch = buffer[offset];

                            if (IsUnsafeCharacter(ch, unsafeAsciiMap, unsafeAsciiMask, hasUnsafeUnicode, isFirstChar, fallback))
                            {
                                var cacheOffsetSave = cacheOffset;

                                if (!fallback.FallBackChar(ch, cacheBuffer, ref cacheOffset, cacheOffset + cacheSpace))
                                {
                                    break;
                                }

                                cacheSpace -= (cacheOffset - cacheOffsetSave);
                            }
                            else
                            {
                                cacheBuffer[cacheOffset++] = ch;
                                cacheSpace--;
                            }
                            isFirstChar = false;
                        }

                        if (cacheOffset - cacheOffsetStart != 0)
                        {
                            pushSink.Write(cacheBuffer, cacheOffsetStart, cacheOffset - cacheOffsetStart);

                            cacheOffset = cacheOffsetStart;
                            cacheSpace  = cacheSpaceStart;
                        }
                    }
                }
                else
                {
                    if (count != 0)
                    {
                        pushSink.Write(buffer, offset, count);
                        isFirstChar = false;
                    }
                }
            }
        }
        // Token: 0x0600106F RID: 4207 RVA: 0x00078874 File Offset: 0x00076A74
        public override void Write(char[] buffer, int offset, int count, IFallback fallback)
        {
            byte unsafeAsciiMask = 0;

            byte[] unsafeAsciiMap   = (fallback == null) ? null : fallback.GetUnsafeAsciiMap(out unsafeAsciiMask);
            bool   hasUnsafeUnicode = fallback != null && fallback.HasUnsafeUnicode();

            if (this.cache.Length == 0)
            {
                if (!this.canRestart)
                {
                    if (this.pullSink != null)
                    {
                        char[] array;
                        int    num;
                        int    num2;
                        this.pullSink.GetOutputBuffer(out array, out num, out num2);
                        if (num2 != 0)
                        {
                            if (fallback != null)
                            {
                                int num3 = num;
                                while (count != 0 && num2 != 0)
                                {
                                    char c = buffer[offset];
                                    if (ConverterUnicodeOutput.IsUnsafeCharacter(c, unsafeAsciiMap, unsafeAsciiMask, hasUnsafeUnicode, this.isFirstChar, fallback))
                                    {
                                        int num4 = num;
                                        if (!fallback.FallBackChar(c, array, ref num, num + num2))
                                        {
                                            break;
                                        }
                                        num2 -= num - num4;
                                    }
                                    else
                                    {
                                        array[num++] = c;
                                        num2--;
                                    }
                                    this.isFirstChar = false;
                                    count--;
                                    offset++;
                                }
                                this.pullSink.ReportOutput(num - num3);
                            }
                            else
                            {
                                int num5 = Math.Min(num2, count);
                                Buffer.BlockCopy(buffer, offset * 2, array, num * 2, num5 * 2);
                                this.isFirstChar = false;
                                count           -= num5;
                                offset          += num5;
                                this.pullSink.ReportOutput(num5);
                                num  += num5;
                                num2 -= num5;
                            }
                        }
                        while (count != 0)
                        {
                            if (fallback != null)
                            {
                                char[] array2;
                                int    num6;
                                int    num7;
                                this.cache.GetBuffer(16, out array2, out num6, out num7);
                                int num8 = num6;
                                while (count != 0 && num7 != 0)
                                {
                                    char c2 = buffer[offset];
                                    if (ConverterUnicodeOutput.IsUnsafeCharacter(c2, unsafeAsciiMap, unsafeAsciiMask, hasUnsafeUnicode, this.isFirstChar, fallback))
                                    {
                                        int num9 = num6;
                                        if (!fallback.FallBackChar(c2, array2, ref num6, num6 + num7))
                                        {
                                            break;
                                        }
                                        num7 -= num6 - num9;
                                    }
                                    else
                                    {
                                        array2[num6++] = c2;
                                        num7--;
                                    }
                                    this.isFirstChar = false;
                                    count--;
                                    offset++;
                                }
                                this.cache.Commit(num6 - num8);
                            }
                            else
                            {
                                int    size = Math.Min(count, 256);
                                char[] array2;
                                int    num6;
                                int    num7;
                                this.cache.GetBuffer(size, out array2, out num6, out num7);
                                int num10 = Math.Min(num7, count);
                                Buffer.BlockCopy(buffer, offset * 2, array2, num6 * 2, num10 * 2);
                                this.isFirstChar = false;
                                this.cache.Commit(num10);
                                offset += num10;
                                count  -= num10;
                            }
                        }
                        while (num2 != 0)
                        {
                            if (this.cache.Length == 0)
                            {
                                return;
                            }
                            char[] src;
                            int    num11;
                            int    val;
                            this.cache.GetData(out src, out num11, out val);
                            int num12 = Math.Min(val, num2);
                            Buffer.BlockCopy(src, num11 * 2, array, num * 2, num12 * 2);
                            this.cache.ReportRead(num12);
                            this.pullSink.ReportOutput(num12);
                            num  += num12;
                            num2 -= num12;
                        }
                    }
                    else
                    {
                        if (fallback != null)
                        {
                            char[] array3;
                            int    num13;
                            int    num14;
                            this.cache.GetBuffer(1024, out array3, out num13, out num14);
                            int num15 = num13;
                            int num16 = num14;
                            while (count != 0)
                            {
                                while (count != 0 && num14 != 0)
                                {
                                    char c3 = buffer[offset];
                                    if (ConverterUnicodeOutput.IsUnsafeCharacter(c3, unsafeAsciiMap, unsafeAsciiMask, hasUnsafeUnicode, this.isFirstChar, fallback))
                                    {
                                        int num17 = num13;
                                        if (!fallback.FallBackChar(c3, array3, ref num13, num13 + num14))
                                        {
                                            break;
                                        }
                                        num14 -= num13 - num17;
                                    }
                                    else
                                    {
                                        array3[num13++] = c3;
                                        num14--;
                                    }
                                    this.isFirstChar = false;
                                    count--;
                                    offset++;
                                }
                                if (num13 - num15 != 0)
                                {
                                    this.pushSink.Write(array3, num15, num13 - num15);
                                    num13 = num15;
                                    num14 = num16;
                                }
                            }
                            return;
                        }
                        if (count != 0)
                        {
                            this.pushSink.Write(buffer, offset, count);
                            this.isFirstChar = false;
                        }
                    }
                    return;
                }
            }
            while (count != 0)
            {
                if (fallback != null)
                {
                    char[] array4;
                    int    num18;
                    int    num19;
                    this.cache.GetBuffer(16, out array4, out num18, out num19);
                    int num20 = num18;
                    while (count != 0 && num19 != 0)
                    {
                        char c4 = buffer[offset];
                        if (ConverterUnicodeOutput.IsUnsafeCharacter(c4, unsafeAsciiMap, unsafeAsciiMask, hasUnsafeUnicode, this.isFirstChar, fallback))
                        {
                            int num21 = num18;
                            if (!fallback.FallBackChar(c4, array4, ref num18, num18 + num19))
                            {
                                break;
                            }
                            num19 -= num18 - num21;
                        }
                        else
                        {
                            array4[num18++] = c4;
                            num19--;
                        }
                        this.isFirstChar = false;
                        count--;
                        offset++;
                    }
                    this.cache.Commit(num18 - num20);
                }
                else
                {
                    int    size2 = Math.Min(count, 256);
                    char[] array4;
                    int    num18;
                    int    num19;
                    this.cache.GetBuffer(size2, out array4, out num18, out num19);
                    int num22 = Math.Min(num19, count);
                    Buffer.BlockCopy(buffer, offset * 2, array4, num18 * 2, num22 * 2);
                    this.isFirstChar = false;
                    this.cache.Commit(num22);
                    offset += num22;
                    count  -= num22;
                }
            }
        }
예제 #18
0
 public void Write(char ch, IFallback fallback)
 {
     stringBuffer[0] = ch;
     Write(stringBuffer, 0, 1, fallback);
 }
        public void WriteComplete(char[] buffer, int offset, int count, IFallback fallback)
        {
            int num = 0;

            if (fallback != null || this.lineModeEncoding)
            {
                byte   b     = 0;
                byte[] array = null;
                uint   num2  = 0U;
                bool   flag  = false;
                bool   flag2 = false;
                if (fallback != null)
                {
                    array = fallback.GetUnsafeAsciiMap(out b);
                    if (array != null)
                    {
                        num2 = (uint)array.Length;
                    }
                    flag  = fallback.HasUnsafeUnicode();
                    flag2 = fallback.TreatNonAsciiAsUnsafe(this.encoding.WebName);
                }
                while (count != 0)
                {
                    while (count != 0 && this.lineBufferCount != this.lineBuffer.Length)
                    {
                        char c = buffer[offset];
                        if (fallback != null && (((uint)c < num2 && (array[(int)c] & b) != 0) || (!this.encodingCompleteUnicode && (c >= '\u007f' || c < ' ') && this.codePageMap.IsUnsafeExtendedCharacter(c)) || (flag && c >= '\u007f' && (flag2 || fallback.IsUnsafeUnicode(c, this.isFirstChar)))))
                        {
                            if (!fallback.FallBackChar(c, this.lineBuffer, ref this.lineBufferCount, this.lineBuffer.Length))
                            {
                                break;
                            }
                            this.isFirstChar = false;
                        }
                        else
                        {
                            this.lineBuffer[this.lineBufferCount++] = c;
                            this.isFirstChar = false;
                            if (this.lineModeEncoding)
                            {
                                if (c == '\n' || c == '\r')
                                {
                                    num = this.lineBufferCount;
                                }
                                else if (num > this.lineBuffer.Length - 256)
                                {
                                    count--;
                                    offset++;
                                    break;
                                }
                            }
                        }
                        count--;
                        offset++;
                    }
                    if (this.lineModeEncoding && (num > this.lineBuffer.Length - 256 || (this.lineBufferCount > this.lineBuffer.Length - 32 && num != 0)))
                    {
                        this.EncodeBuffer(this.lineBuffer, 0, num, false);
                        this.lineBufferCount -= num;
                        if (this.lineBufferCount != 0)
                        {
                            Buffer.BlockCopy(this.lineBuffer, num * 2, this.lineBuffer, 0, this.lineBufferCount * 2);
                        }
                    }
                    else if (this.lineBufferCount > this.lineBuffer.Length - Math.Max(this.minCharsEncode, 32))
                    {
                        this.EncodeBuffer(this.lineBuffer, 0, this.lineBufferCount, false);
                        this.lineBufferCount = 0;
                    }
                    num = 0;
                }
                return;
            }
            if (count > this.minCharsEncode)
            {
                if (this.lineBufferCount != 0)
                {
                    this.EncodeBuffer(this.lineBuffer, 0, this.lineBufferCount, false);
                    this.lineBufferCount = 0;
                }
                this.EncodeBuffer(buffer, offset, count, false);
                return;
            }
            Buffer.BlockCopy(buffer, offset * 2, this.lineBuffer, this.lineBufferCount * 2, count * 2);
            this.lineBufferCount += count;
            if (this.lineBufferCount > this.lineBuffer.Length - this.minCharsEncode)
            {
                this.EncodeBuffer(this.lineBuffer, 0, this.lineBufferCount, false);
                this.lineBufferCount = 0;
            }
        }
예제 #20
0
 public abstract void Write(char[] buffer, int offset, int count, IFallback fallback);
예제 #21
0
 public void Write(string text, IFallback fallback)
 {
     Write(text, 0, text.Length, fallback);
 }
예제 #22
0
 public void WriteComplete(char[] buffer, int offset, int count, IFallback fallback)
 {
     if (fallback != null || lineModeEncoding)
     {
         byte   b     = 0;
         byte[] array = null;
         uint   num   = 0u;
         bool   flag  = false;
         bool   flag2 = false;
         if (fallback != null)
         {
             array = fallback.GetUnsafeAsciiMap(out b);
             if (array != null)
             {
                 num = (uint)array.Length;
             }
             flag  = fallback.HasUnsafeUnicode();
             flag2 = fallback.TreatNonAsciiAsUnsafe(encoding.WebName);
         }
         while (count != 0)
         {
             while (count != 0 && lineBufferCount != lineBuffer.Length)
             {
                 char c = buffer[offset];
                 if (fallback != null && (((uint)c < num && (array[(int)c] & b) != 0) || (!encodingCompleteUnicode && (c >= '\u007f' || c < ' ') && codePageMap.IsUnsafeExtendedCharacter(c)) || (flag && c >= '\u007f' && (flag2 || fallback.IsUnsafeUnicode(c, isFirstChar)))))
                 {
                     if (!fallback.FallBackChar(c, lineBuffer, ref lineBufferCount, lineBuffer.Length))
                     {
                         break;
                     }
                     isFirstChar = false;
                 }
                 else
                 {
                     lineBuffer[lineBufferCount++] = c;
                     isFirstChar = false;
                     if (lineModeEncoding)
                     {
                         if (c == '\n' || c == '\r')
                         {
                             lineBufferLastNL = lineBufferCount;
                         }
                         else if (lineBufferLastNL > lineBuffer.Length - 256)
                         {
                             count--;
                             offset++;
                             break;
                         }
                     }
                 }
                 count--;
                 offset++;
             }
             if (lineModeEncoding && (lineBufferLastNL > lineBuffer.Length - 256 || (lineBufferCount > lineBuffer.Length - 32 && lineBufferLastNL != 0)))
             {
                 EncodeBuffer(lineBuffer, 0, lineBufferLastNL, false);
                 lineBufferCount -= lineBufferLastNL;
                 if (lineBufferCount != 0)
                 {
                     Buffer.BlockCopy(lineBuffer, lineBufferLastNL * 2, lineBuffer, 0, lineBufferCount * 2);
                 }
             }
             else if (lineBufferCount > lineBuffer.Length - Math.Max(minCharsEncode, 32))
             {
                 EncodeBuffer(lineBuffer, 0, lineBufferCount, false);
                 lineBufferCount = 0;
             }
             lineBufferLastNL = 0;
         }
         return;
     }
     if (count > minCharsEncode)
     {
         if (lineBufferCount != 0)
         {
             EncodeBuffer(lineBuffer, 0, lineBufferCount, false);
             lineBufferCount  = 0;
             lineBufferLastNL = 0;
         }
         EncodeBuffer(buffer, offset, count, false);
         return;
     }
     Buffer.BlockCopy(buffer, offset * 2, lineBuffer, lineBufferCount * 2, count * 2);
     lineBufferCount += count;
     if (lineBufferCount > lineBuffer.Length - minCharsEncode)
     {
         EncodeBuffer(lineBuffer, 0, lineBufferCount, false);
         lineBufferCount  = 0;
         lineBufferLastNL = 0;
     }
 }
예제 #23
0
 public ITextSink PrepareSink(IFallback fallback)
 {
     this.fallback = fallback;
     return(this as ITextSink);
 }
예제 #24
0
 internal ITextSinkEx WriteUnstructuredTagContent()
 {
     fallback = null;
     return(this);
 }
예제 #25
0
        public void WriteComplete(char[] buffer, int offset, int count, IFallback fallback)
        {
            InternalDebug.Assert(!this.endOfFile);
            InternalDebug.Assert(this.encoding != null);

            if (fallback != null || this.lineModeEncoding)
            {
                byte   unsafeAsciiMask       = 0;
                byte[] unsafeAsciiMap        = null;
                uint   unsafeAsciiMapLength  = 0;
                bool   hasUnsafeUnicode      = false;
                bool   treatNonAsciiAsUnsafe = false;

                if (fallback != null)
                {
                    unsafeAsciiMap = fallback.GetUnsafeAsciiMap(out unsafeAsciiMask);
                    if (unsafeAsciiMap != null)
                    {
                        unsafeAsciiMapLength = (uint)unsafeAsciiMap.Length;
                    }

                    hasUnsafeUnicode      = fallback.HasUnsafeUnicode();
                    treatNonAsciiAsUnsafe = fallback.TreatNonAsciiAsUnsafe(this.encoding.WebName);
                }

                while (0 != count)
                {
                    for (; 0 != count && this.lineBufferCount != this.lineBuffer.Length; count--, offset++)
                    {
                        char ch = buffer[offset];

                        if (fallback != null)
                        {
                            if (((uint)ch < unsafeAsciiMapLength && (unsafeAsciiMap[(int)ch] & unsafeAsciiMask) != 0) ||
                                (!this.encodingCompleteUnicode && (ch >= 0x7F || ch < ' ') && this.codePageMap.IsUnsafeExtendedCharacter(ch)) ||
                                (hasUnsafeUnicode && ch >= 0x7F && (treatNonAsciiAsUnsafe || fallback.IsUnsafeUnicode(ch, this.isFirstChar))))
                            {
                                if (!fallback.FallBackChar(ch, this.lineBuffer, ref this.lineBufferCount, this.lineBuffer.Length))
                                {
                                    break;
                                }
                                this.isFirstChar = false;
                                continue;
                            }
                        }

                        this.lineBuffer[this.lineBufferCount++] = ch;
                        this.isFirstChar = false;

                        if (this.lineModeEncoding)
                        {
                            if (ch == '\n' || ch == '\r')
                            {
                                this.lineBufferLastNL = this.lineBufferCount;
                            }
                            else if (this.lineBufferLastNL > this.lineBuffer.Length - LineSpaceThreshold)
                            {
                                count--;
                                offset++;

                                break;
                            }
                        }
                    }

                    if (this.lineModeEncoding &&
                        (this.lineBufferLastNL > this.lineBuffer.Length - LineSpaceThreshold ||
                         (this.lineBufferCount > this.lineBuffer.Length - SpaceThreshold &&
                          this.lineBufferLastNL != 0)))
                    {
                        this.EncodeBuffer(this.lineBuffer, 0, this.lineBufferLastNL, false);

                        this.lineBufferCount -= this.lineBufferLastNL;

                        if (this.lineBufferCount != 0)
                        {
                            Buffer.BlockCopy(this.lineBuffer, this.lineBufferLastNL * 2, this.lineBuffer, 0, this.lineBufferCount * 2);
                        }
                    }
                    else if (this.lineBufferCount > this.lineBuffer.Length - Math.Max(this.minCharsEncode, SpaceThreshold))
                    {
                        this.EncodeBuffer(this.lineBuffer, 0, this.lineBufferCount, false);

                        this.lineBufferCount = 0;
                    }

                    this.lineBufferLastNL = 0;
                }
            }
            else
            {
                if (count > this.minCharsEncode)
                {
                    if (this.lineBufferCount != 0)
                    {
                        this.EncodeBuffer(this.lineBuffer, 0, this.lineBufferCount, false);

                        this.lineBufferCount  = 0;
                        this.lineBufferLastNL = 0;
                    }

                    this.EncodeBuffer(buffer, offset, count, false);
                }
                else
                {
                    InternalDebug.Assert(this.lineBufferCount + count <= this.lineBuffer.Length);

                    Buffer.BlockCopy(buffer, offset * 2, this.lineBuffer, this.lineBufferCount * 2, count * 2);
                    this.lineBufferCount += count;

                    if (this.lineBufferCount > this.lineBuffer.Length - this.minCharsEncode)
                    {
                        this.EncodeBuffer(this.lineBuffer, 0, this.lineBufferCount, false);

                        this.lineBufferCount  = 0;
                        this.lineBufferLastNL = 0;
                    }
                }
            }
        }
예제 #26
0
 internal ITextSinkEx WriteTagName()
 {
     outputState = OutputState.WritingTagName;
     fallback    = null;
     return(this);
 }
 // Token: 0x06001074 RID: 4212 RVA: 0x00078E04 File Offset: 0x00077004
 private static bool IsUnsafeCharacter(char ch, byte[] unsafeAsciiMap, byte unsafeAsciiMask, bool hasUnsafeUnicode, bool isFirstChar, IFallback fallback)
 {
     return(unsafeAsciiMap != null && (((int)ch < unsafeAsciiMap.Length && (unsafeAsciiMap[(int)ch] & unsafeAsciiMask) != 0) || (hasUnsafeUnicode && ch >= '\u007f' && fallback.IsUnsafeUnicode(ch, isFirstChar))));
 }
예제 #28
0
 public void Write(char ch, IFallback fallback)
 {
     this.stringBuffer[0] = ch;
     this.Write(this.stringBuffer, 0, 1, fallback);
 }