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


C# System.__DTString类代码示例

本文整理汇总了C#中System.__DTString的典型用法代码示例。如果您正苦于以下问题:C# __DTString类的具体用法?C# __DTString怎么用?C# __DTString使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: GetTimeZoneName

        //
        // Check the word at the current index to see if it matches GMT name or Zulu name.
        //
        private static bool GetTimeZoneName(ref __DTString str)
        {
            if (MatchWord(ref str, GMTName)) {
                return (true);
            }

            if (MatchWord(ref str, ZuluName)) {
                return (true);
            }

            return (false);
        }
开发者ID:ChuangYang,项目名称:coreclr,代码行数:15,代码来源:DateTimeParse.cs

示例2: HandleTimeZone

		private static bool HandleTimeZone(ref __DTString str, ref DateTimeResult result)
		{
			if (str.Index < str.len - 1)
			{
				char c = str.Value[str.Index];
				int num = 0;
				while (char.IsWhiteSpace(c) && str.Index + num < str.len - 1)
				{
					num++;
					c = str.Value[str.Index + num];
				}
				if (c == '+' || c == '-')
				{
					str.Index += num;
					if ((result.flags & ParseFlags.TimeZoneUsed) != (ParseFlags)0)
					{
						result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
						return false;
					}
					result.flags |= ParseFlags.TimeZoneUsed;
					if (!DateTimeParse.ParseTimeZone(ref str, ref result.timeZoneOffset))
					{
						result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
						return false;
					}
				}
			}
			return true;
		}
开发者ID:ChristianWulf,项目名称:CSharpKDMDiscoverer,代码行数:29,代码来源:DateTimeParse.cs

