Clear() public method

public Clear ( ) : void
return void
Ejemplo n.º 1
0
        public void Parse(MiniParser.IReader reader, MiniParser.IHandler handler)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            if (handler == null)
            {
                handler = new MiniParser.HandlerAdapter();
            }
            MiniParser.AttrListImpl attrListImpl = new MiniParser.AttrListImpl();
            string text  = null;
            Stack  stack = new Stack();
            string text2 = null;

            this.line = 1;
            this.col  = 0;
            int           num           = 0;
            int           num2          = 0;
            StringBuilder stringBuilder = new StringBuilder();
            bool          flag          = false;
            bool          flag2         = false;
            bool          flag3         = false;
            int           num3          = 0;

            handler.OnStartParsing(this);
            while (true)
            {
                this.col++;
                num = reader.Read();
                if (num == -1)
                {
                    break;
                }
                int num4 = "<>/?=&'\"![ ]\t\r\n".IndexOf((char)num) & 15;
                if (num4 != 13)
                {
                    if (num4 == 12)
                    {
                        num4 = 10;
                    }
                    if (num4 == 14)
                    {
                        this.col = 0;
                        this.line++;
                        num4 = 10;
                    }
                    int num5 = MiniParser.Xlat(num4, num2);
                    num2 = (num5 & 255);
                    if (num != 10 || (num2 != 14 && num2 != 15))
                    {
                        num5 >>= 8;
                        if (num2 >= 128)
                        {
                            if (num2 == 255)
                            {
                                this.FatalErr("State dispatch error.");
                            }
                            else
                            {
                                this.FatalErr(MiniParser.errors[num2 ^ 128]);
                            }
                        }
                        switch (num5)
                        {
                        case 0:
                            goto IL_19F;

                        case 1:
                        {
                            text2         = stringBuilder.ToString();
                            stringBuilder = new StringBuilder();
                            string text3 = null;
                            if (stack.get_Count() == 0 || text2 != (text3 = (stack.Pop() as string)))
                            {
                                if (text3 == null)
                                {
                                    this.FatalErr("Tag stack underflow");
                                }
                                else
                                {
                                    this.FatalErr(string.Format("Expected end tag '{0}' but found '{1}'", text2, text3));
                                }
                            }
                            handler.OnEndElement(text2);
                            break;
                        }

                        case 2:
                            text2         = stringBuilder.ToString();
                            stringBuilder = new StringBuilder();
                            if (num == 47 || num == 62)
                            {
                                goto IL_19F;
                            }
                            break;

                        case 3:
                            text          = stringBuilder.ToString();
                            stringBuilder = new StringBuilder();
                            break;

                        case 4:
                            if (text == null)
                            {
                                this.FatalErr("Internal error.");
                            }
                            attrListImpl.Add(text, stringBuilder.ToString());
                            stringBuilder = new StringBuilder();
                            text          = null;
                            break;

                        case 5:
                            handler.OnChars(stringBuilder.ToString());
                            stringBuilder = new StringBuilder();
                            break;

                        case 6:
                        {
                            string text4 = "CDATA[";
                            flag2 = false;
                            flag3 = false;
                            if (num == 45)
                            {
                                num = reader.Read();
                                if (num != 45)
                                {
                                    this.FatalErr("Invalid comment");
                                }
                                this.col++;
                                flag2 = true;
                                this.twoCharBuff[0] = -1;
                                this.twoCharBuff[1] = -1;
                            }
                            else if (num != 91)
                            {
                                flag3 = true;
                                num3  = 0;
                            }
                            else
                            {
                                for (int i = 0; i < text4.get_Length(); i++)
                                {
                                    if (reader.Read() != (int)text4.get_Chars(i))
                                    {
                                        this.col += i + 1;
                                        break;
                                    }
                                }
                                this.col += text4.get_Length();
                                flag      = true;
                            }
                            break;
                        }

                        case 7:
                        {
                            int num6 = 0;
                            num = 93;
                            while (num == 93)
                            {
                                num = reader.Read();
                                num6++;
                            }
                            if (num != 62)
                            {
                                for (int j = 0; j < num6; j++)
                                {
                                    stringBuilder.Append(']');
                                }
                                stringBuilder.Append((char)num);
                                num2 = 18;
                            }
                            else
                            {
                                for (int k = 0; k < num6 - 2; k++)
                                {
                                    stringBuilder.Append(']');
                                }
                                flag = false;
                            }
                            this.col += num6;
                            break;
                        }

                        case 8:
                            this.FatalErr(string.Format("Error {0}", num2));
                            break;

                        case 9:
                            break;

                        case 10:
                            stringBuilder = new StringBuilder();
                            if (num != 60)
                            {
                                goto IL_465;
                            }
                            break;

                        case 11:
                            goto IL_465;

                        case 12:
                            if (flag2)
                            {
                                if (num == 62 && this.twoCharBuff[0] == 45 && this.twoCharBuff[1] == 45)
                                {
                                    flag2 = false;
                                    num2  = 0;
                                }
                                else
                                {
                                    this.twoCharBuff[0] = this.twoCharBuff[1];
                                    this.twoCharBuff[1] = num;
                                }
                            }
                            else if (flag3)
                            {
                                if (num == 60 || num == 62)
                                {
                                    num3 ^= 1;
                                }
                                if (num == 62 && num3 != 0)
                                {
                                    flag3 = false;
                                    num2  = 0;
                                }
                            }
                            else
                            {
                                if (this.splitCData && stringBuilder.get_Length() > 0 && flag)
                                {
                                    handler.OnChars(stringBuilder.ToString());
                                    stringBuilder = new StringBuilder();
                                }
                                flag = false;
                                stringBuilder.Append((char)num);
                            }
                            break;

                        case 13:
                        {
                            num = reader.Read();
                            int num7 = this.col + 1;
                            if (num == 35)
                            {
                                int num8  = 10;
                                int num9  = 0;
                                int num10 = 0;
                                num = reader.Read();
                                num7++;
                                if (num == 120)
                                {
                                    num = reader.Read();
                                    num7++;
                                    num8 = 16;
                                }
                                NumberStyles numberStyles = (num8 != 16) ? 7 : 515;
                                while (true)
                                {
                                    int num11 = -1;
                                    if (char.IsNumber((char)num))
                                    {
                                        goto IL_5D9;
                                    }
                                    if ("abcdef".IndexOf(char.ToLower((char)num)) != -1)
                                    {
                                        goto Block_43;
                                    }
IL_5F9:
                                    if (num11 == -1)
                                    {
                                        break;
                                    }
                                    num9 *= num8;
                                    num9 += num11;
                                    num10++;
                                    num = reader.Read();
                                    num7++;
                                    continue;
Block_43:
                                    try
                                    {
IL_5D9:
                                        num11 = int.Parse(new string((char)num, 1), numberStyles);
                                    }
                                    catch (FormatException)
                                    {
                                        num11 = -1;
                                    }
                                    goto IL_5F9;
                                }
                                if (num == 59 && num10 > 0)
                                {
                                    stringBuilder.Append((char)num9);
                                }
                                else
                                {
                                    this.FatalErr("Bad char ref");
                                }
                            }
                            else
                            {
                                string text5  = "aglmopqstu";
                                string text6  = "&'\"><";
                                int    num12  = 0;
                                int    num13  = 15;
                                int    num14  = 0;
                                int    length = stringBuilder.get_Length();
                                while (true)
                                {
                                    if (num12 != 15)
                                    {
                                        num12 = (text5.IndexOf((char)num) & 15);
                                    }
                                    if (num12 == 15)
                                    {
                                        this.FatalErr(MiniParser.errors[7]);
                                    }
                                    stringBuilder.Append((char)num);
                                    int num15 = (int)"U㾏侏ཟク⊙o".get_Chars(num12);
                                    int num16 = num15 >> 4 & 15;
                                    int num17 = num15 & 15;
                                    int num18 = num15 >> 12;
                                    int num19 = num15 >> 8 & 15;
                                    num = reader.Read();
                                    num7++;
                                    num12 = 15;
                                    if (num16 != 15 && num == (int)text5.get_Chars(num16))
                                    {
                                        if (num18 < 14)
                                        {
                                            num13 = num18;
                                        }
                                        num14 = 12;
                                    }
                                    else if (num17 != 15 && num == (int)text5.get_Chars(num17))
                                    {
                                        if (num19 < 14)
                                        {
                                            num13 = num19;
                                        }
                                        num14 = 8;
                                    }
                                    else if (num == 59)
                                    {
                                        if (num13 != 15 && num14 != 0 && (num15 >> num14 & 15) == 14)
                                        {
                                            break;
                                        }
                                        continue;
                                    }
                                    num12 = 0;
                                }
                                int num20 = num7 - this.col - 1;
                                if (num20 > 0 && num20 < 5 && (MiniParser.StrEquals("amp", stringBuilder, length, num20) || MiniParser.StrEquals("apos", stringBuilder, length, num20) || MiniParser.StrEquals("quot", stringBuilder, length, num20) || MiniParser.StrEquals("lt", stringBuilder, length, num20) || MiniParser.StrEquals("gt", stringBuilder, length, num20)))
                                {
                                    stringBuilder.set_Length(length);
                                    stringBuilder.Append(text6.get_Chars(num13));
                                }
                                else
                                {
                                    this.FatalErr(MiniParser.errors[7]);
                                }
                            }
                            this.col = num7;
                            break;
                        }

                        default:
                            this.FatalErr(string.Format("Unexpected action code - {0}.", num5));
                            break;
                        }
                        continue;
IL_19F:
                        handler.OnStartElement(text2, attrListImpl);
                        if (num != 47)
                        {
                            stack.Push(text2);
                        }
                        else
                        {
                            handler.OnEndElement(text2);
                        }
                        attrListImpl.Clear();
                        continue;
IL_465:
                        stringBuilder.Append((char)num);
                    }
                }
            }
            if (num2 != 0)
            {
                this.FatalErr("Unexpected EOF");
            }
            handler.OnEndParsing(this);
        }
