public object Execute(KarinEngine engine, FunctionToken token, object pipedObj) { if (!((token.IsPipe && token.Arguments.Length == 0) || (!token.IsPipe && token.Arguments.Length == 1))) { throw new KarinException($"{Name}関数の引数の数が不正です。"); } var arg = token.IsPipe ? pipedObj : engine.Ride(token.Arguments[0]); if (!(arg is string)) { throw new KarinException($"{Name}関数の引数が文字列ではありません。"); } var s = (string)arg; var sb = new StringBuilder(s.Length); int pre = 0; var ptn = new Regex(@"{\s*(\$\$?[^\s\$\{\}]+)\s*}"); foreach (Match m in ptn.Matches(s)) { var val = engine.Eval(m.Value); sb.Append(s.Substring(pre, m.Index - pre)); sb.Append(val); pre = m.Index + m.Length; } sb.Append(s.Substring(pre, s.Length - pre)); return(sb.ToString()); }
public object Execute(KarinEngine engine, FunctionToken token, object pipedObj) { if (!((token.IsPipe && token.Arguments.Length == 0) || (!token.IsPipe && token.Arguments.Length == 1))) { throw new KarinException($"{Name}関数の引数の数が不正です。"); } var s = token.IsPipe ? pipedObj : engine.Ride(token.Arguments[0]); if (!(s is string)) { throw new KarinException($"構文関数'{token.Name}'を実行できません。"); } return(engine.Eval((string)s)); }