当前位置: 首页>>代码示例>>C#>>正文


C# TimeSpanResult.SetFailure方法代码示例

本文整理汇总了C#中TimeSpanResult.SetFailure方法的典型用法代码示例。如果您正苦于以下问题:C# TimeSpanResult.SetFailure方法的具体用法?C# TimeSpanResult.SetFailure怎么用?C# TimeSpanResult.SetFailure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TimeSpanResult的用法示例。


在下文中一共展示了TimeSpanResult.SetFailure方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessTerminalState

        //
        //  ProcessTerminalState
        //
        //  Actions: Validate the terminal state of a standard format parse.
        //           Sets result.parsedTimeSpan on success.
        // 
        // Calculates the resultant TimeSpan from the TimeSpanRawInfo
        //
        // try => +InvariantPattern, -InvariantPattern, +LocalizedPattern, -LocalizedPattern
        // 1) Verify Start matches
        // 2) Verify End matches
        // 3) 1 number  => d
        //    2 numbers => h:m
        //    3 numbers => h:m:s | d.h:m | h:m:.f
        //    4 numbers => h:m:s.f | d.h:m:s | d.h:m:.f
        //    5 numbers => d.h:m:s.f
        private static Boolean ProcessTerminalState(ref TimeSpanRawInfo raw, TimeSpanStandardStyles style, ref TimeSpanResult result) {
            if (raw.lastSeenTTT == TTT.Num) {
                TimeSpanToken tok = new TimeSpanToken();
                tok.ttt = TTT.Sep;
                tok.sep = String.Empty;
                if (!raw.ProcessToken(ref tok, ref result)) {
                    result.SetFailure(ParseFailureKind.Format, "Format_BadTimeSpan");
                    return false;
                }
            }

            switch (raw.NumCount) {
                case 1:
                    return ProcessTerminal_D(ref raw, style, ref result);
                case 2:
                    return ProcessTerminal_HM(ref raw, style, ref result);
                case 3:
                    return ProcessTerminal_HM_S_D(ref raw, style, ref result);
                case 4:
                    return ProcessTerminal_HMS_F_D(ref raw, style, ref result);
                case 5:
                    return ProcessTerminal_DHMSF(ref raw, style, ref result);
                default:
                    result.SetFailure(ParseFailureKind.Format, "Format_BadTimeSpan");
                    return false;
            }
        }       
开发者ID:kouvel,项目名称:coreclr,代码行数:43,代码来源:TimeSpanParse.cs

示例2: AddNum

 private bool AddNum(TimeSpanToken num, ref TimeSpanResult result) {
     if (NumCount >= MaxNumericTokens || tokenCount >= MaxTokens) {
         result.SetFailure(ParseFailureKind.Format, "Format_BadTimeSpan", null);
         return false;
     }
     numbers[NumCount++] = num;   
     tokenCount++;
     return true;
 }
开发者ID:kouvel,项目名称:coreclr,代码行数:9,代码来源:TimeSpanParse.cs

示例3: TryParseTimeSpan

        // ---- SECTION:  private static methods that do the actual work ---------*
        #region TryParseTimeSpan
        //
        //  TryParseTimeSpan
        //
        //  Actions: Common private Parse method called by both Parse and TryParse
        // 
        private static Boolean TryParseTimeSpan(String input, TimeSpanStandardStyles style, IFormatProvider formatProvider, ref TimeSpanResult result) {
            if (input == null) {
                result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, nameof(input));
                return false;
            }

            input = input.Trim();
            if (input == String.Empty) {
                result.SetFailure(ParseFailureKind.Format, "Format_BadTimeSpan");
                return false;
            }

            TimeSpanTokenizer tokenizer = new TimeSpanTokenizer();
            tokenizer.Init(input);

            TimeSpanRawInfo raw = new TimeSpanRawInfo();
            raw.Init(DateTimeFormatInfo.GetInstance(formatProvider));

            TimeSpanToken tok = tokenizer.GetNextToken();

            /* The following loop will break out when we reach the end of the str or
             * when we can determine that the input is invalid. */
            while (tok.ttt != TTT.End) {
                if (!raw.ProcessToken(ref tok, ref result)) {
                    result.SetFailure(ParseFailureKind.Format, "Format_BadTimeSpan");
                    return false;
                }
                tok = tokenizer.GetNextToken();
            }
            if (!tokenizer.EOL) {
                // embedded nulls in the input string
                result.SetFailure(ParseFailureKind.Format, "Format_BadTimeSpan");
                return false;
            }
            if (!ProcessTerminalState(ref raw, style, ref result)) {
                result.SetFailure(ParseFailureKind.Format, "Format_BadTimeSpan");
                return false;
            }
            return true;
        }
