本文整理汇总了C#中System.__DTString.GetChar方法的典型用法代码示例。如果您正苦于以下问题:C# __DTString.GetChar方法的具体用法?C# __DTString.GetChar怎么用?C# __DTString.GetChar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.__DTString
的用法示例。
在下文中一共展示了__DTString.GetChar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
//.........这里部分代码省略.........
示例2: MatchAbbreviatedTimeMark
/*=================================MatchAbbreviatedTimeMark==================================
**Action: Parse the abbreviated time mark (AM/PM) from string starting at str.Index.
**Returns: TM_AM or TM_PM.
**Arguments: str: a __DTString. The parsing will start from the
** next character after str.Index.
**Exceptions: FormatException if a abbreviated time mark can not be found.
==============================================================================*/
private static bool MatchAbbreviatedTimeMark(ref __DTString str, DateTimeFormatInfo dtfi, ref TM result) {
// NOTENOTE : the assumption here is that abbreviated time mark is the first
// character of the AM/PM designator. If this invariant changes, we have to
// change the code below.
if (str.GetNext())
{
if (str.GetChar() == dtfi.AMDesignator[0]) {
result = TM.AM;
return (true);
}
if (str.GetChar() == dtfi.PMDesignator[0]) {
result = TM.PM;
return (true);
}
}
return false;
}
示例3: ParseByFormat
// Given a specified format character, parse and update the parsing result.
//
private static bool ParseByFormat(
ref __DTString str,
ref __DTString format,
ref ParsingInfo parseInfo,
DateTimeFormatInfo dtfi,
ref DateTimeResult result) {
int tokenLen = 0;
int tempYear = 0, tempMonth = 0, tempDay = 0, tempDayOfWeek = 0, tempHour = 0, tempMinute = 0, tempSecond = 0;
double tempFraction = 0;
TM tempTimeMark = 0;
char ch = format.GetChar();
switch (ch) {
case 'y':
tokenLen = format.GetRepeatCount();
bool parseResult;
if (dtfi.HasForceTwoDigitYears) {
parseResult = ParseDigits(ref str, 1, 4, out tempYear);
}
else {
if (tokenLen <= 2) {
parseInfo.fUseTwoDigitYear = true;
}
parseResult = ParseDigits(ref str, tokenLen, out tempYear);
}
if (!parseResult && parseInfo.fCustomNumberParser) {
parseResult = parseInfo.parseNumberDelegate(ref str, tokenLen, out tempYear);
}
if (!parseResult) {
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return (false);
}
if (!CheckNewValue(ref result.Year, tempYear, ch, ref result)) {
return (false);
}
break;
case 'M':
tokenLen = format.GetRepeatCount();
if (tokenLen <= 2) {
if (!ParseDigits(ref str, tokenLen, out tempMonth)) {
if (!parseInfo.fCustomNumberParser ||
!parseInfo.parseNumberDelegate(ref str, tokenLen, out tempMonth)) {
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return (false);
}
}
} else {
if (tokenLen == 3) {
if (!MatchAbbreviatedMonthName(ref str, dtfi, ref tempMonth)) {
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return (false);
}
} else {
if (!MatchMonthName(ref str, dtfi, ref tempMonth)) {
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return (false);
}
}
result.flags |= ParseFlags.ParsedMonthName;
}
if (!CheckNewValue(ref result.Month, tempMonth, ch, ref result)) {
return (false);
}
break;
case 'd':
// Day & Day of week
tokenLen = format.GetRepeatCount();
if (tokenLen <= 2) {
// "d" & "dd"
if (!ParseDigits(ref str, tokenLen, out tempDay)) {
if (!parseInfo.fCustomNumberParser ||
!parseInfo.parseNumberDelegate(ref str, tokenLen, out tempDay)) {
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return (false);
}
}
if (!CheckNewValue(ref result.Day, tempDay, ch, ref result)) {
return (false);
}
} else {
if (tokenLen == 3) {
// "ddd"
if (!MatchAbbreviatedDayName(ref str, dtfi, ref tempDayOfWeek)) {
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return (false);
}
} else {
// "dddd*"
if (!MatchDayName(ref str, dtfi, ref tempDayOfWeek)) {
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return (false);
}
}
if (!CheckNewValue(ref parseInfo.dayOfWeek, tempDayOfWeek, ch, ref result)) {
return (false);
//.........这里部分代码省略.........
示例4: MatchHebrewDigits
////////////////////////////////////////////////////////////////////////
//
// Actions:
// Parse the current word as a Hebrew number.
// This is used by DateTime.ParseExact().
//
////////////////////////////////////////////////////////////////////////
internal static bool MatchHebrewDigits(ref __DTString str, int digitLen, out int number) {
number = 0;
// Create a context object so that we can parse the Hebrew number text character by character.
HebrewNumberParsingContext context = new HebrewNumberParsingContext(0);
// Set this to ContinueParsing so that we will run the following while loop in the first time.
HebrewNumberParsingState state = HebrewNumberParsingState.ContinueParsing;
while (state == HebrewNumberParsingState.ContinueParsing && str.GetNext()) {
state = HebrewNumber.ParseByChar(str.GetChar(), ref context);
}
if (state == HebrewNumberParsingState.FoundEndOfHebrewNumber) {
// If we have reached a terminal state, update the result and returns.
number = context.result;
return (true);
}
// If we run out of the character before reaching FoundEndOfHebrewNumber, or
// the state is InvalidHebrewNumber or ContinueParsing, we fail to match a Hebrew number.
// Return an error.
return false;
}
示例5: ParseSign
/*=================================ParseSign==================================
**Action: Parse a positive or a negative sign.
**Returns: true if postive sign. flase if negative sign.
**Arguments: str: a __DTString. The parsing will start from the
** next character after str.Index.
**Exceptions: FormatException if end of string is encountered or a sign
** symbol is not found.
==============================================================================*/
private static bool ParseSign(ref __DTString str, ref bool result) {
if (!str.GetNext()) {
// A sign symbol ('+' or '-') is expected. However, end of string is encountered.
return false;
}
char ch = str.GetChar();
if (ch == '+') {
result = true;
return (true);
} else if (ch == '-') {
result = false;
return (true);
}
// A sign symbol ('+' or '-') is expected.
return false;
}
示例6: MatchAbbreviatedTimeMark
private static bool MatchAbbreviatedTimeMark(ref __DTString str, DateTimeFormatInfo dtfi, ref DateTimeParse.TM result)
{
if (str.GetNext())
{
if (str.GetChar() == dtfi.AMDesignator[0])
{
result = DateTimeParse.TM.AM;
return true;
}
if (str.GetChar() == dtfi.PMDesignator[0])
{
result = DateTimeParse.TM.PM;
return true;
}
}
return false;
}
示例7: ParseSign
/*=================================ParseSign==================================
**Action: Parse a positive or a negative sign.
**Returns: true if postive sign. flase if negative sign.
**Arguments: str: a __DTString. The parsing will start from the
** next character after str.Index.
**Exceptions: FormatException if end of string is encountered or a sign
** symbol is not found.
==============================================================================*/
private static bool ParseSign(__DTString str, bool isThrowExp, ref bool result) {
if (!str.GetNext()) {
// A sign symbol ('+' or '-') is expected. However, end of string is encountered.
return (ParseFormatError(isThrowExp, "Format_BadDateTime"));
}
char ch = str.GetChar();
if (ch == '+') {
result = true;
return (true);
} else if (ch == '-') {
result = false;
return (true);
}
// A sign symbol ('+' or '-') is expected.
return (ParseFormatError(isThrowExp, "Format_BadDateTime"));
}
示例8: ParseByFormat
private static bool ParseByFormat(ref __DTString str, ref __DTString format, ref ParsingInfo parseInfo, DateTimeFormatInfo dtfi, ref DateTimeResult result)
{
bool flag;
int returnValue = 0;
int num2 = 0;
int num3 = 0;
int num4 = 0;
int num5 = 0;
int num6 = 0;
int num7 = 0;
int num8 = 0;
double num9 = 0.0;
TM aM = TM.AM;
char failureMessageFormatArgument = format.GetChar();
switch (failureMessageFormatArgument)
{
case '%':
if ((format.Index < (format.Value.Length - 1)) && (format.Value[format.Index + 1] != '%'))
{
goto Label_0A5A;
}
result.SetFailure(ParseFailureKind.Format, "Format_BadFormatSpecifier", null);
return false;
case '\'':
case '"':
{
StringBuilder builder = new StringBuilder();
if (!TryParseQuoteString(format.Value, format.Index, builder, out returnValue))
{
result.SetFailure(ParseFailureKind.FormatWithParameter, "Format_BadQuote", failureMessageFormatArgument);
return false;
}
format.Index += returnValue - 1;
string str2 = builder.ToString();
for (int i = 0; i < str2.Length; i++)
{
if ((str2[i] == ' ') && parseInfo.fAllowInnerWhite)
{
str.SkipWhiteSpaces();
}
else if (!str.Match(str2[i]))
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
}
if ((result.flags & ParseFlags.CaptureOffset) != 0)
{
if (((result.flags & ParseFlags.Rfc1123Pattern) != 0) && (str2 == "GMT"))
{
result.flags |= ParseFlags.TimeZoneUsed;
result.timeZoneOffset = TimeSpan.Zero;
}
else if (((result.flags & ParseFlags.UtcSortPattern) != 0) && (str2 == "Z"))
{
result.flags |= ParseFlags.TimeZoneUsed;
result.timeZoneOffset = TimeSpan.Zero;
}
}
goto Label_0A5A;
}
case '.':
if (!str.Match(failureMessageFormatArgument))
{
if (!format.GetNext() || !format.Match('F'))
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
format.GetRepeatCount();
}
goto Label_0A5A;
case '/':
if (str.Match(dtfi.DateSeparator))
{
goto Label_0A5A;
}
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
case ':':
if (str.Match(dtfi.TimeSeparator))
{
goto Label_0A5A;
}
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
case 'F':
case 'f':
returnValue = format.GetRepeatCount();
if (returnValue <= 7)
{
if (!ParseFractionExact(ref str, returnValue, ref num9) && (failureMessageFormatArgument == 'f'))
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
//.........这里部分代码省略.........
示例9: ParseISO8601
private static bool ParseISO8601(ref DateTimeRawInfo raw, ref __DTString str, DateTimeStyles styles, ref DateTimeResult result)
{
int num;
int num2;
DateTime time;
if ((raw.year >= 0) && (raw.GetNumber(0) >= 0))
{
raw.GetNumber(1);
}
str.Index--;
int num3 = 0;
double num4 = 0.0;
str.SkipWhiteSpaces();
if (!ParseDigits(ref str, 2, out num))
{
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();
if (!ParseDigits(ref str, 2, out num2))
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
str.SkipWhiteSpaces();
if (str.Match(':'))
{
str.SkipWhiteSpaces();
if (!ParseDigits(ref str, 2, out num3))
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
if (str.Match('.'))
{
if (!ParseFraction(ref str, out num4))
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
str.Index--;
}
str.SkipWhiteSpaces();
}
if (str.GetNext())
{
switch (str.GetChar())
{
case '+':
case '-':
result.flags |= ParseFlags.TimeZoneUsed;
if (!ParseTimeZone(ref str, ref result.timeZoneOffset))
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
break;
case 'Z':
case 'z':
result.flags |= ParseFlags.TimeZoneUsed;
result.timeZoneOffset = TimeSpan.Zero;
result.flags |= ParseFlags.TimeZoneUtc;
break;
default:
str.Index--;
break;
}
str.SkipWhiteSpaces();
if (str.Match('#'))
{
if (!VerifyValidPunctuation(ref str))
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
str.SkipWhiteSpaces();
}
if (str.Match('\0') && !VerifyValidPunctuation(ref str))
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
if (str.GetNext())
{
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
}
if (!GregorianCalendar.GetDefaultInstance().TryToDateTime(raw.year, raw.GetNumber(0), raw.GetNumber(1), num, num2, num3, 0, result.era, out time))
{
result.SetFailure(ParseFailureKind.FormatBadDateTimeCalendar, "Format_BadDateTimeCalendar", null);
return false;
//.........这里部分代码省略.........
示例10: 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 TimeSpan ParseTimeZone(__DTString str, char offsetChar) {
// The hour/minute offset for timezone.
int hourOffset = 0;
int minuteOffset = 0;
if (str.GetNextDigit()) {
// Get the first digit, Try if we can parse timezone in the form of "+8".
hourOffset = str.GetDigit();
if (str.GetNextDigit()) {
// Parsing "+18"
hourOffset *= 10;
hourOffset += str.GetDigit();
if (str.GetNext()) {
char ch;
if (Char.IsDigit(ch = str.GetChar())) {
// Parsing "+1800"
// Put the char back, since we already get the char in the previous GetNext() call.
str.Index--;
if (ParseDigits(str, 2, true, out minuteOffset)) {
// ParseDigits() does not advance the char for us, so do it here.
str.Index++;
} else {
throw new FormatException(Environment.GetResourceString("Format_BadDateTime"));
}
} else if (ch == ':') {
// Parsing "+18:00"
if (ParseDigits(str, 2, true, out minuteOffset)) {
str.Index++;
} else {
throw new FormatException(Environment.GetResourceString("Format_BadDateTime"));
}
} else {
// Not a digit, not a colon, put this char back.
str.Index--;
}
}
}
// The next char is not a digit, so we get the timezone in the form of "+8".
} else {
// Invalid timezone: No numbers after +/-.
throw new FormatException(Environment.GetResourceString("Format_BadDateTime"));
}
TimeSpan timezoneOffset = new TimeSpan(hourOffset, minuteOffset, 0);
if (offsetChar == '-') {
timezoneOffset = timezoneOffset.Negate();
}
return (timezoneOffset);
}
示例11: Lex
//
// This is the lexer. Check the character at the current index, and put the found token in dtok and
// some raw date/time information in raw.
//
private static void Lex(
int dps, __DTString str, DateTimeToken dtok, DateTimeRawInfo raw, DateTimeResult result, ref DateTimeFormatInfo dtfi) {
int sep;
dtok.dtt = DTT_Unk; // Assume the token is unkown.
//
// Skip any white spaces.
//
if (!str.SkipWhiteSpaceComma()) {
//
// SkipWhiteSpaceComma() will return true when end of string is reached.
//
dtok.dtt = DTT_End;
return;
}
char ch = str.GetChar();
if (Char.IsLetter(ch))
{
//
// This is a letter.
//
int month, dayOfWeek, era, timeMark;
//
// Check if this is a beginning of a month name.
// And check if this is a day of week name.
//
if (raw.month == -1 && (month = GetMonthNumber(str, dtfi)) >= 1)
{
//
// This is a month name
//
switch(sep=GetSeparator(str, raw, dtfi))
{
case SEP_End:
dtok.dtt = DTT_MonthEnd;
break;
case SEP_Space:
dtok.dtt = DTT_MonthSpace;
break;
case SEP_Date:
dtok.dtt = DTT_MonthDatesep;
break;
default:
//Invalid separator after month name
throw new FormatException(Environment.GetResourceString("Format_BadDateTime"));
}
raw.month = month;
}
else if (raw.dayOfWeek == -1 && (dayOfWeek = GetDayOfWeekNumber(str, dtfi)) >= 0)
{
//
// This is a day of week name.
//
raw.dayOfWeek = dayOfWeek;
dtok.dtt = DTT_DayOfWeek;
//
// Discard the separator.
//
GetSeparator(str, raw, dtfi);
}
else if (GetTimeZoneName(str))
{
//
// This is a timezone designator
//
// NOTENOTE : for now, we only support "GMT" and "Z" (for Zulu time).
//
dtok.dtt = DTT_TimeZone;
result.timeZoneUsed = true;
result.timeZoneOffset = new TimeSpan(0);
} else if ((raw.era == -1) && ((era = GetEra(str, result, ref dtfi)) != -1)) {
raw.era = era;
dtok.dtt = DTT_Era;
} else if (raw.timeMark == -1 && (timeMark = GetTimeMark(str, dtfi)) != -1) {
raw.timeMark = timeMark;
GetSeparator(str, raw, dtfi);
} else {
//
// Not a month name, not a day of week name. Check if this is one of the
// known date words. This is used to deal case like Spanish cultures, which
// uses 'de' in their Date string.
//
//
if (!str.MatchWords(dtfi.DateWords)) {
throw new FormatException(
String.Format(Environment.GetResourceString("Format_UnknowDateTimeWord"), str.Index));
}
GetSeparator(str, raw, dtfi);
}
} else if (Char.IsDigit(ch)) {
if (raw.numCount == 3) {
throw new FormatException(Environment.GetResourceString("Format_BadDateTime"));
//.........这里部分代码省略.........
示例12: GetSeparator
//
// Starting at str.Index, check the type of the separator.
//
private static int GetSeparator(__DTString str, DateTimeRawInfo raw, DateTimeFormatInfo dtfi) {
int separator = SEP_Space; // Assume the separator is a space. And try to find a better one.
//
// Check if we found any white spaces.
//
if (!str.SkipWhiteSpaceComma()) {
//
// SkipWhiteSpaceComma() will return true when end of string is reached.
//
//
// Return the separator as SEP_End.
//
return (SEP_End);
}
if (Char.IsLetter(str.GetChar())) {
//
// This is a beginning of a word.
//
if (raw.timeMark == -1)
{
//
// Check if this is an AM time mark.
//
int timeMark;
if ((timeMark = GetTimeMark(str, dtfi)) != -1)
{
raw.timeMark = timeMark;;
return (timeMark == TM_AM ? SEP_Am: SEP_Pm);
}
}
if (MatchWord(str, LocalTimeMark, false)) {
separator = SEP_LocalTimeMark;
} else if (MatchWord(str, CJKYearSuff, false) || MatchWord(str, KoreanYearSuff, false)) {
separator = SEP_YearSuff;
}
else if (MatchWord(str, CJKMonthSuff, false) || MatchWord(str, KoreanMonthSuff, false))
{
separator = SEP_MonthSuff;
}
else if (MatchWord(str, CJKDaySuff, false) || MatchWord(str, KoreanDaySuff, false))
{
separator = SEP_DaySuff;
}
else if (MatchWord(str, CJKHourSuff, false) || MatchWord(str, ChineseHourSuff, false))
{
separator = SEP_HourSuff;
}
else if (MatchWord(str, CJKMinuteSuff, false))
{
separator = SEP_MinuteSuff;
}
else if (MatchWord(str, CJKSecondSuff, false))
{
separator = SEP_SecondSuff;
}
} else {
//
// Not a letter. Check if this is a date separator.
//
if ((MatchWord(str, dtfi.DateSeparator, false)) ||
(MatchWord(str, invariantInfo.DateSeparator, false)) ||
(MatchWord(str, alternativeDateSeparator, false)))
{
//
// NOTENOTE : alternativeDateSeparator is a special case because some cultures
// (e.g. the invariant culture) use "/". However, in RFC format, we use "-" as the
// date separator. Therefore, we should check for it.
//
separator = SEP_Date;
}
//
// Check if this is a time separator.
//
else if ((MatchWord(str, dtfi.TimeSeparator, false)) ||
(MatchWord(str, invariantInfo.TimeSeparator, false)))
{
separator = SEP_Time;
} else if (dtfi.CultureID == 0x041c) {
// Special case for sq-AL (0x041c)
// Its time pattern is "h:mm:ss.tt"
if (str.GetChar() == '.') {
if (raw.timeMark == -1)
{
//
// Check if this is an AM time mark.
//
int timeMark;
str.Index++;
if ((timeMark = GetTimeMark(str, dtfi)) != -1)
{
raw.timeMark = timeMark;;
return (timeMark == TM_AM ? SEP_Am: SEP_Pm);
}
str.Index--;
//.........这里部分代码省略.........
示例13: ParseByFormat
// Given a specified format character, parse and update the parsing result.
//
private static bool ParseByFormat(
__DTString str,
__DTString format,
ParsingInfo parseInfo,
DateTimeFormatInfo dtfi,
bool isThrowExp,
DateTimeResult result) {
int tokenLen = 0;
int tempYear = 0, tempMonth = 0, tempDay = 0, tempDayOfWeek = 0, tempHour = 0, tempMinute = 0, tempSecond = 0;
double tempFraction = 0;
int tempTimeMark = 0;
char ch = format.GetChar();
switch (ch) {
case 'y':
tokenLen = format.GetRepeatCount();
if (tokenLen <= 2) {
parseInfo.fUseTwoDigitYear = true;
}
if (!ParseDigits(str, tokenLen, isThrowExp, out tempYear)) {
return (false);
}
if (!CheckNewValue(ref result.Year, tempYear, ch, isThrowExp)) {
return (false);
}
break;
case 'M':
tokenLen = format.GetRepeatCount();
if (tokenLen <= 2) {
if (!ParseDigits(str, tokenLen, isThrowExp, out tempMonth)) {
return (false);
}
} else {
if (tokenLen == 3) {
if (!MatchAbbreviatedMonthName(str, dtfi, isThrowExp, ref tempMonth)) {
return (false);
}
} else {
if (!MatchMonthName(str, dtfi, isThrowExp, ref tempMonth)) {
return (false);
}
}
}
if (!CheckNewValue(ref result.Month, tempMonth, ch, isThrowExp)) {
return (false);
}
break;
case 'd':
// Day & Day of week
tokenLen = format.GetRepeatCount();
if (tokenLen <= 2) {
// "d" & "dd"
if (!ParseDigits(str, tokenLen, isThrowExp, out tempDay)) {
return (false);
}
if (!CheckNewValue(ref result.Day, tempDay, ch, isThrowExp)) {
return (false);
}
} else {
if (tokenLen == 3) {
// "ddd"
if (!MatchAbbreviatedDayName(str, dtfi, isThrowExp, ref tempDayOfWeek)) {
return (false);
}
} else {
// "dddd*"
if (!MatchDayName(str, dtfi, isThrowExp, ref tempDayOfWeek)) {
return (false);
}
}
if (!CheckNewValue(ref parseInfo.dayOfWeek, tempDayOfWeek, ch, isThrowExp)) {
return (false);
}
}
break;
case 'g':
tokenLen = format.GetRepeatCount();
// Put the era value in result.era.
if (!MatchEraName(str, dtfi, isThrowExp, ref result.era)) {
return (false);
}
break;
case 'h':
parseInfo.fUseHour12 = true;
tokenLen = format.GetRepeatCount();
if (!ParseDigits(str, (tokenLen < 2? 1 : 2), isThrowExp, out tempHour)) {
return (false);
}
if (!CheckNewValue(ref result.Hour, tempHour, ch, isThrowExp)) {
return (false);
}
break;
case 'H':
tokenLen = format.GetRepeatCount();
if (!ParseDigits(str, (tokenLen < 2? 1 : 2), isThrowExp, out tempHour)) {
return (false);
//.........这里部分代码省略.........
示例14: MatchAbbreviatedTimeMark
/*=================================MatchAbbreviatedTimeMark==================================
**Action: Parse the abbreviated time mark (AM/PM) from string starting at str.Index.
**Returns: TM_AM or TM_PM.
**Arguments: str: a __DTString. The parsing will start from the
** next character after str.Index.
**Exceptions: FormatException if a abbreviated time mark can not be found.
==============================================================================*/
private static bool MatchAbbreviatedTimeMark(__DTString str, DateTimeFormatInfo dtfi, bool isThrowExp, ref int result) {
// NOTENOTE : the assumption here is that abbreviated time mark is the first
// character of the AM/PM designator. If this invariant changes, we have to
// change the code below.
if (str.GetNext())
{
if (str.GetChar() == dtfi.AMDesignator[0]) {
result = TM_AM;
return (true);
}
if (str.GetChar() == dtfi.PMDesignator[0]) {
result = TM_PM;
return (true);
}
}
return (ParseFormatError(isThrowExp, "Format_BadDateTime"));
}
示例15: MatchHebrewDigits
internal static bool MatchHebrewDigits(ref __DTString str, int digitLen, out int number)
{
number = 0;
HebrewNumberParsingContext hebrewNumberParsingContext = new HebrewNumberParsingContext(0);
HebrewNumberParsingState hebrewNumberParsingState = HebrewNumberParsingState.ContinueParsing;
while (hebrewNumberParsingState == HebrewNumberParsingState.ContinueParsing && str.GetNext())
{
hebrewNumberParsingState = HebrewNumber.ParseByChar(str.GetChar(), ref hebrewNumberParsingContext);
}
if (hebrewNumberParsingState == HebrewNumberParsingState.FoundEndOfHebrewNumber)
{
number = hebrewNumberParsingContext.result;
return true;
}
return false;
}