示例3: TryParseHebrewNumber

        ////////////////////////////////////////////////////////////////////////
        //
        // Actions:
        // Try to parse the current word to see if it is a Hebrew number.
        // Tokens will be updated accordingly.
        // This is called by the Lexer of DateTime.Parse().
        //
        // Unlike most of the functions in this class, the return value indicates
        // whether or not it started to parse. The badFormat parameter indicates
        // if parsing began, but the format was bad.
        //
        ////////////////////////////////////////////////////////////////////////

        private static bool TryParseHebrewNumber(
            ref __DTString str,
            out Boolean badFormat,
            out int number)  {

            number = -1;
            badFormat = false;

            int i = str.Index;
            if (!HebrewNumber.IsDigit(str.Value[i])) {
                // If the current character is not a Hebrew digit, just return false.
                // There is no chance that we can parse a valid Hebrew number from here.
                return (false);
            }
            // The current character is a Hebrew digit.  Try to parse this word as a Hebrew number.
            HebrewNumberParsingContext context = new HebrewNumberParsingContext(0);
            HebrewNumberParsingState state;

            do {
                state = HebrewNumber.ParseByChar(str.Value[i++], ref context);
                switch (state) {
                    case HebrewNumberParsingState.InvalidHebrewNumber:    // Not a valid Hebrew number.
                    case HebrewNumberParsingState.NotHebrewDigit:         // The current character is not a Hebrew digit character.
                        // Break out so that we don't continue to try parse this as a Hebrew number.
                        return (false);
                }
            } while (i < str.Value.Length && (state != HebrewNumberParsingState.FoundEndOfHebrewNumber));

            // When we are here, we are either at the end of the string, or we find a valid Hebrew number.
            Contract.Assert(state == HebrewNumberParsingState.ContinueParsing || state == HebrewNumberParsingState.FoundEndOfHebrewNumber,
                "Invalid returned state from HebrewNumber.ParseByChar()");

            if (state != HebrewNumberParsingState.FoundEndOfHebrewNumber) {
                // We reach end of the string but we can't find a terminal state in parsing Hebrew number.
                return (false);
            }

            // We have found a valid Hebrew number.  Update the index.
            str.Advance(i - str.Index);

            // Get the final Hebrew number value from the HebrewNumberParsingContext.
            number = context.result;

            return (true);
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:58,代码来源:DateTimeFormatInfo.cs

示例4: MatchWord

		private static bool MatchWord(ref __DTString str, string target)
		{
			int length = target.Length;
			if (length > str.Value.Length - str.Index)
			{
				return false;
			}
			if (str.CompareInfo.Compare(str.Value, str.Index, length, target, 0, length, CompareOptions.IgnoreCase) != 0)
			{
				return false;
			}
			int num = str.Index + target.Length;
			if (num < str.Value.Length)
			{
				char c = str.Value[num];
				if (char.IsLetter(c))
				{
					return false;
				}
			}
			str.Index = num;
			if (str.Index < str.len)
			{
				str.m_current = str.Value[str.Index];
			}
			return true;
		}
开发者ID:ChristianWulf,项目名称:CSharpKDMDiscoverer,代码行数:27,代码来源:DateTimeParse.cs

示例5: ParseFraction

		private static bool ParseFraction(ref __DTString str, out double result)
		{
			result = 0.0;
			double num = 0.1;
			int num2 = 0;
			char current;
			while (str.GetNext() && DateTimeParse.IsDigit(current = str.m_current))
			{
				result += (double)(current - '0') * num;
				num *= 0.1;
				num2++;
			}
			return num2 > 0;
		}
开发者ID:ChristianWulf,项目名称:CSharpKDMDiscoverer,代码行数:14,代码来源:DateTimeParse.cs

示例6: MatchTimeMark

		private static bool MatchTimeMark(ref __DTString str, DateTimeFormatInfo dtfi, ref DateTimeParse.TM result)
		{
			result = DateTimeParse.TM.NotSet;
			if (dtfi.AMDesignator.Length == 0)
			{
				result = DateTimeParse.TM.AM;
			}
			if (dtfi.PMDesignator.Length == 0)
			{
				result = DateTimeParse.TM.PM;
			}
			if (str.GetNext())
			{
				string text = dtfi.AMDesignator;
				if (text.Length > 0 && str.MatchSpecifiedWord(text))
				{
					str.Index += text.Length - 1;
					result = DateTimeParse.TM.AM;
					return true;
				}
				text = dtfi.PMDesignator;
				if (text.Length > 0 && str.MatchSpecifiedWord(text))
				{
					str.Index += text.Length - 1;
					result = DateTimeParse.TM.PM;
					return true;
				}
				str.Index--;
			}
			return result != -1;
		}
开发者ID:ChristianWulf,项目名称:CSharpKDMDiscoverer,代码行数:31,代码来源:DateTimeParse.cs

示例7: ParseByFormat

		private static bool ParseByFormat(ref __DTString str, ref __DTString format, ref ParsingInfo parseInfo, DateTimeFormatInfo dtfi, ref DateTimeResult result)
		{
			int num = 0;
			int newValue = 0;
			int newValue2 = 0;
			int newValue3 = 0;
			int newValue4 = 0;
			int newValue5 = 0;
			int newValue6 = 0;
			int newValue7 = 0;
			double num2 = 0.0;
			DateTimeParse.TM tM = DateTimeParse.TM.AM;
			char @char = format.GetChar();
			char c = @char;
			if (c <= 'H')
			{
				if (c <= '\'')
				{
					if (c != '"')
					{
						switch (c)
						{
							case '%':
							{
								if (format.Index >= format.Value.Length - 1 || format.Value[format.Index + 1] == '%')
								{
									result.SetFailure(ParseFailureKind.Format, "Format_BadFormatSpecifier", null);
									return false;
								}
								return true;
							}
							case '&':
							{
								goto IL_991;
							}
							case '\'':
							{
								break;
							}
							default:
							{
								goto IL_991;
							}
						}
					}
					StringBuilder stringBuilder = new StringBuilder();
					if (!DateTimeParse.TryParseQuoteString(format.Value, format.Index, stringBuilder, out num))
					{
						result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadQuote", @char);
						return false;
					}
					format.Index += num - 1;
					string text = stringBuilder.ToString();
					for (int i = 0; i < text.Length; i++)
					{
						if (text[i] == ' ' && parseInfo.fAllowInnerWhite)
						{
							str.SkipWhiteSpaces();
						}
						else
						{
							if (!str.Match(text[i]))
							{
								result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
								return false;
							}
						}
					}
					if ((result.flags & ParseFlags.CaptureOffset) == (ParseFlags)0)
					{
						return true;
					}
					if ((result.flags & ParseFlags.Rfc1123Pattern) != (ParseFlags)0 && text == "GMT")
					{
						result.flags |= ParseFlags.TimeZoneUsed;
						result.timeZoneOffset = TimeSpan.Zero;
						return true;
					}
					if ((result.flags & ParseFlags.UtcSortPattern) != (ParseFlags)0 && text == "Z")
					{
						result.flags |= ParseFlags.TimeZoneUsed;
						result.timeZoneOffset = TimeSpan.Zero;
						return true;
					}
					return true;
				}
				else
				{
					switch (c)
					{
						case '.':
						{
							if (str.Match(@char))
							{
								return true;
							}
							if (format.GetNext() && format.Match('F'))
							{
								format.GetRepeatCount();
								return true;
//.........这里部分代码省略.........
开发者ID:ChristianWulf,项目名称:CSharpKDMDiscoverer,代码行数:101,代码来源:DateTimeParse.cs

示例8: TryParse

		internal unsafe static bool TryParse(string s, DateTimeFormatInfo dtfi, DateTimeStyles styles, ref DateTimeResult result)
		{
			if (s == null)
			{
				result.SetFailure(ParseFailureKind.ArgumentNull, "ArgumentNull_String", null, "s");
				return false;
			}
			if (s.Length == 0)
			{
				result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
				return false;
			}
			DateTimeParse.DS dS = DateTimeParse.DS.BEGIN;
			bool flag = false;
			DateTimeToken dateTimeToken = default(DateTimeToken);
			dateTimeToken.suffix = TokenType.SEP_Unk;
			DateTimeRawInfo dateTimeRawInfo = default(DateTimeRawInfo);
			int* numberBuffer = stackalloc int[(UIntPtr)3];
			dateTimeRawInfo.Init(numberBuffer);
			result.calendar = dtfi.Calendar;
			result.era = 0;
			__DTString _DTString = new __DTString(s, dtfi);
			_DTString.GetNext();
			while (DateTimeParse.Lex(dS, ref _DTString, ref dateTimeToken, ref dateTimeRawInfo, ref result, ref dtfi))
			{
				if (dateTimeToken.dtt != DateTimeParse.DTT.Unk)
				{
					if (dateTimeToken.suffix != TokenType.SEP_Unk)
					{
						if (!DateTimeParse.ProcessDateTimeSuffix(ref result, ref dateTimeRawInfo, ref dateTimeToken))
						{
							result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
							return false;
						}
						dateTimeToken.suffix = TokenType.SEP_Unk;
					}
					if (dateTimeToken.dtt == DateTimeParse.DTT.NumLocalTimeMark)
					{
						if (dS == DateTimeParse.DS.D_YNd || dS == DateTimeParse.DS.D_YN)
						{
							return DateTimeParse.ParseISO8601(ref dateTimeRawInfo, ref _DTString, styles, ref result);
						}
						result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
						return false;
					}
					else
					{
						dS = DateTimeParse.dateParsingStates[(int)dS][(int)dateTimeToken.dtt];
						if (dS == DateTimeParse.DS.ERROR)
						{
							result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
							return false;
						}
						if (dS > DateTimeParse.DS.ERROR)
						{
							if ((dtfi.FormatFlags & DateTimeFormatFlags.UseHebrewRule) != DateTimeFormatFlags.None)
							{
								if (!DateTimeParse.ProcessHebrewTerminalState(dS, ref result, ref styles, ref dateTimeRawInfo, dtfi))
								{
									return false;
								}
							}
							else
							{
								if (!DateTimeParse.ProcessTerminaltState(dS, ref result, ref styles, ref dateTimeRawInfo, dtfi))
								{
									return false;
								}
							}
							flag = true;
							dS = DateTimeParse.DS.BEGIN;
						}
					}
				}
				if (dateTimeToken.dtt == DateTimeParse.DTT.End || dateTimeToken.dtt == DateTimeParse.DTT.NumEnd || dateTimeToken.dtt == DateTimeParse.DTT.MonthEnd)
				{
					if (!flag)
					{
						result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
						return false;
					}
					DateTimeParse.AdjustTimeMark(dtfi, ref dateTimeRawInfo);
					if (!DateTimeParse.AdjustHour(ref result.Hour, dateTimeRawInfo.timeMark))
					{
						result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
						return false;
					}
					bool bTimeOnly = result.Year == -1 && result.Month == -1 && result.Day == -1;
					if (!DateTimeParse.CheckDefaultDateTime(ref result, ref result.calendar, styles))
					{
						return false;
					}
					DateTime dateTime;
					if (!result.calendar.TryToDateTime(result.Year, result.Month, result.Day, result.Hour, result.Minute, result.Second, 0, result.era, out dateTime))
					{
						result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, "Format_BadDateTimeCalendar", null);
						return false;
					}
					if (dateTimeRawInfo.fraction > 0.0)
					{
//.........这里部分代码省略.........
开发者ID:ChristianWulf,项目名称:CSharpKDMDiscoverer,代码行数:101,代码来源:DateTimeParse.cs

示例9: ParseISO8601

		private static bool ParseISO8601(ref DateTimeRawInfo raw, ref __DTString str, DateTimeStyles styles, ref DateTimeResult result)
		{
			if (raw.year >= 0 && raw.GetNumber(0) >= 0)
			{
				raw.GetNumber(1);
			}
			str.Index--;
			int second = 0;
			double num = 0.0;
			str.SkipWhiteSpaces();
			int hour;
			if (!DateTimeParse.ParseDigits(ref str, 2, out hour))
			{
				result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
				return false;
			}
			str.SkipWhiteSpaces();
			if (!str.Match(':'))
			{
				result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
				return false;
			}
			str.SkipWhiteSpaces();
			int minute;
			if (!DateTimeParse.ParseDigits(ref str, 2, out minute))
			{
				result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
				return false;
			}
			str.SkipWhiteSpaces();
			if (str.Match(':'))
			{
				str.SkipWhiteSpaces();
				if (!DateTimeParse.ParseDigits(ref str, 2, out second))
				{
					result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
					return false;
				}
				if (str.Match('.'))
				{
					if (!DateTimeParse.ParseFraction(ref str, out num))
					{
						result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
						return false;
					}
					str.Index--;
				}
				str.SkipWhiteSpaces();
			}
			if (str.GetNext())
			{
				char @char = str.GetChar();
				if (@char == '+' || @char == '-')
				{
					result.flags |= ParseFlags.TimeZoneUsed;
					if (!DateTimeParse.ParseTimeZone(ref str, ref result.timeZoneOffset))
					{
						result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
						return false;
					}
				}
				else
				{
					if (@char == 'Z' || @char == 'z')
					{
						result.flags |= ParseFlags.TimeZoneUsed;
						result.timeZoneOffset = TimeSpan.Zero;
						result.flags |= ParseFlags.TimeZoneUtc;
					}
					else
					{
						str.Index--;
					}
				}
				str.SkipWhiteSpaces();
				if (str.Match('#'))
				{
					if (!DateTimeParse.VerifyValidPunctuation(ref str))
					{
						result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
						return false;
					}
					str.SkipWhiteSpaces();
				}
				if (str.Match('\0') && !DateTimeParse.VerifyValidPunctuation(ref str))
				{
					result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
					return false;
				}
				if (str.GetNext())
				{
					result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
					return false;
				}
			}
			Calendar defaultInstance = GregorianCalendar.GetDefaultInstance();
			DateTime parsedDate;
			if (!defaultInstance.TryToDateTime(raw.year, raw.GetNumber(0), raw.GetNumber(1), hour, minute, second, 0, result.era, out parsedDate))
			{
				result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, "Format_BadDateTimeCalendar", null);
//.........这里部分代码省略.........
开发者ID:ChristianWulf,项目名称:CSharpKDMDiscoverer,代码行数:101,代码来源:DateTimeParse.cs

示例10: Lex

        [System.Security.SecuritySafeCritical]  // auto-generated
        private static Boolean Lex(DS dps, ref __DTString str, ref DateTimeToken dtok, ref DateTimeRawInfo raw, ref DateTimeResult result, ref DateTimeFormatInfo dtfi, DateTimeStyles styles)
        {

            TokenType tokenType;
            int tokenValue;
            int indexBeforeSeparator;
            char charBeforeSeparator;

            TokenType sep;
            dtok.dtt = DTT.Unk;     // Assume the token is unkown.

            str.GetRegularToken(out tokenType, out tokenValue, dtfi);

#if _LOGGING
            // Builds with _LOGGING defined (x86dbg, amd64chk, etc) support tracing
            // Set the following internal-only/unsupported environment variables to enable DateTime tracing to the console:
            //
            // COMPlus_LogEnable=1
            // COMPlus_LogToConsole=1
            // COMPlus_LogLevel=9
            // COMPlus_ManagedLogFacility=0x00001000
            if (_tracingEnabled) {
                BCLDebug.Trace("DATETIME", "[DATETIME] Lex({0})\tpos:{1}({2}), {3}, DS.{4}", Hex(str.Value),
                               str.Index, Hex(str.m_current), tokenType, dps);
            }
#endif // _LOGGING

            // Look at the regular token.
            switch (tokenType) {
                case TokenType.NumberToken:
                case TokenType.YearNumberToken:
                    if (raw.numCount == 3 || tokenValue == -1) {
                        result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
                        LexTraceExit("0010", dps);
                        return false;
                    }
                    //
                    // This is a digit.
                    //
                    // If the previous parsing state is DS.T_NNt (like 12:01), and we got another number,
                    // so we will have a terminal state DS.TX_NNN (like 12:01:02).
                    // If the previous parsing state is DS.T_Nt (like 12:), and we got another number,
                    // so we will have a terminal state DS.TX_NN (like 12:01).
                    //
                    // Look ahead to see if the following character is a decimal point or timezone offset.
                    // This enables us to parse time in the forms of:
                    //  "11:22:33.1234" or "11:22:33-08".
                    if (dps == DS.T_NNt) {
                        if ((str.Index < str.len - 1)) {
                            char nextCh = str.Value[str.Index];
                            if (nextCh == '.') {
                                // While ParseFraction can fail, it just means that there were no digits after
                                // the dot. In this case ParseFraction just removes the dot. This is actually
                                // valid for cultures like Albanian, that join the time marker to the time with
                                // with a dot: e.g. "9:03.MD"
                                ParseFraction(ref str, out raw.fraction);
                            }
                        }
                    }
                    if (dps == DS.T_NNt || dps == DS.T_Nt) {
                        if ((str.Index < str.len - 1)) {
                            if (false == HandleTimeZone(ref str, ref result))
                            {
                                LexTraceExit("0020 (value like \"12:01\" or \"12:\" followed by a non-TZ number", dps);
                                return false;
                            }
                        }                        
                    }

                    dtok.num = tokenValue;
                    if (tokenType == TokenType.YearNumberToken)
                    {
                        if (raw.year == -1)
                        {
                            raw.year = tokenValue;
                            //
                            // If we have number which has 3 or more digits (like "001" or "0001"),
                            // we assume this number is a year. Save the currnet raw.numCount in
                            // raw.year.
                            //
                            switch (sep = str.GetSeparatorToken(dtfi, out indexBeforeSeparator, out charBeforeSeparator)) {
                                case TokenType.SEP_End:
                                    dtok.dtt     = DTT.YearEnd;
                                    break;
                                case TokenType.SEP_Am:
                                case TokenType.SEP_Pm:
                                    if (raw.timeMark == TM.NotSet) {
                                        raw.timeMark = (sep == TokenType.SEP_Am ? TM.AM : TM.PM);
                                        dtok.dtt    = DTT.YearSpace;
                                    } else {
                                        result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
                                        LexTraceExit("0030 (TM.AM/TM.PM Happened more than 1x)", dps);
                                    }
                                    break;
                                case TokenType.SEP_Space:
                                    dtok.dtt    = DTT.YearSpace;
                                    break;
                                case TokenType.SEP_Date:
                                    dtok.dtt     = DTT.YearDateSep;
//.........这里部分代码省略.........
开发者ID:ChuangYang,项目名称:coreclr,代码行数:101,代码来源:DateTimeParse.cs

示例11: VerifyValidPunctuation

		private static bool VerifyValidPunctuation(ref __DTString str)
		{
			char c = str.Value[str.Index];
			if (c == '#')
			{
				bool flag = false;
				bool flag2 = false;
				for (int i = 0; i < str.len; i++)
				{
					c = str.Value[i];
					if (c == '#')
					{
						if (flag)
						{
							if (flag2)
							{
								return false;
							}
							flag2 = true;
						}
						else
						{
							flag = true;
						}
					}
					else
					{
						if (c == '\0')
						{
							if (!flag2)
							{
								return false;
							}
						}
						else
						{
							if (!char.IsWhiteSpace(c) && (!flag || flag2))
							{
								return false;
							}
						}
					}
				}
				if (!flag2)
				{
					return false;
				}
				str.GetNext();
				return true;
			}
			else
			{
				if (c == '\0')
				{
					for (int j = str.Index; j < str.len; j++)
					{
						if (str.Value[j] != '\0')
						{
							return false;
						}
					}
					str.Index = str.len;
					return true;
				}
				return false;
			}
		}
开发者ID:ChristianWulf,项目名称:CSharpKDMDiscoverer,代码行数:67,代码来源:DateTimeParse.cs

示例12: HandleTimeZone

 // This is the helper function to handle timezone in string in the format like +/-0800
 private static bool HandleTimeZone(ref __DTString str, ref DateTimeResult result)
 {
     if ((str.Index < str.len - 1)) {
         char nextCh = str.Value[str.Index];
         // Skip whitespace, but don't update the index unless we find a time zone marker
         int whitespaceCount = 0;
         while (Char.IsWhiteSpace(nextCh) && str.Index + whitespaceCount < str.len - 1) {
             whitespaceCount++;
             nextCh = str.Value[str.Index + whitespaceCount];
         }
         if (nextCh == '+' || nextCh == '-') {
             str.Index += whitespaceCount;
             if ((result.flags & ParseFlags.TimeZoneUsed) != 0) {
                 // Should not have two timezone offsets.
                 result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
                 return false;
             }
             result.flags |= ParseFlags.TimeZoneUsed;
             if (!ParseTimeZone(ref str, ref result.timeZoneOffset)) {
                 result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
                 return false;
             }
         }
     }                        
     return true;
 }
开发者ID:ChuangYang,项目名称:coreclr,代码行数:27,代码来源:DateTimeParse.cs

示例13: ParseTimeZone

        /*=================================ParseTimeZone==========================
        **Action: Parse the timezone offset in the following format:
        **          "+8", "+08", "+0800", "+0800"
        **        This method is used by DateTime.Parse().
        **Returns:      The TimeZone offset.
        **Arguments:
        **      str the parsing string
        **Exceptions:
        **      FormatException if invalid timezone format is found.
        ============================================================================*/

        private static bool ParseTimeZone(ref __DTString str, ref TimeSpan result) {
            // The hour/minute offset for timezone.
            int hourOffset = 0;
            int minuteOffset = 0;
            DTSubString sub;

            // Consume the +/- character that has already been read
            sub = str.GetSubString();
            if (sub.length != 1) {
                return false;
            }
            char offsetChar = sub[0];
            if (offsetChar != '+' && offsetChar != '-') {
                return false;
            }
            str.ConsumeSubString(sub);

            sub = str.GetSubString();
            if (sub.type != DTSubStringType.Number) {
                return false;
            }
            int value = sub.value;
            int length = sub.length;
            if (length == 1 || length == 2) {
                // Parsing "+8" or "+08"
                hourOffset = value;
                str.ConsumeSubString(sub);
                // See if we have minutes
                sub = str.GetSubString();
                if (sub.length == 1 && sub[0] == ':') {
                    // Parsing "+8:00" or "+08:00"
                    str.ConsumeSubString(sub);
                    sub = str.GetSubString();
                    if (sub.type != DTSubStringType.Number || sub.length < 1 || sub.length > 2) {
                        return false;
                    }
                    minuteOffset = sub.value;
                    str.ConsumeSubString(sub);
                }
            }
            else if (length == 3 || length == 4) {
                // Parsing "+800" or "+0800"
                hourOffset = value / 100;
                minuteOffset = value % 100;
                str.ConsumeSubString(sub);
            }
            else {
                // Wrong number of digits
                return false;
            }
            Contract.Assert(hourOffset >= 0 && hourOffset <= 99, "hourOffset >= 0 && hourOffset <= 99");
            Contract.Assert(minuteOffset >= 0 && minuteOffset <= 99, "minuteOffset >= 0 && minuteOffset <= 99");
            if (minuteOffset < 0 || minuteOffset >= 60) {
                return false;
            }

            result = new TimeSpan(hourOffset, minuteOffset, 0);
            if (offsetChar == '-') {
                result = result.Negate();
            }
            return true;
        }
开发者ID:ChuangYang,项目名称:coreclr,代码行数:73,代码来源:DateTimeParse.cs

示例14: ParseFraction

        /*=================================ParseFraction==========================
        **Action: Starting at the str.Index, which should be a decimal symbol.
        ** if the current character is a digit, parse the remaining
        **      numbers as fraction.  For example, if the sub-string starting at str.Index is "123", then
        **      the method will return 0.123
        **Returns:      The fraction number.
        **Arguments:
        **      str the parsing string
        **Exceptions:
        ============================================================================*/

        private static bool ParseFraction(ref __DTString str, out double result) {
            result = 0;
            double decimalBase = 0.1;
            int digits = 0;
            char ch;
            while (str.GetNext()
                   && IsDigit(ch = str.m_current)) {
                result += (ch - '0') * decimalBase;
                decimalBase *= 0.1;
                digits++;
            }
            return (digits > 0);
        }
开发者ID:ChuangYang,项目名称:coreclr,代码行数:24,代码来源:DateTimeParse.cs

示例15: MatchDayName

		private static bool MatchDayName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result)
		{
			int num = 0;
			result = -1;
			if (str.GetNext())
			{
				for (DayOfWeek dayOfWeek = DayOfWeek.Sunday; dayOfWeek <= DayOfWeek.Saturday; dayOfWeek += DayOfWeek.Monday)
				{
					string dayName = dtfi.GetDayName(dayOfWeek);
					int length = dayName.Length;
					if ((dtfi.HasSpacesInDayNames ? str.MatchSpecifiedWords(dayName, false, ref length) : str.MatchSpecifiedWord(dayName)) && length > num)
					{
						num = length;
						result = (int)dayOfWeek;
					}
				}
			}
			if (result >= 0)
			{
				str.Index += num - 1;
				return true;
			}
			return false;
		}
开发者ID:ChristianWulf,项目名称:CSharpKDMDiscoverer,代码行数:24,代码来源:DateTimeParse.cs


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