本文整理汇总了C#中System.Globalization.CompareInfo.Compare方法的典型用法代码示例。如果您正苦于以下问题:C# CompareInfo.Compare方法的具体用法?C# CompareInfo.Compare怎么用?C# CompareInfo.Compare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Globalization.CompareInfo
的用法示例。
在下文中一共展示了CompareInfo.Compare方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AssertCompare
void AssertCompare (string message, int result, string s1, string s2,
CompareOptions opt, CompareInfo ci)
{
int ret = ci.Compare (s1, s2, opt);
if (result == 0)
AssertEquals (message, 0, ret);
else if (result < 0)
Assert.IsTrue (message + String.Format ("(neg: {0})", ret), ret < 0);
else
Assert.IsTrue (message + String.Format ("(pos: {0})", ret), ret > 0);
}
示例2: MatchCaseInsensitive
/// <summary>
/// Attempts to match the specified string with the current point in the string in a case-insensitive
/// manner, according to the given comparison info.
/// </summary>
internal bool MatchCaseInsensitive(string match, CompareInfo compareInfo)
{
unchecked
{
if (match.Length > Value.Length - Index)
{
return false;
}
// FIXME: This will fail if the length in the input string is different to the length in the
// match string for culture-specific reasons. It's not clear how to handle that...
if (compareInfo.Compare(Value, Index, match.Length, match, 0, match.Length, CompareOptions.IgnoreCase) == 0)
{
Move(Index + match.Length);
return true;
}
return false;
}
}
示例3: AssertCompare
void AssertCompare (string message, int result,
string s1, int idx1, int len1, string s2, int idx2, int len2,
CompareOptions opt, CompareInfo ci)
{
int ret = ci.Compare (s1, idx1, len1, s2, idx2, len2, opt);
if (result == 0)
Assert.AreEqual (0, ret, message);
else if (result < 0)
Assert.IsTrue (ret < 0, message);
else
Assert.IsTrue (ret > 0, message);
}
示例4: CompareChars
private static int CompareChars(string Left, int LeftLength, int LeftStart, ref int LeftEnd, LigatureInfo[] LeftLigatureInfo, string Right, int RightLength, int RightStart, ref int RightEnd, LigatureInfo[] RightLigatureInfo, CompareInfo Comparer, CompareOptions Options, bool MatchBothCharsOfExpandedCharInRight = false, bool UseUnexpandedCharForRight = false)
{
LeftEnd = LeftStart;
RightEnd = RightStart;
if (Options == CompareOptions.Ordinal)
{
return (Left[LeftStart] - Right[RightStart]);
}
if (UseUnexpandedCharForRight)
{
if ((RightLigatureInfo != null) && (RightLigatureInfo[RightEnd].Kind == CharKind.ExpandedChar1))
{
Right = Right.Substring(RightStart, RightEnd - RightStart);
Right = Right + Conversions.ToString(RightLigatureInfo[RightEnd].CharBeforeExpansion);
RightEnd++;
return CompareChars(Left.Substring(LeftStart, (LeftEnd - LeftStart) + 1), Right, Comparer, Options);
}
}
else if (MatchBothCharsOfExpandedCharInRight)
{
int num2 = RightEnd;
SkipToEndOfExpandedChar(RightLigatureInfo, RightLength, ref RightEnd);
if (num2 < RightEnd)
{
int num4 = 0;
if ((LeftEnd + 1) < LeftLength)
{
num4 = 1;
}
int num3 = CompareChars(Left.Substring(LeftStart, ((LeftEnd - LeftStart) + 1) + num4), Right.Substring(RightStart, (RightEnd - RightStart) + 1), Comparer, Options);
if (num3 == 0)
{
LeftEnd += num4;
}
return num3;
}
}
if ((LeftEnd == LeftStart) && (RightEnd == RightStart))
{
return Comparer.Compare(Conversions.ToString(Left[LeftStart]), Conversions.ToString(Right[RightStart]), Options);
}
return CompareChars(Left.Substring(LeftStart, (LeftEnd - LeftStart) + 1), Right.Substring(RightStart, (RightEnd - RightStart) + 1), Comparer, Options);
}
示例5: CanCharExpand
private static int CanCharExpand(char ch, byte[] LocaleSpecificLigatureTable, CompareInfo Comparer, CompareOptions Options)
{
int num;
byte index = LigatureIndex(ch);
if (index == 0)
{
return 0;
}
if (LocaleSpecificLigatureTable[index] == 0)
{
if (Comparer.Compare(Conversions.ToString(ch), LigatureExpansions[index]) == 0)
{
LocaleSpecificLigatureTable[index] = 1;
}
else
{
LocaleSpecificLigatureTable[index] = 2;
}
}
if (LocaleSpecificLigatureTable[index] == 1)
{
return index;
}
return num;
}
示例6: IsAlefHamzaMatch
// Returns true iff two matching strings continue to match when kashida are considered.
private static bool IsAlefHamzaMatch(string text, string pattern, CompareInfo compareInfo)
{
const CompareOptions options = CompareOptions.IgnoreSymbols | CompareOptions.StringSort | CompareOptions.IgnoreNonSpace;
// Relace the AlefHamza chars with non-symbolic, non-diacritic constant values.
// AlefHamza variations are ignored with the CompareOptions we use during the search.
// When called, it's ok if the constant value matches other chars in the find pattern.
// We've already got a match ignoring AlefHamza.
text = text.Replace(UnicodeArabicAlefMaddaAbove, '0');
text = text.Replace(UnicodeArabicAlefHamzaAbove, '1');
text = text.Replace(UnicodeArabicAlefHamzaBelow, '2');
pattern = pattern.Replace(UnicodeArabicAlefMaddaAbove, '0');
pattern = pattern.Replace(UnicodeArabicAlefHamzaAbove, '1');
pattern = pattern.Replace(UnicodeArabicAlefHamzaBelow, '2');
return compareInfo.Compare(text, pattern, options) == 0;
}
示例7: IsKashidaMatch
// Returns true iff two matching strings continue to match when kashida are considered.
private static bool IsKashidaMatch(string text, string pattern, CompareInfo compareInfo)
{
const CompareOptions options = CompareOptions.IgnoreSymbols | CompareOptions.StringSort | CompareOptions.IgnoreNonSpace;
// Relace the Kashida char with a non-symbolic, non-diacritic constant value.
// Kashida is ignored with the CompareOptions we use during the search.
// When called, it's ok if the constant value matches other chars in the find pattern.
// We've already got a match ignoring kashida.
text = text.Replace(UnicodeArabicKashida, '0');
pattern = pattern.Replace(UnicodeArabicKashida, '0');
return compareInfo.Compare(text, pattern, options) == 0;
}
示例8: BidiIgnoreDiacriticsMatchIndexCalculation
// Returns the index and length of the first or last occurance of one string
// within another string.
//
// Performs a brute force n^2 pattern match search, necessary when FindFlags.MatchDiacritics == false
// on bidi content. (Because textString is not unbounded with document size, performance is not
// completely broken.)
//
// In Vista and later OSs, the native FindNLSString API classifies arabic diacriticals
// as non-spacing characters and provides IndexOf/LastIndexOf functionality.
private static int BidiIgnoreDiacriticsMatchIndexCalculation(string textString, string findPattern, bool matchKashida, bool matchAlefHamza, bool matchWholeWord, bool matchLast, bool ignoreCase, CompareInfo compareInfo, bool hasPreceedingSeparatorChar, bool hasFollowingSeparatorChar, out int matchLength)
{
// NB: See bug 1629855. There is a bug in the xp nls tables where CompareOptions.IgnoreNonSpace will
// not ignore all arabic diacriticals. We don't have a fix for this problem on xp. On Vista
// we work around by using FindNLSString.
int matchIndex = -1;
int startIndex = matchLast ? textString.Length - 1 : 0;
int endIndex = matchLast ? -1 : textString.Length;
int delta = matchLast ? -1 : +1;
if (System.Environment.OSVersion.Version.Major >= 6)
{
const uint NORM_IGNORECASE = 0x00000001; // ignore case
const uint NORM_IGNORENONSPACE = 0x00000002; // ignore nonspacing chars
const uint FIND_FROMEND = 0x00800000; // look for value in source, starting at the end
// In Vista, the flag meaning is "IGNORE NONSPACE == IGNORE MADDA == IGNOREHAMZA"
// The flag NORM_IGNORENONSPACE will ignore Bidi diacratics, Hamza and Madda.
// Kashida is always ignored no matter what flag is set.
uint findNLSStringFlags = NORM_IGNORENONSPACE;
if (ignoreCase)
{
findNLSStringFlags |= NORM_IGNORECASE;
}
if (matchLast)
{
findNLSStringFlags |= FIND_FROMEND;
}
if (matchKashida)
{
// Replace kashida for MatchKashida
textString = textString.Replace(UnicodeArabicKashida, '0');
findPattern = findPattern.Replace(UnicodeArabicKashida, '0');
}
if (matchAlefHamza)
{
// Replace Hamza and Madda for MatchAlefHamza
textString = textString.Replace(UnicodeArabicAlefMaddaAbove, '0');
textString = textString.Replace(UnicodeArabicAlefHamzaAbove, '1');
textString = textString.Replace(UnicodeArabicAlefHamzaBelow, '2');
findPattern = findPattern.Replace(UnicodeArabicAlefMaddaAbove, '0');
findPattern = findPattern.Replace(UnicodeArabicAlefHamzaAbove, '1');
findPattern = findPattern.Replace(UnicodeArabicAlefHamzaBelow, '2');
}
matchLength = 0;
// Find the match index from FindNLSString API which is only in Vista
if (matchWholeWord)
{
for (int i = startIndex; matchIndex == -1 && i != endIndex; i += delta)
{
for (int j = i; j < textString.Length; j++)
{
string subString = textString.Substring(i, j - i + 1);
int subStringIndex = FindNLSString(compareInfo.LCID, findNLSStringFlags,
subString, findPattern, out matchLength);
if (subStringIndex >= 0 &&
IsAtWordBoundary(textString, i + subStringIndex, matchLength, hasPreceedingSeparatorChar, hasFollowingSeparatorChar))
{
matchIndex = i + subStringIndex;
break;
}
}
}
}
else
{
matchIndex = FindNLSString(compareInfo.LCID, findNLSStringFlags,
textString, findPattern, out matchLength);
}
}
else
{
CompareOptions options = CompareOptions.IgnoreNonSpace | (ignoreCase ? CompareOptions.IgnoreCase : 0);
matchLength = 0;
for (int i = startIndex; matchIndex == -1 && i != endIndex; i += delta)
{
for (int j = i; j < textString.Length; j++)
{
//.........这里部分代码省略.........
示例9: LikeStringCompare
private static bool LikeStringCompare(CompareInfo ci, bool SeenNot, bool Match, char p, char s, CompareOptions Options)
{
if (SeenNot && Match)
{
if (Options == CompareOptions.Ordinal)
{
return (p != s);
}
return (ci.Compare(Conversions.ToString(p), Conversions.ToString(s), Options) != 0);
}
if (SeenNot || Match)
{
return Match;
}
if (Options == CompareOptions.Ordinal)
{
return (p == s);
}
return (ci.Compare(Conversions.ToString(p), Conversions.ToString(s), Options) == 0);
}