Exemplo n.º 1
0
    private bool SimplifyMultiplication()
    {
        int i = 0;

        while (i < this.m_tokens.get_Count())
        {
            if (this.m_tokens.get_Item(i).type == WowTextParser.TokenType.Multiply)
            {
                if (i == 0 || i + 1 >= this.m_tokens.get_Count() || this.m_tokens.get_Item(i - 1).type != WowTextParser.TokenType.Number || this.m_tokens.get_Item(i + 1).type != WowTextParser.TokenType.Number)
                {
                    throw new Exception("SimplifyMultiply(): Invalid multiply in string " + this.m_input);
                }
                double num  = Convert.ToDouble(this.m_tokens.get_Item(i - 1).stringValue);
                double num2 = Convert.ToDouble(this.m_tokens.get_Item(i + 1).stringValue);
                double num3 = num * num2;
                int    num4 = (int)num3;
                this.m_tokens.RemoveAt(i + 1);
                this.m_tokens.RemoveAt(i);
                WowTextParser.ParseToken parseToken = default(WowTextParser.ParseToken);
                parseToken.type        = WowTextParser.TokenType.Number;
                parseToken.stringValue = num4.ToString();
                this.m_tokens.Insert(i, parseToken);
                this.m_tokens.RemoveAt(i - 1);
                return(true);
            }
            else
            {
                i++;
            }
        }
        return(false);
    }
Exemplo n.º 2
0
 private void AddColorEndToken()
 {
     WowTextParser.ParseToken parseToken = default(WowTextParser.ParseToken);
     parseToken.type        = WowTextParser.TokenType.ColorEnd;
     parseToken.stringValue = this.m_currentValue;
     this.m_currentValue    = string.Empty;
     this.m_tokens.Add(parseToken);
 }
Exemplo n.º 3
0
 private void AddMultiplyToken()
 {
     WowTextParser.ParseToken parseToken = default(WowTextParser.ParseToken);
     parseToken.type        = WowTextParser.TokenType.Multiply;
     parseToken.stringValue = "*";
     this.m_currentValue    = string.Empty;
     this.m_tokens.Add(parseToken);
 }
Exemplo n.º 4
0
 private void AddMinusToken()
 {
     WowTextParser.ParseToken parseToken = default(WowTextParser.ParseToken);
     parseToken.type        = WowTextParser.TokenType.Subtract;
     parseToken.stringValue = "-";
     this.m_currentValue    = string.Empty;
     this.m_tokens.Add(parseToken);
 }
Exemplo n.º 5
0
 private void AddColorStartToken()
 {
     WowTextParser.ParseToken item = default(WowTextParser.ParseToken);
     item.type           = WowTextParser.TokenType.ColorStart;
     item.stringValue    = this.m_currentValue;
     this.m_currentValue = string.Empty;
     this.m_tokens.Add(item);
 }
Exemplo n.º 6
0
 private void AddPlusToken()
 {
     WowTextParser.ParseToken item = default(WowTextParser.ParseToken);
     item.type           = WowTextParser.TokenType.Add;
     item.stringValue    = "+";
     this.m_currentValue = string.Empty;
     this.m_tokens.Add(item);
 }
Exemplo n.º 7
0
 private void AddNumericToken()
 {
     WowTextParser.ParseToken item = default(WowTextParser.ParseToken);
     item.type           = WowTextParser.TokenType.Number;
     item.stringValue    = this.m_currentValue;
     this.m_currentValue = string.Empty;
     this.m_tokens.Add(item);
 }
Exemplo n.º 8
0
 private void AddOpenBracketToken()
 {
     WowTextParser.ParseToken parseToken = default(WowTextParser.ParseToken);
     parseToken.type        = WowTextParser.TokenType.OpenBracket;
     parseToken.stringValue = "{";
     this.m_currentValue    = string.Empty;
     this.m_tokens.Add(parseToken);
     this.m_bracketLevel++;
 }
Exemplo n.º 9
0
 private void AddTextToken()
 {
     if (this.m_currentValue == string.Empty)
     {
         return;
     }
     WowTextParser.ParseToken parseToken = default(WowTextParser.ParseToken);
     parseToken.type        = WowTextParser.TokenType.Text;
     parseToken.stringValue = this.m_currentValue;
     this.m_currentValue    = string.Empty;
     this.m_tokens.Add(parseToken);
 }
Exemplo n.º 10
0
 private void AddCloseBracketToken()
 {
     WowTextParser.ParseToken parseToken = default(WowTextParser.ParseToken);
     parseToken.type        = WowTextParser.TokenType.ClosedBracket;
     parseToken.stringValue = "}";
     this.m_currentValue    = string.Empty;
     this.m_tokens.Add(parseToken);
     this.m_bracketLevel--;
     if (this.m_bracketLevel < 0)
     {
         throw new Exception("AddCloseBracketToken(): Mismatched brackets in string " + this.m_input);
     }
 }
Exemplo n.º 11
0
    private bool SimplifyAddSubtract()
    {
        int i = 0;

        while (i < this.m_tokens.Count)
        {
            if (this.m_tokens[i].type == WowTextParser.TokenType.Add || this.m_tokens[i].type == WowTextParser.TokenType.Subtract)
            {
                if (i == 0 || i + 1 >= this.m_tokens.Count || this.m_tokens[i - 1].type != WowTextParser.TokenType.Number || this.m_tokens[i + 1].type != WowTextParser.TokenType.Number)
                {
                    throw new Exception("SimplifyAddSubtract(): Invalid multiply in string " + this.m_input);
                }
                double num  = Convert.ToDouble(this.m_tokens[i - 1].stringValue);
                double num2 = Convert.ToDouble(this.m_tokens[i + 1].stringValue);
                double num3;
                if (this.m_tokens[i].type == WowTextParser.TokenType.Add)
                {
                    num3 = num + num2;
                }
                else
                {
                    num3 = num - num2;
                }
                int num4 = (int)num3;
                this.m_tokens.RemoveAt(i + 1);
                this.m_tokens.RemoveAt(i);
                WowTextParser.ParseToken item = default(WowTextParser.ParseToken);
                item.type        = WowTextParser.TokenType.Number;
                item.stringValue = num4.ToString();
                this.m_tokens.Insert(i, item);
                this.m_tokens.RemoveAt(i - 1);
                return(true);
            }
            else
            {
                i++;
            }
        }
        return(false);
    }
Exemplo n.º 12
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);
    }