本文整理汇总了C#中System.__DTString.MatchSpecifiedWords方法的典型用法代码示例。如果您正苦于以下问题:C# __DTString.MatchSpecifiedWords方法的具体用法?C# __DTString.MatchSpecifiedWords怎么用?C# __DTString.MatchSpecifiedWords使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.__DTString
的用法示例。
在下文中一共展示了__DTString.MatchSpecifiedWords方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Tokenize
[System.Security.SecurityCritical] // auto-generated
internal bool Tokenize(TokenType TokenMask, out TokenType tokenType, out int tokenValue, ref __DTString str) {
tokenType = TokenType.UnknownToken;
tokenValue = 0;
TokenHashValue value;
Contract.Assert(str.Index < str.Value.Length, "DateTimeFormatInfo.Tokenize(): start < value.Length");
char ch = str.m_current;
bool isLetter = Char.IsLetter(ch);
if (isLetter) {
ch = Char.ToLower(ch, this.Culture);
if (IsHebrewChar(ch) && TokenMask == TokenType.RegularTokenMask) {
bool badFormat;
if (TryParseHebrewNumber(ref str, out badFormat, out tokenValue)) {
if (badFormat) {
tokenType = TokenType.UnknownToken;
return (false);
}
// This is a Hebrew number.
// Do nothing here. TryParseHebrewNumber() will update token accordingly.
tokenType = TokenType.HebrewNumber;
return (true);
}
}
}
int hashcode = ch % TOKEN_HASH_SIZE;
int hashProbe = 1 + ch % SECOND_PRIME;
int remaining = str.len - str.Index;
int i = 0;
TokenHashValue[] hashTable = m_dtfiTokenHash;
if (hashTable == null) {
hashTable = CreateTokenHashTable();
}
do {
value = hashTable[hashcode];
if (value == null) {
// Not found.
break;
}
// Check this value has the right category (regular token or separator token) that we are looking for.
if (((int)value.tokenType & (int)TokenMask) > 0 && value.tokenString.Length <= remaining) {
if (String.Compare(str.Value, str.Index, value.tokenString, 0, value.tokenString.Length, this.Culture, CompareOptions.IgnoreCase)==0) {
if (isLetter) {
// If this token starts with a letter, make sure that we won't allow partial match. So you can't tokenize "MarchWed" separately.
int nextCharIndex;
if ((nextCharIndex = str.Index + value.tokenString.Length) < str.len) {
// Check word boundary. The next character should NOT be a letter.
char nextCh = str.Value[nextCharIndex];
if (Char.IsLetter(nextCh)) {
return (false);
}
}
}
tokenType = value.tokenType & TokenMask;
tokenValue = value.tokenValue;
str.Advance(value.tokenString.Length);
return (true);
} else if (value.tokenType == TokenType.MonthToken && HasSpacesInMonthNames) {
// For month token, we will match the month names which have spaces.
int matchStrLen = 0;
if (str.MatchSpecifiedWords(value.tokenString, true, ref matchStrLen)) {
tokenType = value.tokenType & TokenMask;
tokenValue = value.tokenValue;
str.Advance(matchStrLen);
return (true);
}
} else if (value.tokenType == TokenType.DayOfWeekToken && HasSpacesInDayNames) {
// For month token, we will match the month names which have spaces.
int matchStrLen = 0;
if (str.MatchSpecifiedWords(value.tokenString, true, ref matchStrLen)) {
tokenType = value.tokenType & TokenMask;
tokenValue = value.tokenValue;
str.Advance(matchStrLen);
return (true);
}
}
}
i++;
hashcode += hashProbe;
if (hashcode >= TOKEN_HASH_SIZE) hashcode -= TOKEN_HASH_SIZE;
}while (i < TOKEN_HASH_SIZE);
return (false);
}
示例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
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;
}
示例4: 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;
}
示例5: 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;
}
示例6: Tokenize
internal bool Tokenize(TokenType TokenMask, out TokenType tokenType, out int tokenValue, ref __DTString str)
{
tokenType = TokenType.UnknownToken;
tokenValue = 0;
char ch = str.m_current;
bool flag = char.IsLetter(ch);
if (flag)
{
ch = char.ToLower(ch, this.Culture);
bool badFormat;
if (DateTimeFormatInfo.IsHebrewChar(ch) && TokenMask == TokenType.RegularTokenMask && DateTimeFormatInfo.TryParseHebrewNumber(ref str, out badFormat, out tokenValue))
{
if (badFormat)
{
tokenType = TokenType.UnknownToken;
return false;
}
else
{
tokenType = TokenType.HebrewNumber;
return true;
}
}
}
int index1 = (int) ch % 199;
int num1 = 1 + (int) ch % 197;
int num2 = str.len - str.Index;
int num3 = 0;
TokenHashValue[] tokenHashValueArray = this.m_dtfiTokenHash ?? this.CreateTokenHashTable();
do
{
TokenHashValue tokenHashValue = tokenHashValueArray[index1];
if (tokenHashValue != null)
{
if ((tokenHashValue.tokenType & TokenMask) > (TokenType) 0 && tokenHashValue.tokenString.Length <= num2)
{
if (string.Compare(str.Value, str.Index, tokenHashValue.tokenString, 0, tokenHashValue.tokenString.Length, this.Culture, CompareOptions.IgnoreCase) == 0)
{
int index2;
if (flag && (index2 = str.Index + tokenHashValue.tokenString.Length) < str.len && char.IsLetter(str.Value[index2]))
return false;
tokenType = tokenHashValue.tokenType & TokenMask;
tokenValue = tokenHashValue.tokenValue;
str.Advance(tokenHashValue.tokenString.Length);
return true;
}
else if (tokenHashValue.tokenType == TokenType.MonthToken && this.HasSpacesInMonthNames)
{
int matchLength = 0;
if (str.MatchSpecifiedWords(tokenHashValue.tokenString, true, ref matchLength))
{
tokenType = tokenHashValue.tokenType & TokenMask;
tokenValue = tokenHashValue.tokenValue;
str.Advance(matchLength);
return true;
}
}
else if (tokenHashValue.tokenType == TokenType.DayOfWeekToken && this.HasSpacesInDayNames)
{
int matchLength = 0;
if (str.MatchSpecifiedWords(tokenHashValue.tokenString, true, ref matchLength))
{
tokenType = tokenHashValue.tokenType & TokenMask;
tokenValue = tokenHashValue.tokenValue;
str.Advance(matchLength);
return true;
}
}
}
++num3;
index1 += num1;
if (index1 >= 199)
index1 -= 199;
}
else
break;
}
while (num3 < 199);
return false;
}
示例7: Tokenize
internal bool Tokenize(TokenType TokenMask, out TokenType tokenType, out int tokenValue, ref __DTString str)
{
tokenType = TokenType.UnknownToken;
tokenValue = 0;
char current = str.m_current;
bool flag = char.IsLetter(current);
if (flag)
{
bool flag2;
current = char.ToLower(current, this.Culture);
if ((IsHebrewChar(current) && (TokenMask == TokenType.RegularTokenMask)) && TryParseHebrewNumber(ref str, out flag2, out tokenValue))
{
if (flag2)
{
tokenType = TokenType.UnknownToken;
return false;
}
tokenType = TokenType.HebrewNumber;
return true;
}
}
int index = current % '\x00c7';
int num2 = 1 + (current % '\x00c5');
int num3 = str.len - str.Index;
int num4 = 0;
TokenHashValue[] dtfiTokenHash = this.m_dtfiTokenHash;
if (dtfiTokenHash == null)
{
dtfiTokenHash = this.CreateTokenHashTable();
}
do
{
TokenHashValue value2 = dtfiTokenHash[index];
if (value2 == null)
{
break;
}
if (((value2.tokenType & TokenMask) > ((TokenType) 0)) && (value2.tokenString.Length <= num3))
{
if (string.Compare(str.Value, str.Index, value2.tokenString, 0, value2.tokenString.Length, this.Culture, CompareOptions.IgnoreCase) == 0)
{
int num5;
if (flag && ((num5 = str.Index + value2.tokenString.Length) < str.len))
{
char c = str.Value[num5];
if (char.IsLetter(c))
{
return false;
}
}
tokenType = value2.tokenType & TokenMask;
tokenValue = value2.tokenValue;
str.Advance(value2.tokenString.Length);
return true;
}
if ((value2.tokenType == TokenType.MonthToken) && this.HasSpacesInMonthNames)
{
int matchLength = 0;
if (str.MatchSpecifiedWords(value2.tokenString, true, ref matchLength))
{
tokenType = value2.tokenType & TokenMask;
tokenValue = value2.tokenValue;
str.Advance(matchLength);
return true;
}
}
else if ((value2.tokenType == TokenType.DayOfWeekToken) && this.HasSpacesInDayNames)
{
int num7 = 0;
if (str.MatchSpecifiedWords(value2.tokenString, true, ref num7))
{
tokenType = value2.tokenType & TokenMask;
tokenValue = value2.tokenValue;
str.Advance(num7);
return true;
}
}
}
num4++;
index += num2;
if (index >= 0xc7)
{
index -= 0xc7;
}
}
while (num4 < 0xc7);
return false;
}
示例8: 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;
}