开发者ID:kouvel,项目名称:coreclr,代码行数:47,代码来源:TimeSpanParse.cs

示例4: ProcessToken

            internal Boolean ProcessToken(ref TimeSpanToken tok, ref TimeSpanResult result) {
                if (tok.ttt == TTT.NumOverflow) {
                    result.SetFailure(ParseFailureKind.Overflow, "Overflow_TimeSpanElementTooLarge", null);
                    return false;
                }
                if (tok.ttt != TTT.Sep && tok.ttt != TTT.Num) {
                    // Some unknown token or a repeat token type in the input
                    result.SetFailure(ParseFailureKind.Format, "Format_BadTimeSpan", null);
                    return false;
                }

                switch (tok.ttt) {
                    case TTT.Sep:
                        if (!AddSep(tok.sep, ref result)) return false;
                        break;
                    case TTT.Num:
                        if (tokenCount == 0) {
                            if (!AddSep(String.Empty, ref result)) return false;
                        }
                        if (!AddNum(tok, ref result)) return false;
                        break;
                    default:
                        break;
                }

                lastSeenTTT = tok.ttt;
                Debug.Assert(tokenCount == (SepCount + NumCount), "tokenCount == (SepCount + NumCount)");
                return true;
            }
开发者ID:kouvel,项目名称:coreclr,代码行数:29,代码来源:TimeSpanParse.cs

示例5: AddSep

 private bool AddSep(String sep, ref TimeSpanResult result) {
     if (SepCount >= MaxLiteralTokens || tokenCount >= MaxTokens) {
         result.SetFailure(ParseFailureKind.Format, "Format_BadTimeSpan", null);
         return false;
     }
     literals[SepCount++] = sep;
     tokenCount++;
     return true;
 }
开发者ID:kouvel,项目名称:coreclr,代码行数:9,代码来源:TimeSpanParse.cs

示例6: TryParseExactMultipleTimeSpan

 private static bool TryParseExactMultipleTimeSpan(string input, string[] formats, IFormatProvider formatProvider, TimeSpanStyles styles, ref TimeSpanResult result)
 {
     if (input == null)
     {
         result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, "input");
         return false;
     }
     if (formats == null)
     {
         result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, "formats");
         return false;
     }
     if (input.Length == 0)
     {
         result.SetFailure(ParseFailureKind.Format, "Format_BadTimeSpan");
         return false;
     }
     if (formats.Length == 0)
     {
         result.SetFailure(ParseFailureKind.Format, "Format_BadFormatSpecifier");
         return false;
     }
     for (int i = 0; i < formats.Length; i++)
     {
         if ((formats[i] == null) || (formats[i].Length == 0))
         {
             result.SetFailure(ParseFailureKind.Format, "Format_BadFormatSpecifier");
             return false;
         }
         TimeSpanResult result2 = new TimeSpanResult();
         result2.Init(TimeSpanThrowStyle.None);
         if (TryParseExactTimeSpan(input, formats[i], formatProvider, styles, ref result2))
         {
             result.parsedTimeSpan = result2.parsedTimeSpan;
             return true;
         }
     }
     result.SetFailure(ParseFailureKind.Format, "Format_BadTimeSpan");
     return false;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:40,代码来源:TimeSpanParse.cs

示例7: TryParseExactMultipleTimeSpan

        //
        //  TryParseExactMultipleTimeSpan
        //
        //  Actions: Common private ParseExactMultiple method called by both ParseExactMultiple and TryParseExactMultiple
        // 
        private static Boolean TryParseExactMultipleTimeSpan(String input, String[] formats, IFormatProvider formatProvider, TimeSpanStyles styles, ref TimeSpanResult result) {
            if (input == null) {
                result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, nameof(input));
                return false;
            }
            if (formats == null) {
                result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, nameof(formats));
                return false;
            }

            if (input.Length == 0) {
                result.SetFailure(ParseFailureKind.Format, "Format_BadTimeSpan");
                return false;
            }

            if (formats.Length == 0) {
                result.SetFailure(ParseFailureKind.Format, "Format_BadFormatSpecifier");
                return false;
            }

            //
            // Do a loop through the provided formats and see if we can parse succesfully in
            // one of the formats.
            //
            for (int i = 0; i < formats.Length; i++) {
                if (formats[i] == null || formats[i].Length == 0) {
                    result.SetFailure(ParseFailureKind.Format, "Format_BadFormatSpecifier");
                    return false;
                }

                // Create a new non-throwing result each time to ensure the runs are independent.
                TimeSpanResult innerResult = new TimeSpanResult();
                innerResult.Init(TimeSpanThrowStyle.None);

                if(TryParseExactTimeSpan(input, formats[i], formatProvider, styles, ref innerResult)) {
                    result.parsedTimeSpan = innerResult.parsedTimeSpan;
                    return true;
                }
            }

            result.SetFailure(ParseFailureKind.Format, "Format_BadTimeSpan");
            return (false);
        }
