public object Has(FunctionArgument _args, EvalContext cal) { var args = _args.Arguments; OperationHelper.AssertArgsNumberThrowIf(this, 1, args); OperationHelper.AssertCertainValueThrowIf(this, args); var ov = cal.GetValue <IValue>(args[0]); return(this.Contains(ov)); }
public static bool Exists(FunctionArgument _args, EvalContext cal) { var args = _args.Arguments; OperationHelper.AssertArgsNumberThrowIf(null, 1, args); OperationHelper.AssertCertainValueThrowIf(null, args); var ov = cal.GetValue <StringValue>(args)[0]; return(File.Exists(ov)); }
public static FileEasyWriter OpenEasyWrite(FunctionArgument _args, EvalContext cal) { var args = _args.Arguments; OperationHelper.AssertArgsNumberThrowIf(null, 1, args); OperationHelper.AssertCertainValueThrowIf(null, args); var ov = cal.GetValue <StringValue>(args)[0]; return(new FileEasyWriter(ov)); }
public static number Cos(FunctionArgument _args, EvalContext cal) { var args = _args.Arguments; OperationHelper.AssertArgsNumberThrowIf(null, 1, args); OperationHelper.AssertCertainValueThrowIf(null, args); var ov = cal.GetValue <number>(args[0]); return(new number(System.Math.Cos(ov))); }
public static TupleValue Split(FunctionArgument _args, EvalContext cal) { var args = _args.Arguments; OperationHelper.AssertArgsNumberThrowIf(null, 2, args); OperationHelper.AssertCertainValueThrowIf(null, args); var ov = cal.GetValue <StringValue>(args); return(new TupleValue(ov[0].Value.Split(ov[1].Value[0]).Select(x => new iExpr.Values.ConcreteValue(new StringValue(x))))); }
public static StringValue Substring(FunctionArgument _args, EvalContext cal) { var args = _args.Arguments; OperationHelper.AssertArgsNumberThrowIf(null, 3, args); OperationHelper.AssertCertainValueThrowIf(null, args); var ov = cal.GetValue <StringValue>(args[0]); var begin = (int)cal.GetValue <RealNumber>(args[1]); var len = (int)cal.GetValue <RealNumber>(args[2]); return(new StringValue(ov.Value.Substring(begin, len))); }
public static StringValue Remove(FunctionArgument _args, EvalContext cal) { var args = _args.Arguments; OperationHelper.AssertCertainValueThrowIf(null, args); if (OperationHelper.AssertArgsNumber(3, args)) { var ov = cal.GetValue <StringValue>(args[0]); var begin = (int)cal.GetValue <RealNumber>(args[1]); var len = (int)cal.GetValue <RealNumber>(args[2]); return(new StringValue(ov.Value.Remove(begin, len))); } else if (OperationHelper.AssertArgsNumber(2, args)) { var ov = cal.GetValue <StringValue>(args[0]); var begin = (int)cal.GetValue <RealNumber>(args[1]); return(new StringValue(ov.Value.Remove(begin))); } ExceptionHelper.RaiseWrongArgsNumber(null, 3, args?.Length ?? 0); return(default);
public static number Next(FunctionArgument _args, EvalContext cal) { var args = _args.Arguments; OperationHelper.AssertCertainValueThrowIf(null, args); var ov = cal.GetValue <number>(args); switch (ov.Length) { case 0: return(new number(rand.Next())); case 1: return(new number(rand.Next(ov[0]))); case 2: return(new number(rand.Next(ov[0], ov[1]))); } ExceptionHelper.RaiseWrongArgsNumber(null, 2, args?.Length ?? 0); return(default);