Compare() public method

public Compare ( String string1, String string2 ) : int
string1 String
string2 String
return int
コード例 #1
0
ファイル: TreeNodeEx.cs プロジェクト: prepare/box2c
		internal int AddSorted(TreeNodeEx node)
		{
			int pos = 0;
			string text = node.Text;
			if (childCount > 0)
			{
				System.Globalization.CompareInfo compare = System.Windows.Forms.Application.CurrentCulture.CompareInfo;
				// Simple optimization if added in sort order
				if (compare.Compare(children[(childCount - 1)].Text, text) <= 0)
					pos = childCount;
				else
				{
					// Binary Search
					int i = 0;
					int j = childCount;
					while (i < j)
					{
						int mid = (i + j) / 2;
						if (compare.Compare(children[mid].Text, text) <= 0)
							i = mid + 1;
						else
							i = mid;
					}
					pos = i;
				}
			}

			node.SortChildren();
			InsertNodeAt(pos, node);
			if (treeView != null && node == treeView.SelectedNode)
			{
				treeView.SelectedNode = node;
			}
			return pos;
		}
コード例 #2
0
 /// <summary>
 /// Compara as instancias informadas.
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <returns></returns>
 public override int Compare(IMessageFormattable x, IMessageFormattable y)
 {
     if (object.ReferenceEquals(x, y))
     {
         return(0);
     }
     if (x == null)
     {
         return(-1);
     }
     if (y == null)
     {
         return(1);
     }
     return(_compareInfo.Compare(x.Format(_culture), y.Format(_culture), _ignoreCase ? System.Globalization.CompareOptions.IgnoreCase : System.Globalization.CompareOptions.None));
 }
コード例 #3
0
 public override int Compare(string x, string y)
 {
     if (Object.ReferenceEquals(x, y))
     {
         return(0);
     }
     if (x == null)
     {
         return(-1);
     }
     if (y == null)
     {
         return(1);
     }
     return(_compareInfo.Compare(x, 0, x.Length, y, 0, y.Length, _ignoreCase ? CompareOptions.IgnoreCase : CompareOptions.None));
 }
コード例 #4
0
 public override int Compare(string x, string y)
 {
     if (Object.ReferenceEquals(x, y))
     {
         return(0);
     }
     if (x == null)
     {
         return(-1);
     }
     if (y == null)
     {
         return(1);
     }
     return(_compareInfo.Compare(x, y, _options));
 }
コード例 #5
0
        private bool IsContentMatch(string ListItems, string Item)
        {
            int ListItemsLength = ListItems.Length;
            int ItemLength      = Item.Length;

            System.Globalization.CompareInfo ci = System.Globalization.CompareInfo.GetCompareInfo("ja-JP");

            if (ListItemsLength < ItemLength)
            {
                return(false);
            }
            else
            {
                string index = string.Empty;
                for (int i = 0; i <= ListItemsLength - ItemLength; i++)
                {
                    index = ListItems.Substring(i, ItemLength);
                    if (ci.Compare(index, Item, System.Globalization.CompareOptions.IgnoreWidth | System.Globalization.CompareOptions.IgnoreKanaType | System.Globalization.CompareOptions.IgnoreCase) == 0)
                    {
                        return(true);
                    }
                }
                return(false);
            }
        }
コード例 #6
0
ファイル: CompareInfoTest.jvm.cs プロジェクト: carrie901/mono
	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);
	}
コード例 #7
0
ファイル: ValueCursor.cs プロジェクト: manirana007/NodaTime
 /// <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;
     }
 }
コード例 #8
0
        /*
         * <summary>Customised Compare Class</summary>
         * <remarks>
         * <para>
         * The Virtual Payment Client need to use an Ordinal comparison to Sort on
         * the field names to create the MD5 Signature for validation of the message.
         * This class provides a Compare method that is used to allow the sorted list
         * to be ordered using an Ordinal comparison.
         * </para>
         * </remarks>
         */

        public int Compare(Object a, Object b)
        {
            /*
             * <summary>Compare method using Ordinal comparison</summary>
             * <param name="a">The first string in the comparison.</param>
             * <param name="b">The second string in the comparison.</param>
             * <returns>An int containing the result of the comparison.</returns>
             */

            // Return if we are comparing the same object or one of the
            // objects is null, since we don't need to go any further.
            if (a == b)
            {
                return(0);
            }
            if (a == null)
            {
                return(-1);
            }
            if (b == null)
            {
                return(1);
            }

            // Ensure we have string to compare
            string sa = a as string;
            string sb = b as string;

            // Get the CompareInfo object to use for comparing
            System.Globalization.CompareInfo myComparer = System.Globalization.CompareInfo.GetCompareInfo("en-US");
            if (sa != null && sb != null)
            {
                // Compare using an Ordinal Comparison.
                return(myComparer.Compare(sa, sb, System.Globalization.CompareOptions.Ordinal));
            }
            throw new ArgumentException("a and b should be strings.");
        }
コード例 #9
0
 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);
 }
コード例 #10
0
 private static int CompareChars(string Left, string Right, CompareInfo Comparer, CompareOptions Options)
 {
     if (Options == CompareOptions.Ordinal)
     {
         return (Left[0] - Right[0]);
     }
     return Comparer.Compare(Left, Right, Options);
 }
コード例 #11
0
 private static int CompareChars(char Left, char Right, CompareInfo Comparer, CompareOptions Options)
 {
     if (Options == CompareOptions.Ordinal)
     {
         return (Left - Right);
     }
     return Comparer.Compare(Conversions.ToString(Left), Conversions.ToString(Right), Options);
 }
コード例 #12
0
 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;
 }
コード例 #13
0
ファイル: TextFindEngine.cs プロジェクト: sjyanxin/WPFSource
        // 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; 
        }
コード例 #14
0
ファイル: TextFindEngine.cs プロジェクト: sjyanxin/WPFSource
        // 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++) 
                    {
                        if (compareInfo.Compare(textString, i, j - i + 1, findPattern, 0, findPattern.Length, options) == 0 && 
                            (!matchWholeWord || IsAtWordBoundary(textString, i, j - i + 1, hasPreceedingSeparatorChar, hasFollowingSeparatorChar)))
                        {
                            if ((!matchKashida || IsKashidaMatch(textString.Substring(i, j - i + 1), findPattern, compareInfo)) &&
                                (!matchAlefHamza || IsAlefHamzaMatch(textString.Substring(i, j - i + 1), findPattern, compareInfo))) 
                            {
                                matchIndex = i; 
                                matchLength = j - i + 1; 
                                break;
                            } 
                        }
                    }
                }
            } 

            return matchIndex; 
        } 
コード例 #15
0
 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);
 }
コード例 #16
0
ファイル: CompareInfoTest.cs プロジェクト: carrie901/mono
	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);
	}
コード例 #17
0
ファイル: TextFindEngine.cs プロジェクト: sjyanxin/WPFSource
        // 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;
        }