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); }
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); }
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); }
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); }
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); }
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); }
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); }
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++; }
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); }
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); } }
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); }
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); }