public override Value Execute(Args args, Environment environment, SourcePos pos) { if (args.IsNull("y")) { return(ValueNull.NULL); } if (args.IsNull("x")) { return(ValueNull.NULL); } return(new ValueDecimal((decimal)Math.Atan2((double)args.GetNumerical("y").GetValue(), (double)args.GetNumerical("x").GetValue()))); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { if (args.IsNull("str")) { return(ValueNull.NULL); } var value = args.GetString("str").GetValue(); var start = (int)args.GetInt("startidx").GetValue(); if (start < 0) { start = value.Length + start; } if (start > value.Length) { return(new ValueString("")); } var end = (int)args.GetInt("endidx", value.Length).GetValue(); if (end < 0) { end = value.Length + end; } if (end > value.Length) { end = value.Length; } return(new ValueString(value.Substring(start, end - start))); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { if (args.IsNull("lst")) { return(ValueNull.NULL); } var value = args.GetList("lst").GetValue(); var start = (int)args.GetInt("startidx").GetValue(); if (start < 0) { start = value.Count + start; } if (start > value.Count) { return(new ValueList()); } var end = (int)args.GetInt("endidx", value.Count).GetValue(); if (end < 0) { end = value.Count + end; } if (end > value.Count) { end = value.Count; } var result = new ValueList(); for (var i = start; i < end; i++) { result.AddItem(value[i]); } return(result); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { if (args.IsNull("ch")) { return(ValueNull.NULL); } return(new ValueInt(char.ConvertToUtf32(args.GetString("ch").GetValue(), 0))); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { if (args.IsNull("n")) { return(ValueNull.NULL); } return(new ValueString(char.ConvertFromUtf32((int)args.GetInt("n").GetValue()).ToString())); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { if (args.IsNull("str")) { return(ValueBoolean.FALSE); } return(ValueBoolean.From(args.GetString("str").GetValue().Contains(args.GetString("part").GetValue()))); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { if (args.IsNull("str")) { return(ValueNull.NULL); } return(new ValueString(args.GetString("str").GetValue().ToUpper())); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { if (args.IsNull("str")) { return(ValueBoolean.FALSE); } return(ValueBoolean.From(args.GetString("str").Matches(args.GetAsPattern("pattern")))); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { if (args.IsNull("s")) { return(ValueNull.NULL); } var value = args.GetString("s").GetValue(); return(new ValueString(value.Replace("|", "\\|").Replace(".", "\\."))); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { if (args.IsNull("date")) { return(ValueNull.NULL); } var value = args.GetDate("date"); var date = value.AsDate().GetValue(); var fmt = args.HasArg("fmt") ? args.GetString("fmt").GetValue() : "yyyy-MM-dd HH:mm:ss"; return(new ValueString(date.ToString(fmt, DateTimeFormatInfo.InvariantInfo))); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { if (args.IsNull("x")) { return(ValueNull.NULL); } if (args.IsNull("y")) { return(ValueNull.NULL); } if (args.Get("y").IsInt()) { if (args.Get("x").IsInt()) { var x = args.GetInt("x").GetValue(); var y = args.GetInt("y").GetValue(); long result = 1; for (int i = 0; i < y; i++) { result *= x; } return(new ValueInt(result)); } else { var x = args.GetDecimal("x").GetValue(); var y = args.GetInt("y").GetValue(); decimal result = 1; for (int i = 0; i < y; i++) { result *= x; } return(new ValueDecimal(result)); } } else { return(new ValueDecimal((decimal)Math.Pow((double)args.GetNumerical("x").GetValue(), (double)args.GetNumerical("y").GetValue()))); } }
public override Value Execute(Args args, Environment environment, SourcePos pos) { if (args.IsNull("x")) { return(ValueNull.NULL); } var digits = 0; if (args.HasArg("digits")) { digits = (int)args.GetInt("digits").GetValue(); } return(new ValueDecimal((decimal)Math.Round((double)args.GetNumerical("x").GetValue(), digits))); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { if (args.IsNull("str")) { return(ValueNull.NULL); } var value = args.GetString("str").GetValue(); var delim = "[ \\t]+"; if (args.HasArg("delim")) { delim = args.GetAsString("delim").GetValue(); } return(SplitValue(value, delim)); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { if (args.IsNull("lst")) { return(ValueNull.NULL); } var lst = args.GetList("lst").GetValue(); var result = new ValueList(); for (var i = 0; i < lst.Count - 1; i++) { var pair = new ValueList(); pair.AddItem(lst[i]); pair.AddItem(lst[i + 1]); result.AddItem(pair); } return(result); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { if (args.IsNull("str")) { return(ValueNull.NULL); } var value = args.GetString("str").GetValue(); var sep1 = args.GetAsString("sep1").GetValue(); var sep2 = args.GetAsString("sep2").GetValue(); var result = FuncSplit.SplitValue(value, sep1); var list = result.GetValue(); for (var i = 0; i < list.Count; i++) { list[i] = FuncSplit.SplitValue(list[i].AsString().GetValue(), sep2); } return(result); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { if (args.IsNull("obj")) { return(ValueNull.NULL); } var obj = args.Get("obj"); var key = args.HasArg("key") ? args.GetFunc("key") : null; if (obj.IsString()) { var str = obj.AsString().GetValue(); var start = (int)args.GetInt("start", str.Length - 1).GetValue(); var part = args.GetString("part").GetValue(); return(new ValueInt(str.LastIndexOf(part, start, StringComparison.Ordinal))); } if (obj.IsList()) { var env = environment; if (key != null) { env = environment.NewEnv(); } var item = args.Get("part"); var list = obj.AsList().GetValue(); var start = (int)args.GetInt("start", list.Count - 1).GetValue(); for (var idx = start; idx >= 0; idx--) { var elem = list[idx]; if (key != null) { elem = key.Execute(new Args(key.GetArgNames()[0], elem, pos), env, pos); } if (elem.IsEquals(item)) { return(new ValueInt(idx)); } } return(new ValueInt(-1)); } throw new ControlErrorException(new ValueString("ERROR"), "Find_last only works with strings and lists", pos); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { if (args.IsNull("str")) { return(ValueNull.NULL); } var str = args.GetString("str").GetValue(); var fmts = new List <string>(); if (args.HasArg("fmt")) { if (args.Get("fmt").IsList()) { foreach (var fmt_ in args.GetList("fmt").GetValue()) { fmts.Add(fmt_.AsString().GetValue()); } } else { fmts.Add(args.GetString("fmt").GetValue()); } } else { fmts.Add("yyyyMMdd"); } foreach (var fmt in fmts) { try { return(new ValueDate(DateTime.ParseExact(str, fmt, DateTimeFormatInfo.InvariantInfo))); } catch { // continue; } } return(ValueNull.NULL); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { if (args.IsNull("s")) { return(ValueNull.NULL); } var s = args.GetString("s").GetValue(); var a = args.GetString("a").GetValue(); var b = args.GetString("b").GetValue(); var start = args.GetInt("start", 0L).GetValue(); if (start >= s.Length) { return(args.GetString("s")); } if (start == 0) { return(new ValueString(s.Replace(a, b))); } var prefix = s.Substring(0, (int)start); return(new ValueString(prefix + s.Substring((int)start).Replace(a, b))); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { if (args.IsNull("list")) { return(ValueNull.NULL); } var list = args.GetList("list").GetValue(); var ignore = new List <Value>(); if (args.HasArg("ignore")) { ignore.AddRange(args.GetList("ignore").GetValue()); } var resultdecimal = (decimal)0; var resultint = 0L; var decimalrequired = false; foreach (var value in list) { var skipvalue = false; foreach (var ignoreval in ignore) { if (ignoreval.IsEquals(value)) { skipvalue = true; break; } } if (skipvalue) { continue; } if (decimalrequired) { resultdecimal += value.AsDecimal().GetValue(); } else if (value.IsInt()) { resultint += value.AsInt().GetValue(); } else if (value.IsDecimal()) { if (!decimalrequired) { decimalrequired = true; resultdecimal = resultint; } resultdecimal += value.AsDecimal().GetValue(); } else { throw new ControlErrorException(new ValueString("ERROR"), "Cannot sum " + value, pos); } } if (decimalrequired) { return(new ValueDecimal(resultdecimal)); } return(new ValueInt(resultint)); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { if (args.IsNull("str")) { return(ValueNull.NULL); } var str = args.GetString("str").GetValue(); var start = (int)args.GetInt("start", 0).GetValue(); if (start < 0) { start = str.Length + start; } while (true) { var idx1 = str.IndexOf('{', start); if (idx1 == -1) { return(new ValueString(str)); } var idx2 = str.IndexOf('}', idx1 + 1); if (idx2 == -1) { return(new ValueString(str)); } var variable = str.Substring(idx1 + 1, idx2 - idx1 - 1); var width = 0; var zeroes = false; var leading = true; var digits = -1; int idx3 = variable.IndexOf('#'); if (idx3 != -1) { var spec = variable.Substring(idx3 + 1); variable = variable.Substring(0, idx3); if (spec.StartsWith("-")) { leading = false; spec = spec.Substring(1); } if (spec.StartsWith("0")) { zeroes = true; leading = false; spec = spec.Substring(1); } int idx4 = spec.IndexOf('.'); if (idx4 == -1) { digits = -1; width = int.Parse(spec); } else { digits = int.Parse(spec.Substring(idx4 + 1)); width = idx4 == 0 ? 0 : int.Parse(spec.Substring(0, idx4)); } } var node = Parser.Parse(variable, pos.filename); var value = node.Evaluate(environment).AsString().GetValue(); if (digits != -1) { value = string.Format("{0:f" + digits + "}", decimal.Parse(value)); } while (value.Length < width) { if (leading) { value = ' ' + value; } else if (zeroes) { value = '0' + value; } else { value = value + ' '; } } str = str.Substring(0, idx1) + value + str.Substring(idx2 + 1); start = idx1 + value.Length; } }
public override Value Execute(Args args, Environment environment, SourcePos pos) { if (args.IsNull("fmt")) { return(ValueNull.NULL); } var fmt = args.GetString("fmt").GetValue(); var arguments = args.Get("args...").AsList().GetValue(); var result = ""; var lastidx = 0; var pattern = "\\{([0-9]+)(#[^}]+)?\\}"; foreach (Match match in Regex.Matches(fmt, pattern)) { var start = match.Groups[0].Index; var end = start + match.Groups[0].Length; var var = int.Parse(match.Groups[1].Value); var spec = match.Groups[2].Value; var width = 0; var zeroes = false; var leading = true; int numbase = 10; var digits = -1; if (spec != null && spec != "") { spec = spec.Substring(1); // skip # if (spec.StartsWith("-")) { leading = false; spec = spec.Substring(1); } if (spec.StartsWith("0")) { zeroes = true; leading = false; spec = spec.Substring(1); } if (spec.EndsWith("x")) { numbase = 16; spec = spec.Substring(0, spec.Length - 1); } int idx = spec.IndexOf('.'); if (idx == -1) { digits = -1; width = int.Parse(spec == "" ? "0" : spec); } else { digits = int.Parse(spec.Substring(idx + 1)); width = idx == 0 ? 0 : int.Parse(spec.Substring(0, idx)); } } string value; if (numbase != 10) { value = string.Format("{0:x}", arguments[var].AsInt().GetValue()); } else if (digits != -1) { value = string.Format("{0:f" + digits + "}", arguments[var].AsDecimal().GetValue()); } else { value = arguments[var].AsString().GetValue(); } while (value.Length < width) { if (leading) { value = ' ' + value; } else if (zeroes) { value = '0' + value; } else { value = value + ' '; } } if (lastidx < start) { result += fmt.Substring(lastidx, start - lastidx); } result += value; lastidx = end; } if (lastidx < fmt.Length) { result += fmt.Substring(lastidx); } return(new ValueString(result)); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { if (args.IsNull("str")) { return(ValueNull.NULL); } var str = args.GetString("str").GetValue(); var start_ = (int)args.GetInt("start", 0).GetValue(); if (start_ < 0) { start_ = str.Length + start_; } var result = ""; if (start_ > 0) { result = str.Substring(0, start_); str = str.Substring(start_); } var lastidx = 0; var pattern = "\\{([^#{}]+)(#-?[0-9.]*x?)?\\}"; foreach (Match match in Regex.Matches(str, pattern)) { var start = match.Groups[0].Index; var end = start + match.Groups[0].Length; var expr = match.Groups[1].Value; var spec = match.Groups[2].Value; var width = 0; var zeroes = false; var leading = true; int numbase = 10; var digits = -1; if (spec != null && spec != "") { spec = spec.Substring(1); // skip # if (spec.StartsWith("-")) { leading = false; spec = spec.Substring(1); } if (spec.StartsWith("0")) { zeroes = true; leading = false; spec = spec.Substring(1); } if (spec.EndsWith("x")) { numbase = 16; spec = spec.Substring(0, spec.Length - 1); } int idx = spec.IndexOf('.'); if (idx == -1) { digits = -1; width = int.Parse(spec == "" ? "0" : spec); } else { digits = int.Parse(spec.Substring(idx + 1)); width = idx == 0 ? 0 : int.Parse(spec.Substring(0, idx)); } } string value = ""; try { var node = Parser.Parse(expr, pos.filename); var val = node.Evaluate(environment); if (numbase != 10) { value = string.Format("{0:x}", val.AsInt().GetValue()); } else if (digits != -1) { value = string.Format("{0:f" + digits + "}", val.AsDecimal().GetValue()); } else { value = val.AsString().GetValue(); } while (value.Length < width) { if (leading) { value = ' ' + value; } else if (zeroes) { value = '0' + value; } else { value = value + ' '; } } } catch (Exception) { // ignore } if (lastidx < start) { result += str.Substring(lastidx, start - lastidx); } result += value; lastidx = end; } if (lastidx < str.Length) { result += str.Substring(lastidx); } return(new ValueString(result)); }