private void ReplaceEntries(FormulaDecorator formula, string str) { string[] sep = { Substring.Value }; var strs = str.Split(sep, StringSplitOptions.None); bool emptyLast = strs.Last().Length == 0; strs = strs.Where(s => s.Length > 0).ToArray(); for (int i = 0; i < strs.Length; ++i) { var concatC = new ConcatDecorator(new Const(strs[i])); concatC.Subformula = formula.Subformula; formula.Subformula = concatC; if (i < strs.Length - 1 || emptyLast) { Assert.IsTrue(Replacement.IsVar); var concatV = new ConcatDecorator(new Var(Replacement.Value)); concatV.Subformula = formula.Subformula; formula.Subformula = concatV; } } ToLeave = true; }
private void Replace(FormulaDecorator f) { if (f.Subformula is Var) { if (Substring.IsVar && (f.Subformula as Var).Value == Substring.Value) { (f.Subformula as Var).Value = (f.Subformula as Var).Value.Replace(Substring.Value, Replacement.Value); if (Replacement.IsConst) { var fConst = new Const((f.Subformula as Var).Value); f.Subformula = fConst; } } } else if (f.Subformula is Const) { if (Substring.IsConst && (Replacement.IsConst || (f.Subformula as Const).Value == Substring.Value)) { (f.Subformula as Const).Value = (f.Subformula as Const).Value.Replace(Substring.Value, Replacement.Value); if (Replacement.IsVar) { var fVar = new Var((f.Subformula as Const).Value); f.Subformula = fVar; } } else if (Substring.IsConst && Replacement.IsVar) { string value = (f.Subformula as Const).Value; f.Subformula = new Const(""); ReplaceEntries(f, value); } } }