Beispiel #1
0
        //
        //  ProcessTerminal_DHMSF
        //
        //  Actions: Validate the 5-number "Days.Hours:Minutes:Seconds.Fraction" terminal case.
        //           Sets result.parsedTimeSpan on success.
        // 
        private static Boolean ProcessTerminal_DHMSF(ref TimeSpanRawInfo raw, TimeSpanStandardStyles style, ref TimeSpanResult result) {
            if (raw.SepCount != 6 || raw.NumCount != 5) {
                result.SetFailure(ParseFailureKind.Format, "Format_BadTimeSpan");
                return false;
            }

            bool inv = ((style & TimeSpanStandardStyles.Invariant) != 0);
            bool loc = ((style & TimeSpanStandardStyles.Localized) != 0);

            bool positive = false;
            bool match = false;

            if (inv) {
                if (raw.FullMatch(raw.PositiveInvariant)) {
                    match = true;
                    positive = true;         
                }
                if (!match && raw.FullMatch(raw.NegativeInvariant)) {
                    match = true;
                    positive = false;         
                }
            }
            if (loc) {
                if (!match && raw.FullMatch(raw.PositiveLocalized)) {
                    match = true;
                    positive = true;         
                }
                if (!match && raw.FullMatch(raw.NegativeLocalized)) {
                    match = true;
                    positive = false;         
                }
            }
            long ticks;
            if (match) {
                if (!TryTimeToTicks(positive, raw.numbers[0], raw.numbers[1], raw.numbers[2], raw.numbers[3], raw.numbers[4], out ticks)) {
                    result.SetFailure(ParseFailureKind.Overflow, "Overflow_TimeSpanElementTooLarge");
                    return false;
                }              
                if (!positive) {
                    ticks = -ticks;
                    if (ticks > 0) {
                        result.SetFailure(ParseFailureKind.Overflow, "Overflow_TimeSpanElementTooLarge");
                        return false;
                    }
                }
                result.parsedTimeSpan._ticks = ticks;
                return true;
            }   

            result.SetFailure(ParseFailureKind.Format, "Format_BadTimeSpan");
            return false;
        }
 private static bool ProcessTerminal_DHMSF(ref TimeSpanRawInfo raw, TimeSpanStandardStyles style, ref TimeSpanResult result)
 {
     if ((raw.SepCount != 6) || (raw.NumCount != 5))
     {
         result.SetFailure(ParseFailureKind.Format, "Format_BadTimeSpan");
         return false;
     }
     bool flag = (style & TimeSpanStandardStyles.Invariant) != TimeSpanStandardStyles.None;
     bool flag2 = (style & TimeSpanStandardStyles.Localized) != TimeSpanStandardStyles.None;
     bool positive = false;
     bool flag4 = false;
     if (flag)
     {
         if (raw.FullMatch(raw.PositiveInvariant))
         {
             flag4 = true;
             positive = true;
         }
         if (!flag4 && raw.FullMatch(raw.NegativeInvariant))
         {
             flag4 = true;
             positive = false;
         }
     }
     if (flag2)
     {
         if (!flag4 && raw.FullMatch(raw.PositiveLocalized))
         {
             flag4 = true;
             positive = true;
         }
         if (!flag4 && raw.FullMatch(raw.NegativeLocalized))
         {
             flag4 = true;
             positive = false;
         }
     }
     if (flag4)
     {
         long num;
         if (!TryTimeToTicks(positive, raw.numbers[0], raw.numbers[1], raw.numbers[2], raw.numbers[3], raw.numbers[4], out num))
         {
             result.SetFailure(ParseFailureKind.Overflow, "Overflow_TimeSpanElementTooLarge");
             return false;
         }
         if (!positive)
         {
             num = -num;
             if (num > 0L)
             {
                 result.SetFailure(ParseFailureKind.Overflow, "Overflow_TimeSpanElementTooLarge");
                 return false;
             }
         }
         result.parsedTimeSpan._ticks = num;
         return true;
     }
     result.SetFailure(ParseFailureKind.Format, "Format_BadTimeSpan");
     return false;
 }