private static (object, string) Function(IReadOnlyList <object> args, Options options) { string result = null; string error = null; var locale = options.Locale != null ? new CultureInfo(options.Locale) : Thread.CurrentThread.CurrentCulture; (locale, error) = FunctionUtils.DetermineLocale(args, locale, 2); if (error == null) { var inputStr = (string)args[0]; if (string.IsNullOrEmpty(inputStr)) { result = string.Empty; } else { var ti = locale.TextInfo; result = ti.ToTitleCase(inputStr); // Case that starts with number. result = Regex.Replace( result, "([0-9]+[a-zA-Z]+)", new MatchEvaluator((m) => { return(m.Captures[0].Value.ToLower(locale)); }), RegexOptions.IgnoreCase); } } return(result, error); }
private static EvaluateExpressionDelegate Evaluator() { return(FunctionUtils.ApplyWithOptionsAndError( (args, options) => { string error = null; string result = null; var locale = options.Locale != null ? new CultureInfo(options.Locale) : Thread.CurrentThread.CurrentCulture; if (error == null) { (locale, error) = FunctionUtils.DetermineLocale(args, locale, 2); } if (error == null) { if (args[0].IsNumber()) { result = Convert.ToDouble(args[0], CultureInfo.InvariantCulture).ToString(locale); } else if (args[0] is DateTime dt) { result = dt.ToString(FunctionUtils.DefaultDateTimeFormat, locale); } else { result = JsonConvert.SerializeObject(args[0]).TrimStart('"').TrimEnd('"'); } } return (result, error); })); }
private static EvaluateExpressionDelegate Evaluator() { return(FunctionUtils.ApplyWithOptionsAndError( (args, options) => { string result = null; string error = null; var locale = options.Locale != null ? new CultureInfo(options.Locale) : Thread.CurrentThread.CurrentCulture; if (!args[0].IsNumber()) { error = $"formatNumber first argument {args[0]} must be number"; } else if (!args[1].IsInteger()) { error = $"formatNumber second argument {args[1]} must be number"; } else if (args.Count == 3 && !(args[2] is string)) { error = $"formatNumber third agument {args[2]} must be a locale"; } if (error == null) { (locale, error) = FunctionUtils.DetermineLocale(args, locale, 3); } if (error == null) { var precision = 0; (precision, error) = FunctionUtils.ParseInt32(args[1]); if (error == null) { var number = Convert.ToDouble(args[0], CultureInfo.InvariantCulture); result = number.ToString("N" + precision.ToString(CultureInfo.InvariantCulture), locale); } } return (result, error); })); }
private static (object, string) Function(IReadOnlyList <object> args, Options options) { string result = null; string error = null; var locale = options.Locale != null ? new CultureInfo(options.Locale) : Thread.CurrentThread.CurrentCulture; (locale, error) = FunctionUtils.DetermineLocale(args, locale, 2); if (error == null) { if (args[0] == null) { result = string.Empty; } else { result = args[0].ToString().ToUpper(locale); } } return(result, error); }
private static (object, string) Function(IReadOnlyList <object> args, Options options) { string result = null; string error = null; var locale = options.Locale != null ? new CultureInfo(options.Locale) : Thread.CurrentThread.CurrentCulture; (locale, error) = FunctionUtils.DetermineLocale(args, locale, 2); if (error == null) { var inputStr = (string)args[0]; if (string.IsNullOrEmpty(inputStr)) { result = string.Empty; } else { result = inputStr.Substring(0, 1).ToUpper(locale) + inputStr.Substring(1).ToLower(locale); } } return(result, error); }
private static (object, string) Function(IReadOnlyList <object> args, Options options) { string result = null; string error = null; var locale = options.Locale != null ? new CultureInfo(options.Locale) : Thread.CurrentThread.CurrentCulture; (locale, error) = FunctionUtils.DetermineLocale(args, locale, 2); if (error == null) { var inputStr = (string)args[0]; if (string.IsNullOrEmpty(inputStr)) { result = string.Empty; } else { var ti = locale.TextInfo; result = ti.ToTitleCase(inputStr); } } return(result, error); }