Beispiel #1
0
        //
        //  ProcessTerminal_HM_S_D
        //
        //  Actions: Validate the ambiguous 3-number "Hours:Minutes:Seconds", "Days.Hours:Minutes", or "Hours:Minutes:.Fraction" terminal case
        // 
        private static Boolean ProcessTerminal_HM_S_D(ref TimeSpanRawInfo raw, TimeSpanStandardStyles style, ref TimeSpanResult result) {
            if (raw.SepCount != 4 || raw.NumCount != 3 || (style & TimeSpanStandardStyles.RequireFull) != 0) {
                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;
            bool overflow = false;

            long ticks = 0;

            if (inv) {
                if (raw.FullHMSMatch(raw.PositiveInvariant)) {
                    positive = true; 
                    match = TryTimeToTicks(positive, zero, raw.numbers[0], raw.numbers[1], raw.numbers[2], zero, out ticks);
                    overflow = overflow || !match;
                }
                if (!match && raw.FullDHMMatch(raw.PositiveInvariant)) {
                    positive = true;
                    match = TryTimeToTicks(positive, raw.numbers[0], raw.numbers[1], raw.numbers[2], zero, zero, out ticks);
                    overflow = overflow || !match;
                } 
                if (!match && raw.PartialAppCompatMatch(raw.PositiveInvariant)) {
                    positive = true;
                    match = TryTimeToTicks(positive, zero, raw.numbers[0], raw.numbers[1], zero, raw.numbers[2], out ticks);
                    overflow = overflow || !match;
                }
                if (!match && raw.FullHMSMatch(raw.NegativeInvariant)) {
                    positive = false;
                    match = TryTimeToTicks(positive, zero, raw.numbers[0], raw.numbers[1], raw.numbers[2], zero, out ticks);
                    overflow = overflow || !match;
                }
                if (!match && raw.FullDHMMatch(raw.NegativeInvariant)) {
                    positive = false;
                    match = TryTimeToTicks(positive, raw.numbers[0], raw.numbers[1], raw.numbers[2], zero, zero, out ticks);
                    overflow = overflow || !match;
                } 
                if (!match && raw.PartialAppCompatMatch(raw.NegativeInvariant)) {
                    positive = false;
                    match = TryTimeToTicks(positive, zero, raw.numbers[0], raw.numbers[1], zero, raw.numbers[2], out ticks);
                    overflow = overflow || !match;
                }
            }
            if (loc) {
                if (!match && raw.FullHMSMatch(raw.PositiveLocalized)) {
                    positive = true; 
                    match = TryTimeToTicks(positive, zero, raw.numbers[0], raw.numbers[1], raw.numbers[2], zero, out ticks);
                    overflow = overflow || !match;
                }
                if (!match && raw.FullDHMMatch(raw.PositiveLocalized)) {
                    positive = true;
                    match = TryTimeToTicks(positive, raw.numbers[0], raw.numbers[1], raw.numbers[2], zero, zero, out ticks);
                    overflow = overflow || !match;
                }
                if (!match && raw.PartialAppCompatMatch(raw.PositiveLocalized)) {
                    positive = true;
                    match = TryTimeToTicks(positive, zero, raw.numbers[0], raw.numbers[1], zero, raw.numbers[2], out ticks);
                    overflow = overflow || !match;
                }
                if (!match && raw.FullHMSMatch(raw.NegativeLocalized)) {
                    positive = false;
                    match = TryTimeToTicks(positive, zero, raw.numbers[0], raw.numbers[1], raw.numbers[2], zero, out ticks);
                    overflow = overflow || !match;
                }
                if (!match && raw.FullDHMMatch(raw.NegativeLocalized)) {
                    positive = false;
                    match = TryTimeToTicks(positive, raw.numbers[0], raw.numbers[1], raw.numbers[2], zero, zero, out ticks);
                    overflow = overflow || !match;
                } 
                if (!match && raw.PartialAppCompatMatch(raw.NegativeLocalized)) {
                    positive = false;
                    match = TryTimeToTicks(positive, zero, raw.numbers[0], raw.numbers[1], zero, raw.numbers[2], out ticks);
                    overflow = overflow || !match;
                }
            }

            if (match) {
                if (!positive) {
                    ticks = -ticks;
                    if (ticks > 0) {
                        result.SetFailure(ParseFailureKind.Overflow, "Overflow_TimeSpanElementTooLarge");
                        return false;
                    }
                }
                result.parsedTimeSpan._ticks = ticks;
                return true;
            }  

            if (overflow) {
                // we found at least one literal pattern match but the numbers just didn't fit
                result.SetFailure(ParseFailureKind.Overflow, "Overflow_TimeSpanElementTooLarge");
                return false;
            }
            else {
                // we couldn't find a thing
                result.SetFailure(ParseFailureKind.Format, "Format_BadTimeSpan");
                return false;
            }
        }
 private static bool ProcessTerminal_HM_S_D(ref TimeSpanRawInfo raw, TimeSpanStandardStyles style, ref TimeSpanResult result)
 {
     if (((raw.SepCount != 4) || (raw.NumCount != 3)) || ((style & TimeSpanStandardStyles.RequireFull) != TimeSpanStandardStyles.None))
     {
         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;
     bool flag5 = false;
     long num = 0L;
     if (flag)
     {
         if (raw.FullHMSMatch(raw.PositiveInvariant))
         {
             positive = true;
             flag4 = TryTimeToTicks(positive, zero, raw.numbers[0], raw.numbers[1], raw.numbers[2], zero, out num);
             flag5 = flag5 || !flag4;
         }
         if (!flag4 && raw.FullDHMMatch(raw.PositiveInvariant))
         {
             positive = true;
             flag4 = TryTimeToTicks(positive, raw.numbers[0], raw.numbers[1], raw.numbers[2], zero, zero, out num);
             flag5 = flag5 || !flag4;
         }
         if (!flag4 && raw.PartialAppCompatMatch(raw.PositiveInvariant))
         {
             positive = true;
             flag4 = TryTimeToTicks(positive, zero, raw.numbers[0], raw.numbers[1], zero, raw.numbers[2], out num);
             flag5 = flag5 || !flag4;
         }
         if (!flag4 && raw.FullHMSMatch(raw.NegativeInvariant))
         {
             positive = false;
             flag4 = TryTimeToTicks(positive, zero, raw.numbers[0], raw.numbers[1], raw.numbers[2], zero, out num);
             flag5 = flag5 || !flag4;
         }
         if (!flag4 && raw.FullDHMMatch(raw.NegativeInvariant))
         {
             positive = false;
             flag4 = TryTimeToTicks(positive, raw.numbers[0], raw.numbers[1], raw.numbers[2], zero, zero, out num);
             flag5 = flag5 || !flag4;
         }
         if (!flag4 && raw.PartialAppCompatMatch(raw.NegativeInvariant))
         {
             positive = false;
             flag4 = TryTimeToTicks(positive, zero, raw.numbers[0], raw.numbers[1], zero, raw.numbers[2], out num);
             flag5 = flag5 || !flag4;
         }
     }
     if (flag2)
     {
         if (!flag4 && raw.FullHMSMatch(raw.PositiveLocalized))
         {
             positive = true;
             flag4 = TryTimeToTicks(positive, zero, raw.numbers[0], raw.numbers[1], raw.numbers[2], zero, out num);
             flag5 = flag5 || !flag4;
         }
         if (!flag4 && raw.FullDHMMatch(raw.PositiveLocalized))
         {
             positive = true;
             flag4 = TryTimeToTicks(positive, raw.numbers[0], raw.numbers[1], raw.numbers[2], zero, zero, out num);
             flag5 = flag5 || !flag4;
         }
         if (!flag4 && raw.PartialAppCompatMatch(raw.PositiveLocalized))
         {
             positive = true;
             flag4 = TryTimeToTicks(positive, zero, raw.numbers[0], raw.numbers[1], zero, raw.numbers[2], out num);
             flag5 = flag5 || !flag4;
         }
         if (!flag4 && raw.FullHMSMatch(raw.NegativeLocalized))
         {
             positive = false;
             flag4 = TryTimeToTicks(positive, zero, raw.numbers[0], raw.numbers[1], raw.numbers[2], zero, out num);
             flag5 = flag5 || !flag4;
         }
         if (!flag4 && raw.FullDHMMatch(raw.NegativeLocalized))
         {
             positive = false;
             flag4 = TryTimeToTicks(positive, raw.numbers[0], raw.numbers[1], raw.numbers[2], zero, zero, out num);
             flag5 = flag5 || !flag4;
         }
         if (!flag4 && raw.PartialAppCompatMatch(raw.NegativeLocalized))
         {
             positive = false;
             flag4 = TryTimeToTicks(positive, zero, raw.numbers[0], raw.numbers[1], zero, raw.numbers[2], out num);
             flag5 = flag5 || !flag4;
         }
     }
     if (flag4)
     {
         if (!positive)
         {
             num = -num;
             if (num > 0L)
             {
                 result.SetFailure(ParseFailureKind.Overflow, "Overflow_TimeSpanElementTooLarge");
                 return false;
             }
         }
         result.parsedTimeSpan._ticks = num;
         return true;
     }
     if (flag5)
     {
         result.SetFailure(ParseFailureKind.Overflow, "Overflow_TimeSpanElementTooLarge");
         return false;
     }
     result.SetFailure(ParseFailureKind.Format, "Format_BadTimeSpan");
     return false;
 }