public static Parse <int> DigitValue() { return(value => { ParseResult <char> whiteSpaceResult = IsWhitespace()(value); if (!whiteSpaceResult.Succeeded) { ParseResult <char> result = Match(char.IsDigit)(value); int resultValue = 0; if (result.Succeeded) { resultValue = System.Convert.ToInt32(result.Result.ToString()); return new ParseResult <int>(resultValue, result.RemainingInput, true); } else { return new ParseResult <int>(resultValue, value, false); } } else { ParseResult <int> result = DigitValue()(whiteSpaceResult.RemainingInput); return result; } }); }
private static Parse <string> DecimalStringHelper(string x, bool front, int stelle) { return(value => { var culture = new CultureInfo("en-gb"); if (front) { ParseResult <int> parseResult = DigitValue()(value); if (parseResult.Succeeded) { string str = Convert.ToString(10 * Convert.ToInt32(x) + Convert.ToInt32(parseResult.Result), culture); var doubleVal = DecimalStringHelper(str, true, 1); ParseResult <string> result = doubleVal(parseResult.RemainingInput); return result; } else { ParseResult <char> pointResult = IsPoint()(value); if (pointResult.Succeeded) { var doubleVal = DecimalStringHelper(x, false, 1); ParseResult <string> result = doubleVal(pointResult.RemainingInput); return result; } if (string.IsNullOrEmpty(x) || (!parseResult.Succeeded && !pointResult.Succeeded)) { return new ParseResult <string>(x, parseResult.RemainingInput, false); } return new ParseResult <string>(x, parseResult.RemainingInput, true); } } else { ParseResult <int> parseResult = DigitValue()(value); if (parseResult.Succeeded) { decimal dec = (decimal)parseResult.Result; for (int i = 0; i < stelle; i++) { dec = dec / 10; } string str = Convert.ToString(Convert.ToDecimal(x) + Convert.ToDecimal(dec), culture); var doubleVal = DecimalStringHelper(str, false, ++stelle); ParseResult <string> result = doubleVal(parseResult.RemainingInput); return result; } if (string.IsNullOrEmpty(x)) { return new ParseResult <string>(x, parseResult.RemainingInput, false); } return new ParseResult <string>(x, parseResult.RemainingInput, true); } }); }
private static Parse <int> IntegerHelper(int x) { return(value => { ParseResult <int> parseResult = DigitValue()(value); if (parseResult.Succeeded) { var intVal = IntegerHelper(10 * x + parseResult.Result); ParseResult <int> result = intVal(parseResult.RemainingInput); return result; } if (x == 0) { return new ParseResult <int>(x, parseResult.RemainingInput, false); } return new ParseResult <int>(x, parseResult.RemainingInput, true); }); }
private static Parse <decimal> DecimalHelper(decimal x, bool front, int stelle) { return(value => { if (front) { ParseResult <int> parseResult = DigitValue()(value); if (parseResult.Succeeded) { var doubleVal = DecimalHelper(10 * x + parseResult.Result, true, 1); ParseResult <decimal> result = doubleVal(parseResult.RemainingInput); return result; } else { ParseResult <char> pointResult = IsPoint()(value); if (pointResult.Succeeded) { var doubleVal = DecimalHelper(x, false, 1); ParseResult <decimal> result = doubleVal(pointResult.RemainingInput); return result; } return new ParseResult <decimal>(x, parseResult.RemainingInput, false); } } else { ParseResult <int> parseResult = DigitValue()(value); if (parseResult.Succeeded) { decimal dec = (decimal)parseResult.Result; for (int i = 0; i < stelle; i++) { dec = dec / 10; } var doubleVal = DecimalHelper(x + dec, false, ++stelle); ParseResult <decimal> result = doubleVal(parseResult.RemainingInput); return result; } return new ParseResult <decimal>(x, parseResult.RemainingInput, false); } }); }
private static Parse <string> IntegerHelperString(string x) { return(value => { ParseResult <int> parseResult = DigitValue()(value); if (parseResult.Succeeded) { var innerValue = 10 * Convert.ToInt16(x) + parseResult.Result; var intVal = IntegerHelperString(innerValue.ToString()); ParseResult <string> result = intVal(parseResult.RemainingInput); return result; } if (x.ToString() == "0") { return new ParseResult <string>(x, parseResult.RemainingInput, false); } return new ParseResult <string>(x, parseResult.RemainingInput, true); }); }
/// <summary> /// Compare two Importances /// </summary> /// <param name="obj"></param> /// <returns></returns> public int CompareTo(object obj) { Importance imp = obj as Importance; return(DigitValue.CompareTo(imp.DigitValue)); }
/// <summary> /// Initializes a new instance of <see cref="DigitViewModel"/>. /// </summary> public DigitViewModel() { Value = 0; }
private static DigitValue[] GetDigitValues(int value, string format) { var valueStr = value.ToString(format); if (value < 0) { // Lop off negative sign from string valueStr = valueStr.Substring(1); } var digits = new DigitValue[valueStr.Length]; int i = 0; if (value < 0) { // Pad the array with a dash if the value is negative digits[i++] = DigitValue.Dash; } for (; i < valueStr.Length; i++) { digits[i] = (DigitValue) Convert.ToInt32(valueStr.Substring(i, 1)); } return digits; }