示例#1
0
    public string Parse(string input, int spellID = 0)
    {
        this.m_input        = input;
        this.m_tokens       = new List <WowTextParser.ParseToken>();
        this.m_readIndex    = 0;
        this.m_currentValue = string.Empty;
        this.m_bracketLevel = 0;
        this.m_richText     = false;
        this.m_spellID      = spellID;
        if (spellID > 0 && GeneralHelpers.SpellGrantsArtifactXP(spellID))
        {
            return(this.ParseForArtifactXP(input, spellID));
        }
        while (true)
        {
            int readIndex = this.m_readIndex;
            if (this.ReadCharacter() == '$')
            {
                this.ParseDollarSign();
            }
            else if (this.ReadCharacter() == '}')
            {
                this.AddCloseBracketToken();
                this.ConsumeCharacter();
            }
            else if (this.ReadCharacter() == '+')
            {
                this.ParsePlusSign();
            }
            else if (this.ReadCharacter() == '-')
            {
                this.ParseMinusSign();
            }
            else if (this.ReadCharacter() == '*')
            {
                this.ParseMultiply();
            }
            else if (this.ReadCharacter() == '|')
            {
                this.ParseBar();
            }
            else
            {
                this.ParseCharacter();
            }
            if (this.m_readIndex == readIndex)
            {
                break;
            }
            if (!this.CharacterIsValid())
            {
                goto Block_10;
            }
        }
        throw new Exception("Parse: loop failed to advance in string " + this.m_input);
Block_10:
        this.AddTextToken();
        this.SimplifyTokens();
        string text = string.Empty;

        using (List <WowTextParser.ParseToken> .Enumerator enumerator = this.m_tokens.GetEnumerator())
        {
            while (enumerator.MoveNext())
            {
                WowTextParser.ParseToken current = enumerator.get_Current();
                WowTextParser.TokenType  type    = current.type;
                switch (type)
                {
                case WowTextParser.TokenType.Text:
                    text += current.stringValue;
                    continue;

                case WowTextParser.TokenType.OpenBracket:
                case WowTextParser.TokenType.ClosedBracket:
IL_170:
                    if (type == WowTextParser.TokenType.ColorStart)
                    {
                        text += current.stringValue;
                        continue;
                    }
                    if (type != WowTextParser.TokenType.ColorEnd)
                    {
                        continue;
                    }
                    text += current.stringValue;
                    continue;

                case WowTextParser.TokenType.Number:
                    text += current.stringValue;
                    continue;
                }
                goto IL_170;
            }
        }
        return(text);
    }
示例#2
0
        public string Parse(string input, int spellID = 0)
        {
            this.m_input        = input;
            this.m_tokens       = new List <WowTextParser.ParseToken>();
            this.m_readIndex    = 0;
            this.m_currentValue = string.Empty;
            this.m_bracketLevel = 0;
            this.m_richText     = false;
            this.m_spellID      = spellID;
            if (spellID > 0 && GeneralHelpers.SpellGrantsArtifactXP(spellID))
            {
                if (!(Main.instance.GetLocale() != "enUS"))
                {
                    return(this.ParseForArtifactXP(input, spellID));
                }
                this.m_input = this.ParseForArtifactXP(input, spellID);
            }
            for (;;)
            {
                int readIndex = this.m_readIndex;
                if (this.ReadCharacter() == '$')
                {
                    this.ParseDollarSign();
                }
                else if (this.ReadCharacter() == '}')
                {
                    this.AddCloseBracketToken();
                    this.ConsumeCharacter();
                }
                else if (this.ReadCharacter() == '+')
                {
                    this.ParsePlusSign();
                }
                else if (this.ReadCharacter() == '-')
                {
                    this.ParseMinusSign();
                }
                else if (this.ReadCharacter() == '*')
                {
                    this.ParseMultiply();
                }
                else if (this.ReadCharacter() == '|')
                {
                    this.ParseBar();
                }
                else
                {
                    this.ParseCharacter();
                }
                if (this.m_readIndex == readIndex)
                {
                    break;
                }
                if (!this.CharacterIsValid())
                {
                    goto Block_11;
                }
            }
            throw new Exception("Parse: loop failed to advance in string " + this.m_input);
Block_11:
            this.AddTextToken();
            this.SimplifyTokens();
            string text = string.Empty;

            foreach (WowTextParser.ParseToken parseToken in this.m_tokens)
            {
                WowTextParser.TokenType type = parseToken.type;
                switch (type)
                {
                case WowTextParser.TokenType.Text:
                    text += parseToken.stringValue;
                    break;

                default:
                    if (type != WowTextParser.TokenType.ColorStart)
                    {
                        if (type == WowTextParser.TokenType.ColorEnd)
                        {
                            text += parseToken.stringValue;
                        }
                    }
                    else
                    {
                        text += parseToken.stringValue;
                    }
                    break;

                case WowTextParser.TokenType.Number:
                    text += parseToken.stringValue;
                    break;
                }
            }
            return(text);
        }