protected override Variable Evaluate(ParsingScript script) { List <Variable> args = script.GetFunctionArgs(); Utils.CheckArgs(args.Count, 3, m_name); string varName = Utils.GetSafeString(args, 0); Variable toAdd = Utils.GetSafeVariable(args, 1); string hash = Utils.GetSafeString(args, 2); var function = ParserFunction.GetFunction(varName); Variable mapVar = function != null?function.GetValue(script) : new Variable(Variable.VarType.ARRAY); mapVar.AddVariableToHash(hash, toAdd); for (int i = 3; i < args.Count; i++) { string hash2 = Utils.GetSafeString(args, 3); if (!string.IsNullOrWhiteSpace(hash2) && !hash2.Equals(hash, StringComparison.OrdinalIgnoreCase)) { mapVar.AddVariableToHash(hash2, toAdd); } } ParserFunction.AddGlobalOrLocalVariable(varName, new GetVarFunction(mapVar)); return(Variable.EmptyInstance); }
protected override Variable Evaluate(ParsingScript script) { List <Variable> args = script.GetFunctionArgs(); Utils.CheckArgs(args.Count, 2, m_name); string pattern = Utils.GetSafeString(args, 0); string text = Utils.GetSafeString(args, 1); Variable result = new Variable(Variable.VarType.ARRAY); Regex rx = new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase); MatchCollection matches = rx.Matches(text); foreach (Match match in matches) { result.AddVariableToHash("matches", new Variable(match.Value)); var groups = match.Groups; foreach (var group in groups) { result.AddVariableToHash("groups", new Variable(group.ToString())); } } return(result); }
protected override Variable Evaluate(ParsingScript script) { bool isList = false; List <Variable> args = Utils.GetArgs(script, Constants.START_ARG, Constants.END_ARG, out isList); Utils.CheckArgs(args.Count, 3, m_name); string varName = Utils.GetSafeString(args, 0); Variable lines = Utils.GetSafeVariable(args, 1); int fromLine = Utils.GetSafeInt(args, 2); string hash2 = Utils.GetSafeString(args, 3); string sepStr = Utils.GetSafeString(args, 4, "\t"); if (sepStr == "\\t") { sepStr = "\t"; } char[] sep = sepStr.ToCharArray(); var function = ParserFunction.GetFunction(varName); Variable mapVar = function != null?function.GetValue(script) : new Variable(Variable.VarType.ARRAY); for (int counter = fromLine; counter < lines.Tuple.Count; counter++) { Variable lineVar = lines.Tuple[counter]; Variable toAdd = new Variable(counter - fromLine); string line = lineVar.AsString(); var tokens = line.Split(sep); string hash = tokens[0]; mapVar.AddVariableToHash(hash, toAdd); if (!string.IsNullOrWhiteSpace(hash2) && !hash2.Equals(hash, StringComparison.OrdinalIgnoreCase)) { mapVar.AddVariableToHash(hash2, toAdd); } } ParserFunction.AddGlobalOrLocalVariable(varName, new GetVarFunction(mapVar)); return(Variable.EmptyInstance); }