Ejemplo n.º 2
0
        public void Parse(MiniParser.IReader reader, MiniParser.IHandler handler)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }
            if (handler == null)
            {
                handler = (MiniParser.IHandler) new MiniParser.HandlerAdapter();
            }
            MiniParser.AttrListImpl attrListImpl = new MiniParser.AttrListImpl();
            string name1 = (string)null;
            Stack  stack = new Stack();
            string name2 = (string)null;

            this.line = 1;
            this.col  = 0;
            int           state = 0;
            StringBuilder sb    = new StringBuilder();
            bool          flag1 = false;
            bool          flag2 = false;
            bool          flag3 = false;
            int           num1  = 0;

            handler.OnStartParsing(this);
            while (true)
            {
                int num2;
                int num3;
                do
                {
                    do
                    {
                        int num4;
                        do
                        {
                            int charCode;
                            do
                            {
                                ++this.col;
                                num2 = reader.Read();
                                if (num2 == -1)
                                {
                                    if (state != 0)
                                    {
                                        this.FatalErr("Unexpected EOF");
                                        goto label_106;
                                    }
                                    else
                                    {
                                        goto label_106;
                                    }
                                }
                                else
                                {
                                    charCode = "<>/?=&'\"![ ]\t\r\n".IndexOf((char)num2) & 15;
                                }
                            }while (charCode == 13);
                            if (charCode == 12)
                            {
                                charCode = 10;
                            }
                            if (charCode == 14)
                            {
                                this.col = 0;
                                ++this.line;
                                charCode = 10;
                            }
                            num4  = MiniParser.Xlat(charCode, state);
                            state = num4 & (int)byte.MaxValue;
                        }while (num2 == 10 && (state == 14 || state == 15));
                        num3 = num4 >> 8;
                        if (state >= 128)
                        {
                            if (state == (int)byte.MaxValue)
                            {
                                this.FatalErr("State dispatch error.");
                            }
                            else
                            {
                                this.FatalErr(MiniParser.errors[state ^ 128]);
                            }
                        }
                        switch (num3)
                        {
                        case 0:
                            handler.OnStartElement(name2, (MiniParser.IAttrList)attrListImpl);
                            if (num2 != 47)
                            {
                                stack.Push((object)name2);
                            }
                            else
                            {
                                handler.OnEndElement(name2);
                            }
                            attrListImpl.Clear();
                            continue;

                        case 1:
                            name2 = sb.ToString();
                            sb    = new StringBuilder();
                            string str1 = (string)null;
                            if (stack.Count == 0 || name2 != (str1 = stack.Pop() as string))
                            {
                                if (str1 == null)
                                {
                                    this.FatalErr("Tag stack underflow");
                                }
                                else
                                {
                                    this.FatalErr(string.Format("Expected end tag '{0}' but found '{1}'", (object)name2, (object)str1));
                                }
                            }
                            handler.OnEndElement(name2);
                            continue;

                        case 2:
                            name2 = sb.ToString();
                            sb    = new StringBuilder();
                            if (num2 == 47 || num2 == 62)
                            {
                                goto case 0;
                            }
                            else
                            {
                                continue;
                            }

                        case 3:
                            name1 = sb.ToString();
                            sb    = new StringBuilder();
                            continue;

                        case 4:
                            if (name1 == null)
                            {
                                this.FatalErr("Internal error.");
                            }
                            attrListImpl.Add(name1, sb.ToString());
                            sb    = new StringBuilder();
                            name1 = (string)null;
                            continue;

                        case 5:
                            handler.OnChars(sb.ToString());
                            sb = new StringBuilder();
                            continue;

                        case 6:
                            string str2 = "CDATA[";
                            flag2 = false;
                            flag3 = false;
                            switch (num2)
                            {
                            case 45:
                                if (reader.Read() != 45)
                                {
                                    this.FatalErr("Invalid comment");
                                }
                                ++this.col;
                                flag2 = true;
                                this.twoCharBuff[0] = -1;
                                this.twoCharBuff[1] = -1;
                                continue;

                            case 91:
                                for (int index = 0; index < str2.Length; ++index)
                                {
                                    if (reader.Read() != (int)str2[index])
                                    {
                                        this.col += index + 1;
                                        break;
                                    }
                                }
                                this.col += str2.Length;
                                flag1     = true;
                                continue;

                            default:
                                flag3 = true;
                                num1  = 0;
                                continue;
                            }

                        case 7:
                            int num5 = 0;
                            int num6 = 93;
                            while (true)
                            {
                                switch (num6)
                                {
                                case 62:
                                    goto label_52;

                                case 93:
                                    num6 = reader.Read();
                                    ++num5;
                                    continue;

                                default:
                                    goto label_48;
                                }
                            }
label_48:
                            for (int index = 0; index < num5; ++index)
                            {
                                sb.Append(']');
                            }
                            sb.Append((char)num6);
                            state = 18;
                            goto label_56;
label_52:
                            for (int index = 0; index < num5 - 2; ++index)
                            {
                                sb.Append(']');
                            }
                            flag1 = false;
label_56:
                            this.col += num5;
                            continue;

                        case 8:
                            this.FatalErr(string.Format("Error {0}", (object)state));
                            continue;

                        case 9:
                            continue;

                        case 10:
                            sb = new StringBuilder();
                            continue;

                        case 11:
                            goto label_59;

                        case 12:
                            goto label_60;

                        case 13:
                            goto label_72;

                        default:
                            goto label_105;
                        }
                    }while (num2 == 60);
label_59:
                    sb.Append((char)num2);
                    continue;
label_60:
                    if (flag2)
                    {
                        if (num2 == 62 && this.twoCharBuff[0] == 45 && this.twoCharBuff[1] == 45)
                        {
                            flag2 = false;
                            state = 0;
                        }
                        else
                        {
                            this.twoCharBuff[0] = this.twoCharBuff[1];
                            this.twoCharBuff[1] = num2;
                        }
                    }
                    else if (flag3)
                    {
                        if (num2 == 60 || num2 == 62)
                        {
                            num1 ^= 1;
                        }
                    }
                    else
                    {
                        goto label_69;
                    }
                }while (num2 != 62 || num1 == 0);
                flag3 = false;
                state = 0;
                continue;
label_69:
                if (this.splitCData && sb.Length > 0 && flag1)
                {
                    handler.OnChars(sb.ToString());
                    sb = new StringBuilder();
                }
                flag1 = false;
                sb.Append((char)num2);
                continue;
label_72:
                int num7 = reader.Read();
                int num8 = this.col + 1;
                if (num7 == 35)
                {
                    int num4 = 10;
                    int num5 = 0;
                    int num6 = 0;
                    int num9 = reader.Read();
                    ++num8;
                    if (num9 == 120)
                    {
                        num9 = reader.Read();
                        ++num8;
                        num4 = 16;
                    }
                    NumberStyles style = num4 != 16 ? NumberStyles.Integer : NumberStyles.HexNumber;
                    while (true)
                    {
                        int num10 = -1;
                        if (!char.IsNumber((char)num9))
                        {
                            if ("abcdef".IndexOf(char.ToLower((char)num9)) == -1)
                            {
                                goto label_80;
                            }
                        }
                        try
                        {
                            num10 = int.Parse(new string((char)num9, 1), style);
                        }
                        catch (FormatException)
                        {
                            num10 = -1;
                        }
label_80:
                        if (num10 != -1)
                        {
                            num5 = num5 * num4 + num10;
                            ++num6;
                            num9 = reader.Read();
                            ++num8;
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (num9 == 59 && num6 > 0)
                    {
                        sb.Append((char)num5);
                    }
                    else
                    {
                        this.FatalErr("Bad char ref");
                    }
                }
                else
                {
                    string str1   = "aglmopqstu";
                    string str2   = "&'\"><";
                    int    index1 = 0;
                    int    index2 = 15;
                    int    num4   = 0;
                    int    length = sb.Length;
                    while (true)
                    {
                        int num5;
                        do
                        {
                            if (index1 != 15)
                            {
                                index1 = str1.IndexOf((char)num7) & 15;
                            }
                            if (index1 == 15)
                            {
                                this.FatalErr(MiniParser.errors[7]);
                            }
                            sb.Append((char)num7);
                            num5 = (int)"U㾏侏ཟク\xE1F4⊙\xEEFF\xEEFFo"[index1];
                            int index3 = num5 >> 4 & 15;
                            int index4 = num5 & 15;
                            int num6   = num5 >> 12;
                            int num9   = num5 >> 8 & 15;
                            num7 = reader.Read();
                            ++num8;
                            index1 = 15;
                            if (index3 != 15 && num7 == (int)str1[index3])
                            {
                                if (num6 < 14)
                                {
                                    index2 = num6;
                                }
                                num4 = 12;
                                goto label_100;
                            }
                            else if (index4 != 15 && num7 == (int)str1[index4])
                            {
                                if (num9 < 14)
                                {
                                    index2 = num9;
                                }
                                num4 = 8;
                                goto label_100;
                            }
                            else if (num7 != 59)
                            {
                                goto label_100;
                            }
                        }while (index2 == 15 || num4 == 0 || (num5 >> num4 & 15) != 14);
                        break;
label_100:
                        index1 = 0;
                    }
                    int len = num8 - this.col - 1;
                    if (len > 0 && len < 5 && (MiniParser.StrEquals("amp", sb, length, len) || MiniParser.StrEquals("apos", sb, length, len) || (MiniParser.StrEquals("quot", sb, length, len) || MiniParser.StrEquals("lt", sb, length, len)) || MiniParser.StrEquals("gt", sb, length, len)))
                    {
                        sb.Length = length;
                        sb.Append(str2[index2]);
                    }
                    else
                    {
                        this.FatalErr(MiniParser.errors[7]);
                    }
                }
                this.col = num8;
                continue;
label_105:
                this.FatalErr(string.Format("Unexpected action code - {0}.", (object)num3));
            }
label_106:
            handler.OnEndParsing(this);
        }