开发者ID:kouvel,项目名称:coreclr,代码行数:48,代码来源:TimeSpanParse.cs

示例8: TryParse

            internal bool TryParse(String input, ref TimeSpanResult result) {
                result.parsedTimeSpan._ticks = 0;

                if (input == null) {
                    result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, nameof(input));
                    return false;
                }
                str = input;
                len = input.Length;
                pos = -1;
                NextChar();
                SkipBlanks();
                bool negative = false;
                if (ch == '-') {
                    negative = true;
                    NextChar();
                }
                long time;
                if (NextNonDigit() == ':') {
                    if (!ParseTime(out time, ref result)) {
                        return false;
                    };
                }
                else {
                    int days;
                    if (!ParseInt((int)(0x7FFFFFFFFFFFFFFFL / TimeSpan.TicksPerDay), out days, ref result)) {
                        return false;
                    }
                    time = days * TimeSpan.TicksPerDay;
                    if (ch == '.') {
                        NextChar();
                        long remainingTime;
                        if (!ParseTime(out remainingTime, ref result)) {
                            return false;
                        };
                        time += remainingTime;
                    }
                }
                if (negative) {
                    time = -time;
                    // Allow -0 as well
                    if (time > 0) {
                        result.SetFailure(ParseFailureKind.Overflow, "Overflow_TimeSpanElementTooLarge");
                        return false;                        
                    }
                }
                else {
                    if (time < 0) {
                        result.SetFailure(ParseFailureKind.Overflow, "Overflow_TimeSpanElementTooLarge");
                        return false;                        
                    }
                }
                SkipBlanks();
                if (pos < len) {
                    result.SetFailure(ParseFailureKind.Format, "Format_BadTimeSpan");
                    return false;                                        
                }
                result.parsedTimeSpan._ticks = time;
                return true;
            }
开发者ID:kouvel,项目名称:coreclr,代码行数:60,代码来源:TimeSpanParse.cs

示例9: ParseInt

 internal bool ParseInt(int max, out int i, ref TimeSpanResult result) {
     i = 0;
     int p = pos;
     while (ch >= '0' && ch <= '9') {
         if ((i & 0xF0000000) != 0) {
             result.SetFailure(ParseFailureKind.Overflow, "Overflow_TimeSpanElementTooLarge");
             return false;
         }
         i = i * 10 + ch - '0';
         if (i < 0) {
             result.SetFailure(ParseFailureKind.Overflow, "Overflow_TimeSpanElementTooLarge");
             return false;
         }
         NextChar();
     }
     if (p == pos) {
         result.SetFailure(ParseFailureKind.Format, "Format_BadTimeSpan");
         return false;
     }
     if (i > max) {
         result.SetFailure(ParseFailureKind.Overflow, "Overflow_TimeSpanElementTooLarge");
         return false;
     }
     return true;
 }
开发者ID:kouvel,项目名称:coreclr,代码行数:25,代码来源:TimeSpanParse.cs

示例10: TryParseExactTimeSpan

        //
        //  TryParseExactTimeSpan
        //
        //  Actions: Common private ParseExact method called by both ParseExact and TryParseExact
        // 
        private static Boolean TryParseExactTimeSpan(String input, String format, IFormatProvider formatProvider, TimeSpanStyles styles, ref TimeSpanResult result) {
            if (input == null) {
                result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, nameof(input));
                return false;
            }
            if (format == null) {
                result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, nameof(format));
                return false;
            }
            if (format.Length == 0) {
                result.SetFailure(ParseFailureKind.Format, "Format_BadFormatSpecifier");
                return false;
            }

            if (format.Length == 1) {
                TimeSpanStandardStyles style = TimeSpanStandardStyles.None;

                if (format[0] == 'c' || format[0] == 't' || format[0] == 'T') {
                    // fast path for legacy style TimeSpan formats.
                    return TryParseTimeSpanConstant(input, ref result);
                }
                else if (format[0] == 'g') {
                    style = TimeSpanStandardStyles.Localized;
                }
                else if (format[0] == 'G') {
                    style = TimeSpanStandardStyles.Localized | TimeSpanStandardStyles.RequireFull;
                }
                else {
                    result.SetFailure(ParseFailureKind.Format, "Format_BadFormatSpecifier");
                    return false;
                }
                return TryParseTimeSpan(input, style, formatProvider, ref result);
            }
           
            return TryParseByFormat(input, format, styles, ref result);
        }
