Esempio n. 1
0
        //
        //  ProcessTerminal_HM
        //
        //  Actions: Validate the 2-number "Hours:Minutes" terminal case
        // 
        private static Boolean ProcessTerminal_HM(ref TimeSpanRawInfo raw, TimeSpanStandardStyles style, ref TimeSpanResult result) {
            if (raw.SepCount != 3 || raw.NumCount != 2 || (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;

            if (inv) {
                if (raw.FullHMMatch(raw.PositiveInvariant)) {
                    match = true;
                    positive = true; 
                }
                if (!match && raw.FullHMMatch(raw.NegativeInvariant)) {
                    match = true;
                    positive = false;
                }
            }
            if (loc) {
                if (!match && raw.FullHMMatch(raw.PositiveLocalized)) {
                    match = true;
                    positive = true; 
                }
                if (!match && raw.FullHMMatch(raw.NegativeLocalized)) {
                    match = true;
                    positive = false;
                }
            }

            long ticks = 0;
            if (match) {
                if (!TryTimeToTicks(positive, zero, raw.numbers[0], raw.numbers[1], zero, zero, 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_HM(ref TimeSpanRawInfo raw, TimeSpanStandardStyles style, ref TimeSpanResult result)
 {
     if (((raw.SepCount != 3) || (raw.NumCount != 2)) || ((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;
     if (flag)
     {
         if (raw.FullHMMatch(raw.PositiveInvariant))
         {
             flag4 = true;
             positive = true;
         }
         if (!flag4 && raw.FullHMMatch(raw.NegativeInvariant))
         {
             flag4 = true;
             positive = false;
         }
     }
     if (flag2)
     {
         if (!flag4 && raw.FullHMMatch(raw.PositiveLocalized))
         {
             flag4 = true;
             positive = true;
         }
         if (!flag4 && raw.FullHMMatch(raw.NegativeLocalized))
         {
             flag4 = true;
             positive = false;
         }
     }
     long num = 0L;
     if (flag4)
     {
         if (!TryTimeToTicks(positive, zero, raw.numbers[0], raw.numbers[1], zero, zero, 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;
 }