本文整理汇总了C#中System.__DTString.MatchSpecifiedWord方法的典型用法代码示例。如果您正苦于以下问题:C# __DTString.MatchSpecifiedWord方法的具体用法?C# __DTString.MatchSpecifiedWord怎么用?C# __DTString.MatchSpecifiedWord使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.__DTString
的用法示例。
在下文中一共展示了__DTString.MatchSpecifiedWord方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseByFormat
//.........这里部分代码省略.........
if ((result.flags & ParseFlags.CaptureOffset) != 0) {
if ((result.flags & ParseFlags.Rfc1123Pattern) != 0 && quotedStr == GMTName) {
result.flags |= ParseFlags.TimeZoneUsed;
result.timeZoneOffset = TimeSpan.Zero;
}
else if ((result.flags & ParseFlags.UtcSortPattern) != 0 && quotedStr == ZuluName) {
result.flags |= ParseFlags.TimeZoneUsed;
result.timeZoneOffset = TimeSpan.Zero;
}
}
break;
case '%':
// Skip this so we can get to the next pattern character.
// Used in case like "%d", "%y"
// Make sure the next character is not a '%' again.
if (format.Index >= format.Value.Length - 1 || format.Value[format.Index + 1] == '%') {
result.SetFailure(ParseFailureKind.Format, "Format_BadFormatSpecifier", null);
return false;
}
break;
case '\\':
// Escape character. For example, "\d".
// Get the next character in format, and see if we can
// find a match in str.
if (format.GetNext()) {
if (!str.Match(format.GetChar())) {
// Can not find a match for the escaped character.
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
} else {
result.SetFailure(ParseFailureKind.Format, "Format_BadFormatSpecifier", null);
return false;
}
break;
case '.':
if (!str.Match(ch)) {
if (format.GetNext()) {
// If we encounter the pattern ".F", and the dot is not present, it is an optional
// second fraction and we can skip this format.
if (format.Match('F')) {
format.GetRepeatCount();
break;
}
}
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
break;
default:
if (ch == ' ') {
if (parseInfo.fAllowInnerWhite) {
// Skip whitespaces if AllowInnerWhite.
// Do nothing here.
} else {
if (!str.Match(ch)) {
// If the space does not match, and trailing space is allowed, we do
// one more step to see if the next format character can lead to
// successful parsing.
// This is used to deal with special case that a empty string can match
// a specific pattern.
// The example here is af-ZA, which has a time format like "hh:mm:ss tt". However,
// its AM symbol is "" (empty string). If fAllowTrailingWhite is used, and time is in
// the AM, we will trim the whitespaces at the end, which will lead to a failure
// when we are trying to match the space before "tt".
if (parseInfo.fAllowTrailingWhite) {
if (format.GetNext()) {
if (ParseByFormat(ref str, ref format, ref parseInfo, dtfi, ref result)) {
return (true);
}
}
}
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
// Found a macth.
}
} else {
if (format.MatchSpecifiedWord(GMTName)) {
format.Index += (GMTName.Length - 1);
// Found GMT string in format. This means the DateTime string
// is in GMT timezone.
result.flags |= ParseFlags.TimeZoneUsed;
result.timeZoneOffset = TimeSpan.Zero;
if (!str.Match(GMTName)) {
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
} else if (!str.Match(ch)) {
// ch is expected.
result.SetFailure(ParseFailureKind.Format, "Format_BadDateTime", null);
return false;
}
}
break;
} // switch
return (true);
}
示例2: MatchMonthName
private static bool MatchMonthName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result)
{
int num = 0;
result = -1;
if (str.GetNext())
{
int num2 = (dtfi.GetMonthName(13).Length == 0) ? 12 : 13;
for (int i = 1; i <= num2; i++)
{
string monthName = dtfi.GetMonthName(i);
int length = monthName.Length;
if ((dtfi.HasSpacesInMonthNames ? str.MatchSpecifiedWords(monthName, false, ref length) : str.MatchSpecifiedWord(monthName)) && length > num)
{
num = length;
result = i;
}
}
if ((dtfi.FormatFlags & DateTimeFormatFlags.UseGenitiveMonth) != DateTimeFormatFlags.None)
{
int num3 = str.MatchLongestWords(dtfi.MonthGenitiveNames, ref num);
if (num3 >= 0)
{
result = num3 + 1;
}
}
if ((dtfi.FormatFlags & DateTimeFormatFlags.UseLeapYearMonth) != DateTimeFormatFlags.None)
{
int num4 = str.MatchLongestWords(dtfi.internalGetLeapYearMonthNames(), ref num);
if (num4 >= 0)
{
result = num4 + 1;
}
}
}
if (result > 0)
{
str.Index += num - 1;
return true;
}
return false;
}
示例3: MatchDayName
/*=================================MatchDayName==================================
**Action: Parse the day of week name from string starting at str.Index.
**Returns: A value from 0 to 6 indicating Sunday to Saturday.
**Arguments: str: a __DTString. The parsing will start from the
** next character after str.Index.
**Exceptions: FormatException if a day of week name can not be found.
==============================================================================*/
private static bool MatchDayName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result) {
// Turkish (tr-TR) got day names with the same prefix.
int maxMatchStrLen = 0;
result = -1;
if (str.GetNext()) {
for (DayOfWeek i = DayOfWeek.Sunday; i <= DayOfWeek.Saturday; i++) {
String searchStr = dtfi.GetDayName(i);
int matchStrLen = searchStr.Length;
if ( dtfi.HasSpacesInDayNames
? str.MatchSpecifiedWords(searchStr, false, ref matchStrLen)
: str.MatchSpecifiedWord(searchStr)) {
if (matchStrLen > maxMatchStrLen) {
maxMatchStrLen = matchStrLen;
result = (int)i;
}
}
}
}
if (result >= 0) {
str.Index += maxMatchStrLen - 1;
return (true);
}
return false;
}
示例4: MatchTimeMark
/*=================================MatchTimeMark==================================
**Action: Parse the 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 time mark can not be found.
==============================================================================*/
private static bool MatchTimeMark(ref __DTString str, DateTimeFormatInfo dtfi, ref TM result) {
result = TM.NotSet;
// In some cultures have empty strings in AM/PM mark. E.g. af-ZA (0x0436), the AM mark is "", and PM mark is "nm".
if (dtfi.AMDesignator.Length == 0) {
result = TM.AM;
}
if (dtfi.PMDesignator.Length == 0) {
result = TM.PM;
}
if (str.GetNext()) {
String searchStr = dtfi.AMDesignator;
if (searchStr.Length > 0) {
if (str.MatchSpecifiedWord(searchStr)) {
// Found an AM timemark with length > 0.
str.Index += (searchStr.Length - 1);
result = TM.AM;
return (true);
}
}
searchStr = dtfi.PMDesignator;
if (searchStr.Length > 0) {
if (str.MatchSpecifiedWord(searchStr)) {
// Found a PM timemark with length > 0.
str.Index += (searchStr.Length - 1);
result = TM.PM;
return (true);
}
}
str.Index--; // Undo the GetNext call.
}
if (result != TM.NotSet) {
// If one of the AM/PM marks is empty string, return the result.
return (true);
}
return false;
}
示例5: MatchAbbreviatedDayName
/*=================================MatchAbbreviatedDayName==================================
**Action: Parse the abbreviated day of week name from string starting at str.Index.
**Returns: A value from 0 to 6 indicating Sunday to Saturday.
**Arguments: str: a __DTString. The parsing will start from the
** next character after str.Index.
**Exceptions: FormatException if a abbreviated day of week name can not be found.
==============================================================================*/
private static bool MatchAbbreviatedDayName(__DTString str, DateTimeFormatInfo dtfi, bool isThrowExp, ref int result) {
if (str.GetNext()) {
for (DayOfWeek i = DayOfWeek.Sunday; i <= DayOfWeek.Saturday; i++) {
String searchStr = dtfi.GetAbbreviatedDayName(i);
if (str.MatchSpecifiedWord(searchStr)) {
str.Index += (searchStr.Length - 1);
result = (int)i;
return (true);
}
}
}
return (ParseFormatError(isThrowExp, "Format_BadDateTime"));
}
示例6: MatchMonthName
/*=================================MatchMonthName==================================
**Action: Parse the month name from string starting at str.Index.
**Returns: A value from 1 to 12 indicating the first month to the twelveth month.
**Arguments: str: a __DTString. The parsing will start from the
** next character after str.Index.
**Exceptions: FormatException if a month name can not be found.
==============================================================================*/
private static bool MatchMonthName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result) {
int maxMatchStrLen = 0;
result = -1;
if (str.GetNext()) {
//
// Scan the month names (note that some calendars has 13 months) and find
// the matching month name which has the max string length.
// We need to do this because some cultures (e.g. "vi-VN") which have
// month names with the same prefix.
//
int monthsInYear = (dtfi.GetMonthName(13).Length == 0 ? 12: 13);
for (int i = 1; i <= monthsInYear; i++) {
String searchStr = dtfi.GetMonthName(i);
int matchStrLen = searchStr.Length;
if ( dtfi.HasSpacesInMonthNames
? str.MatchSpecifiedWords(searchStr, false, ref matchStrLen)
: str.MatchSpecifiedWord(searchStr)) {
if (matchStrLen > maxMatchStrLen) {
maxMatchStrLen = matchStrLen;
result = i;
}
}
}
// Search genitive form.
if ((dtfi.FormatFlags & DateTimeFormatFlags.UseGenitiveMonth) != 0) {
int tempResult = str.MatchLongestWords(dtfi.MonthGenitiveNames, ref maxMatchStrLen);
// We found a longer match in the genitive month name. Use this as the result.
// The result from MatchLongestWords is 0 ~ length of word array.
// So we increment the result by one to become the month value.
if (tempResult >= 0) {
result = tempResult + 1;
}
}
// Search leap year form.
if ((dtfi.FormatFlags & DateTimeFormatFlags.UseLeapYearMonth) != 0) {
int tempResult = str.MatchLongestWords(dtfi.internalGetLeapYearMonthNames(), ref maxMatchStrLen);
// We found a longer match in the leap year month name. Use this as the result.
// The result from MatchLongestWords is 0 ~ length of word array.
// So we increment the result by one to become the month value.
if (tempResult >= 0) {
result = tempResult + 1;
}
}
}
if (result > 0) {
str.Index += (maxMatchStrLen - 1);
return (true);
}
return false;
}
示例7: MatchAbbreviatedMonthName
private static bool MatchAbbreviatedMonthName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result)
{
int maxMatchStrLen = 0;
result = -1;
if (str.GetNext())
{
int num2 = (dtfi.GetMonthName(13).Length == 0) ? 12 : 13;
for (int i = 1; i <= num2; i++)
{
string abbreviatedMonthName = dtfi.GetAbbreviatedMonthName(i);
int length = abbreviatedMonthName.Length;
if ((dtfi.HasSpacesInMonthNames ? str.MatchSpecifiedWords(abbreviatedMonthName, false, ref length) : str.MatchSpecifiedWord(abbreviatedMonthName)) && (length > maxMatchStrLen))
{
maxMatchStrLen = length;
result = i;
}
}
if ((dtfi.FormatFlags & DateTimeFormatFlags.UseLeapYearMonth) != DateTimeFormatFlags.None)
{
int num5 = str.MatchLongestWords(dtfi.internalGetLeapYearMonthNames(), ref maxMatchStrLen);
if (num5 >= 0)
{
result = num5 + 1;
}
}
}
if (result > 0)
{
str.Index += maxMatchStrLen - 1;
return true;
}
return false;
}
示例8: 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;
}
示例9: ParseByFormat
//.........这里部分代码省略.........
case '\'':
StringBuilder enquotedString = new StringBuilder();
try {
// Use ParseQuoteString so that we can handle escape characters within the quoted string.
tokenLen = DateTimeFormat.ParseQuoteString(format.Value, format.Index, enquotedString);
} catch (Exception) {
if (isThrowExp) {
throw new FormatException(String.Format(Environment.GetResourceString("Format_BadQuote"), ch));
} else {
return (false);
}
}
format.Index += tokenLen - 1;
// Some cultures uses space in the quoted string. E.g. Spanish has long date format as:
// "dddd, dd' de 'MMMM' de 'yyyy". When inner spaces flag is set, we should skip whitespaces if there is space
// in the quoted string.
String quotedStr = enquotedString.ToString();
for (int i = 0; i < quotedStr.Length; i++) {
if (quotedStr[i] == ' ' && parseInfo.fAllowInnerWhite) {
str.SkipWhiteSpaces();
} else if (!str.Match(quotedStr[i])) {
// Can not find the matching quoted string.
BCLDebug.Trace("NLS", "DateTimeParse.DoStrictParse():Quote string doesn't match");
return (ParseFormatError(isThrowExp, "Format_BadDateTime"));
}
}
break;
case '%':
// Skip this so we can get to the next pattern character.
// Used in case like "%d", "%y"
// Make sure the next character is not a '%' again.
if (format.Index >= format.Value.Length - 1 || format.Value[format.Index + 1] == '%') {
BCLDebug.Trace("NLS", "DateTimeParse.DoStrictParse():%% is not permitted");
return (ParseFormatError(isThrowExp, "Format_BadFormatSpecifier"));
}
break;
case '\\':
// Escape character. For example, "\d".
// Get the next character in format, and see if we can
// find a match in str.
if (format.GetNext()) {
if (!str.Match(format.GetChar())) {
// Can not find a match for the escaped character.
BCLDebug.Trace("NLS", "DateTimeParse.DoStrictParse(): Can not find a match for the escaped character");
return (ParseFormatError(isThrowExp, "Format_BadDateTime"));
}
} else {
BCLDebug.Trace("NLS", "DateTimeParse.DoStrictParse(): \\ is at the end of the format string");
return (ParseFormatError(isThrowExp, "Format_BadFormatSpecifier"));
}
break;
default:
if (ch == ' ') {
if (parseInfo.fAllowInnerWhite) {
// Skip whitespaces if AllowInnerWhite.
// Do nothing here.
} else {
if (!str.Match(ch)) {
// If the space does not match, and trailing space is allowed, we do
// one more step to see if the next format character can lead to
// successful parsing.
// This is used to deal with special case that a empty string can match
// a specific pattern.
// The example here is af-ZA, which has a time format like "hh:mm:ss tt". However,
// its AM symbol is "" (empty string). If fAllowTrailingWhite is used, and time is in
// the AM, we will trim the whitespaces at the end, which will lead to a failure
// when we are trying to match the space before "tt".
if (parseInfo.fAllowTrailingWhite) {
if (format.GetNext()) {
if (ParseByFormat(str, format, parseInfo, dtfi, isThrowExp, result)) {
return (true);
}
}
}
return (ParseFormatError(isThrowExp, "Format_BadDateTime"));
}
// Found a macth.
}
} else {
if (format.MatchSpecifiedWord(GMTName)) {
format.Index += (GMTName.Length - 1);
// Found GMT string in format. This means the DateTime string
// is in GMT timezone.
parseInfo.fUseTimeZone = true;
if (!str.Match(GMTName)) {
BCLDebug.Trace("NLS", "DateTimeParse.DoStrictParse(): GMT in format, but not in str");
return (ParseFormatError(isThrowExp, "Format_BadDateTime"));
}
} else if (!str.Match(ch)) {
// ch is expected.
BCLDebug.Trace ("NLS", "DateTimeParse.DoStrictParse(): '", ch, "' is expected");
return (ParseFormatError(isThrowExp, "Format_BadDateTime"));
}
}
break;
} // switch
return (true);
}
示例10: GetDayOfWeekNumber
//
// Check the word at the current index to see if it matches a day of week name.
// Return -1 if a match is not found. Otherwise, a value from 0 to 6 is returned.
//
private static int GetDayOfWeekNumber(__DTString str, DateTimeFormatInfo dtfi) {
//
// Check the month name specified in dtfi.
//
DayOfWeek i;
int maxLen = 0;
int result = -1;
//
// We have to match the day name with the longest length,
// since there are cultures which have more than one day of week names
// with the same prefix.
//
int endIndex = str.FindEndOfCurrentWord();
String dayName=null;
for (i = DayOfWeek.Sunday; i <= DayOfWeek.Saturday; i++) {
dayName = dtfi.GetDayName(i);
if (str.MatchSpecifiedWord(dayName, endIndex)) {
if (dayName.Length > maxLen) {
result = (int)i;
maxLen = dayName.Length;
}
}
}
if (result > -1) {
str.Index = endIndex;
return (result);
}
for (i = DayOfWeek.Sunday; i <= DayOfWeek.Saturday; i++)
{
if (MatchWord(str, dtfi.GetAbbreviatedDayName(i), false))
{
return ((int)i);
}
}
//
// Check the month name in the invariant culture.
//
for (i = DayOfWeek.Sunday; i <= DayOfWeek.Saturday; i++)
{
if (MatchWord(str, invariantInfo.GetDayName(i), false))
{
return ((int)i);
}
}
for (i = DayOfWeek.Sunday; i <= DayOfWeek.Saturday; i++)
{
if (MatchWord(str, invariantInfo.GetAbbreviatedDayName(i), false))
{
return ((int)i);
}
}
return (-1);
}
示例11: MatchTimeMark
/*=================================MatchTimeMark==================================
**Action: Parse the 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 time mark can not be found.
==============================================================================*/
private static bool MatchTimeMark(__DTString str, DateTimeFormatInfo dtfi, bool isThrowExp, ref int result) {
result = -1;
// In some cultures have empty strings in AM/PM mark. E.g. af-ZA (0x0436), the AM mark is "", and PM mark is "nm".
if (dtfi.AMDesignator.Length == 0) {
result = TM_AM;
}
if (dtfi.PMDesignator.Length == 0) {
result = TM_PM;
}
if (str.GetNext()) {
String searchStr = dtfi.AMDesignator;
if (searchStr.Length > 0) {
if (str.MatchSpecifiedWord(searchStr)) {
// Found an AM timemark with length > 0.
str.Index += (searchStr.Length - 1);
result = TM_AM;
return (true);
}
}
searchStr = dtfi.PMDesignator;
if (searchStr.Length > 0) {
if (str.MatchSpecifiedWord(searchStr)) {
// Found a PM timemark with length > 0.
str.Index += (searchStr.Length - 1);
result = TM_PM;
return (true);
}
}
// If we can not match the time mark strings with length > 0,
// just return the
return (true);
}
if (result != -1) {
// If one of the AM/PM marks is empty string, return the result.
return (true);
}
return (ParseFormatError(isThrowExp, "Format_BadDateTime"));
}
示例12: MatchEraName
/*=================================MatchEraName==================================
**Action: Parse era name from string starting at str.Index.
**Returns: An era value.
**Arguments: str: a __DTString. The parsing will start from the
** next character after str.Index.
**Exceptions: FormatException if an era name can not be found.
==============================================================================*/
private static bool MatchEraName(__DTString str, DateTimeFormatInfo dtfi, bool isThrowExp, ref int result) {
if (str.GetNext()) {
int[] eras = dtfi.Calendar.Eras;
if (eras != null) {
for (int i = 0; i <= eras.Length; i++) {
String searchStr = dtfi.GetEraName(eras[i]);
if (str.MatchSpecifiedWord(searchStr)) {
str.Index += (searchStr.Length - 1);
result = eras[i];
return (true);
}
searchStr = dtfi.GetAbbreviatedEraName(eras[i]);
if (str.MatchSpecifiedWord(searchStr)) {
str.Index += (searchStr.Length - 1);
result = eras[i];
return (true);
}
}
}
}
return (ParseFormatError(isThrowExp, "Format_BadDateTime"));
}
示例13: MatchDayName
/*=================================MatchDayName==================================
**Action: Parse the day of week name from string starting at str.Index.
**Returns: A value from 0 to 6 indicating Sunday to Saturday.
**Arguments: str: a __DTString. The parsing will start from the
** next character after str.Index.
**Exceptions: FormatException if a day of week name can not be found.
==============================================================================*/
private static bool MatchDayName(__DTString str, DateTimeFormatInfo dtfi, bool isThrowExp, ref int result) {
// Turkish (tr-TR) got day names with the same prefix.
int maxMatchStrLen = 0;
result = -1;
if (str.GetNext()) {
for (DayOfWeek i = DayOfWeek.Sunday; i <= DayOfWeek.Saturday; i++) {
String searchStr = dtfi.GetDayName(i);
if (str.MatchSpecifiedWord(searchStr)) {
int matchStrLen = (searchStr.Length - 1);
if (matchStrLen > maxMatchStrLen) {
maxMatchStrLen = matchStrLen;
result = (int)i;
}
}
}
}
if (result >= 0) {
str.Index += maxMatchStrLen;
return (true);
}
return (ParseFormatError(isThrowExp, "Format_BadDateTime"));
}
示例14: 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;
}
示例15: MatchTimeMark
private static bool MatchTimeMark(ref __DTString str, DateTimeFormatInfo dtfi, ref TM result)
{
result = TM.NotSet;
if (dtfi.AMDesignator.Length == 0)
{
result = TM.AM;
}
if (dtfi.PMDesignator.Length == 0)
{
result = TM.PM;
}
if (str.GetNext())
{
string aMDesignator = dtfi.AMDesignator;
if ((aMDesignator.Length > 0) && str.MatchSpecifiedWord(aMDesignator))
{
str.Index += aMDesignator.Length - 1;
result = TM.AM;
return true;
}
aMDesignator = dtfi.PMDesignator;
if ((aMDesignator.Length > 0) && str.MatchSpecifiedWord(aMDesignator))
{
str.Index += aMDesignator.Length - 1;
result = TM.PM;
return true;
}
str.Index--;
}
return (result != TM.NotSet);
}