开发者ID:kouvel,项目名称:coreclr,代码行数:41,代码来源:TimeSpanParse.cs

示例11: TryParseByFormat

        //
        //  TryParseByFormat
        //
        //  Actions: Parse the TimeSpan instance using the specified format.  Used by TryParseExactTimeSpan.
        // 
        private static Boolean TryParseByFormat(String input, String format, TimeSpanStyles styles, ref TimeSpanResult result) {
            Debug.Assert(input != null, "input != null");
            Debug.Assert(format != null, "format != null");

            bool seenDD = false;      // already processed days?
            bool seenHH = false;      // already processed hours?
            bool seenMM = false;      // already processed minutes?
            bool seenSS = false;      // already processed seconds?
            bool seenFF = false;      // already processed fraction?
            int dd = 0;               // parsed days
            int hh = 0;               // parsed hours
            int mm = 0;               // parsed minutes
            int ss = 0;               // parsed seconds
            int leadingZeroes = 0;    // number of leading zeroes in the parsed fraction
            int ff = 0;               // parsed fraction
            int i = 0;                // format string position
            int tokenLen = 0;         // length of current format token, used to update index 'i'

            TimeSpanTokenizer tokenizer = new TimeSpanTokenizer();
            tokenizer.Init(input, -1);

            while (i < format.Length) {
                char ch = format[i];
                int nextFormatChar;
                switch (ch) {
                    case 'h':
                        tokenLen = DateTimeFormat.ParseRepeatPattern(format, i, ch);
                        if (tokenLen > 2 || seenHH || !ParseExactDigits(ref tokenizer, tokenLen, out hh)) {
                            result.SetFailure(ParseFailureKind.Format, "Format_InvalidString");
                            return false;
                        }
                        seenHH = true;
                        break;
                    case 'm':
                        tokenLen = DateTimeFormat.ParseRepeatPattern(format, i, ch);
                        if (tokenLen > 2 || seenMM || !ParseExactDigits(ref tokenizer, tokenLen, out mm)) {
                            result.SetFailure(ParseFailureKind.Format, "Format_InvalidString");
                            return false;
                        }
                        seenMM = true;
                        break;
                    case 's':
                        tokenLen = DateTimeFormat.ParseRepeatPattern(format, i, ch);
                        if (tokenLen > 2 || seenSS || !ParseExactDigits(ref tokenizer, tokenLen, out ss)) {
                            result.SetFailure(ParseFailureKind.Format, "Format_InvalidString");
                            return false;
                        }
                        seenSS = true;
                        break;
                    case 'f':
                        tokenLen = DateTimeFormat.ParseRepeatPattern(format, i, ch);
                        if (tokenLen > DateTimeFormat.MaxSecondsFractionDigits || seenFF || !ParseExactDigits(ref tokenizer, tokenLen, tokenLen, out leadingZeroes, out ff)) {
                            result.SetFailure(ParseFailureKind.Format, "Format_InvalidString");
                            return false;
                        }
                        seenFF = true;
                        break;
                    case 'F':
                        tokenLen = DateTimeFormat.ParseRepeatPattern(format, i, ch);
                        if (tokenLen > DateTimeFormat.MaxSecondsFractionDigits || seenFF) {
                            result.SetFailure(ParseFailureKind.Format, "Format_InvalidString");
                            return false;
                        }
                        ParseExactDigits(ref tokenizer, tokenLen, tokenLen, out leadingZeroes, out ff);
                        seenFF = true;
                        break;
                    case 'd':
                        tokenLen = DateTimeFormat.ParseRepeatPattern(format, i, ch);
                        int tmp = 0;
                        if (tokenLen > 8 || seenDD || !ParseExactDigits(ref tokenizer, (tokenLen<2) ? 1 : tokenLen, (tokenLen<2) ? 8 : tokenLen, out tmp, out dd)) {
                            result.SetFailure(ParseFailureKind.Format, "Format_InvalidString");
                            return false;
                        }
                        seenDD = true;
                        break;
                    case '\'':
                    case '\"':
                        StringBuilder enquotedString = new StringBuilder();
                        if (!DateTimeParse.TryParseQuoteString(format, i, enquotedString, out tokenLen)) {
                            result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadQuote", ch);
                            return false;
                        }
                        if (!ParseExactLiteral(ref tokenizer, enquotedString)) {
                            result.SetFailure(ParseFailureKind.Format, "Format_InvalidString");
                            return false;
                        }
                        break;
                    case '%':
                        // Optional format character.
                        // For example, format string "%d" will print day 
                        // Most of the cases, "%" can be ignored.
                        nextFormatChar = DateTimeFormat.ParseNextChar(format, i);
                        // nextFormatChar will be -1 if we already reach the end of the format string.
                        // Besides, we will not allow "%%" appear in the pattern.
                        if (nextFormatChar >= 0 && nextFormatChar != (int)'%') {
//.........这里部分代码省略.........
开发者ID:kouvel,项目名称:coreclr,代码行数:101,代码来源:TimeSpanParse.cs

示例12: ProcessTerminal_D

 private static bool ProcessTerminal_D(ref TimeSpanRawInfo raw, TimeSpanStandardStyles style, ref TimeSpanResult result)
 {
     if (((raw.SepCount != 2) || (raw.NumCount != 1)) || ((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.FullDMatch(raw.PositiveInvariant))
         {
             flag4 = true;
             positive = true;
         }
         if (!flag4 && raw.FullDMatch(raw.NegativeInvariant))
         {
             flag4 = true;
             positive = false;
         }
     }
     if (flag2)
     {
         if (!flag4 && raw.FullDMatch(raw.PositiveLocalized))
         {
             flag4 = true;
             positive = true;
         }
         if (!flag4 && raw.FullDMatch(raw.NegativeLocalized))
         {
             flag4 = true;
             positive = false;
         }
     }
     long num = 0L;
     if (flag4)
     {
         if (!TryTimeToTicks(positive, raw.numbers[0], zero, zero, 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;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:60,代码来源:TimeSpanParse.cs

示例13: TryParseTimeSpan

 private static bool TryParseTimeSpan(string input, TimeSpanStandardStyles style, IFormatProvider formatProvider, ref TimeSpanResult result)
 {
     if (input == null)
     {
         result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, "input");
         return false;
     }
     input = input.Trim();
     if (input == string.Empty)
     {
         result.SetFailure(ParseFailureKind.Format, "Format_BadTimeSpan");
         return false;
     }
     TimeSpanTokenizer tokenizer = new TimeSpanTokenizer();
     tokenizer.Init(input);
     TimeSpanRawInfo raw = new TimeSpanRawInfo();
     raw.Init(DateTimeFormatInfo.GetInstance(formatProvider));
     for (TimeSpanToken token = tokenizer.GetNextToken(); token.ttt != TTT.End; token = tokenizer.GetNextToken())
     {
         if (!raw.ProcessToken(ref token, ref result))
         {
             result.SetFailure(ParseFailureKind.Format, "Format_BadTimeSpan");
             return false;
         }
     }
     if (!tokenizer.EOL)
     {
         result.SetFailure(ParseFailureKind.Format, "Format_BadTimeSpan");
         return false;
     }
     if (!ProcessTerminalState(ref raw, style, ref result))
     {
         result.SetFailure(ParseFailureKind.Format, "Format_BadTimeSpan");
         return false;
     }
     return true;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:37,代码来源:TimeSpanParse.cs

示例14: TryParseExactTimeSpan

 private static bool TryParseExactTimeSpan(string input, string format, IFormatProvider formatProvider, TimeSpanStyles styles, ref TimeSpanResult result)
 {
     if (input == null)
     {
         result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, "input");
         return false;
     }
     if (format == null)
     {
         result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, "format");
         return false;
     }
     if (format.Length == 0)
     {
         result.SetFailure(ParseFailureKind.Format, "Format_BadFormatSpecifier");
         return false;
     }
     if (format.Length != 1)
     {
         return TryParseByFormat(input, format, styles, ref result);
     }
     TimeSpanStandardStyles none = TimeSpanStandardStyles.None;
     if (((format[0] == 'c') || (format[0] == 't')) || (format[0] == 'T'))
     {
         return TryParseTimeSpanConstant(input, ref result);
     }
     if (format[0] == 'g')
     {
         none = TimeSpanStandardStyles.Localized;
     }
     else if (format[0] == 'G')
     {
         none = TimeSpanStandardStyles.RequireFull | TimeSpanStandardStyles.Localized;
     }
     else
     {
         result.SetFailure(ParseFailureKind.Format, "Format_BadFormatSpecifier");
         return false;
     }
     return TryParseTimeSpan(input, none, formatProvider, ref result);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:41,代码来源:TimeSpanParse.cs

示例15: ProcessTerminal_HM_S_D

        //
        //  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");
//.........这里部分代码省略.........
开发者ID:kouvel,项目名称:coreclr,代码行数:101,代码来源:TimeSpanParse.cs


注:本文中的TimeSpanResult.SetFailure方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。