Esempio n. 1
0
            public int Compare(String a, String b)
            {
                if (a == b)
                {
                    return(0);
                }
                if (a == null)
                {
                    return(-1);
                }
                if (b == null)
                {
                    return(1);
                }

                string sa = a as string;
                string sb = b as string;

                System.Globalization.CompareInfo myComparer = System.Globalization.CompareInfo.GetCompareInfo("en-US");
                if (sa != null && sb != null)
                {
                    return(myComparer.Compare(sa, sb, System.Globalization.CompareOptions.Ordinal));
                }
                throw new ArgumentException("a and b should be strings.");
            }
Esempio n. 2
0
 public static bool CompareString(string string1, string string2)
 {
     return(compare_info.Compare(string1, string2,
                                 System.Globalization.CompareOptions.IgnoreCase |
                                 System.Globalization.CompareOptions.IgnoreKanaType |
                                 System.Globalization.CompareOptions.IgnoreWidth) == 0);
 }
        /// <summary>
        /// The Virtual Payment Client need to use an Ordinal comparison to Sort on
        /// the field names to create the SHA256 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.
        /// </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>
        public int Compare(string a, string b)
        {
            // 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.");
        }
Esempio n. 4
0
        /// <summary> Compares the the attributes of the first LdapEntry to the second.
        /// Only the values of the attributes named at the construction of this
        /// object will be compared.  Multi-valued attributes compare on the first
        /// value only.
        ///
        /// </summary>
        /// <param name="object1">        Target entry for comparison.
        ///
        /// </param>
        /// <param name="object2">        Entry to be compared to.
        ///
        /// </param>
        /// <returns>     Negative value if the first entry is less than the second and
        /// positive if the first is greater than the second.  Zero is returned if all
        /// attributes to be compared are the same.
        /// </returns>
        public virtual int Compare(object object1, object object2)
        {
            LdapEntry     entry1 = (LdapEntry)object1;
            LdapEntry     entry2 = (LdapEntry)object2;
            LdapAttribute one, two;

            string[] first;  //multivalued attributes are ignored.
            string[] second; //we just use the first element
            int      compare, i = 0;

            if (collator == null)
            {
                //using default locale
                collator = System.Globalization.CultureInfo.CurrentCulture.CompareInfo;
            }

            do
            {
                //while first and second are equal
                one = entry1.getAttribute(sortByNames[i]);
                two = entry2.getAttribute(sortByNames[i]);
                if ((one != null) && (two != null))
                {
                    first   = one.StringValueArray;
                    second  = two.StringValueArray;
                    compare = collator.Compare(first[0], second[0]);
                }
                //We could also use the other multivalued attributes to break ties.
                //one of the entries was null
                else
                {
                    if (one != null)
                    {
                        compare = -1;
                    }
                    //one is greater than two
                    else if (two != null)
                    {
                        compare = 1;
                    }
                    //one is lesser than two
                    else
                    {
                        compare = 0; //tie - break it with the next attribute name
                    }
                }

                i++;
            }while ((compare == 0) && (i < sortByNames.Length));

            if (sortAscending[i - 1])
            {
                // return the normal ascending comparison.
                return(compare);
            }
            // negate the comparison for a descending comparison.
            return(-compare);
        }
Esempio n. 5
0
 public override int Compare(int slot1, int slot2)
 {
     System.String val1 = values[slot1];
     System.String val2 = values[slot2];
     if (val1 == null)
     {
         if (val2 == null)
         {
             return(0);
         }
         return(-1);
     }
     else if (val2 == null)
     {
         return(1);
     }
     return(collator.Compare(val1.ToString(), val2.ToString()));
 }
Esempio n. 6
0
        public /*protected internal*/ override bool TermCompare(Term term)
        {
            if (collator == null)
            {
                // Use Unicode code point ordering
                bool checkLower = false;
                if (!includeLower)
                {
                    // make adjustments to set to exclusive
                    checkLower = true;
                }
                if (term != null && (System.Object)term.Field() == (System.Object)field)
                {
                    // interned comparison
                    if (!checkLower || null == lowerTermText || String.CompareOrdinal(term.Text(), lowerTermText) > 0)
                    {
                        checkLower = false;
                        if (upperTermText != null)
                        {
                            int compare = String.CompareOrdinal(upperTermText, term.Text());

                            /*
                             * if beyond the upper term, or is exclusive and this is equal to
                             * the upper term, break out
                             */
                            if ((compare < 0) || (!includeUpper && compare == 0))
                            {
                                endEnum = true;
                                return(false);
                            }
                        }
                        return(true);
                    }
                }
                else
                {
                    // break
                    endEnum = true;
                    return(false);
                }
                return(false);
            }
            else
            {
                if (term != null && (System.Object)term.Field() == (System.Object)field)
                {
                    // interned comparison
                    if ((lowerTermText == null || (includeLower?collator.Compare(term.Text().ToString(), lowerTermText.ToString()) >= 0:collator.Compare(term.Text().ToString(), lowerTermText.ToString()) > 0)) && (upperTermText == null || (includeUpper?collator.Compare(term.Text().ToString(), upperTermText.ToString()) <= 0:collator.Compare(term.Text().ToString(), upperTermText.ToString()) < 0)))
                    {
                        return(true);
                    }
                    return(false);
                }
                endEnum = true;
                return(false);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// ReSort elements in the parent of <c>node</c>
        /// </summary>
        /// <remarks>
        /// Get the parent of this node and resort this node in the
        /// collection of nodes. We only operate on this node and we
        /// assume all nodes are already sorted except for this node
        /// </remarks>
        /// <param name="node">The node to sort</param>
        private void ReSortNodes(TreeNode node)
        {
            // We need to sort the node and rename it
            TreeNode parent = node.Parent;

            if (parent != null)
            {
                int newindex = -1;
                int curindex = -1;

                System.Globalization.CompareInfo comp =
                    System.Globalization.CultureInfo.CurrentCulture.CompareInfo;

                for (int i = 0; i < parent.Nodes.Count; i++)
                {
                    TreeNode tnode = parent.Nodes[i];

                    // We assume that the collection is already sorted
                    if (newindex == -1 &&
                        comp.Compare(node.Text, tnode.Text) < 0)
                    {
                        newindex = i;
                    }
                    if (node == tnode)
                    {
                        curindex = i;
                    }
                }

                if (curindex != -1)
                {
                    // We found the node we're editing.
                    if (newindex == -1)
                    {
                        // This node is to be put at the end
                        newindex = parent.Nodes.Count - 1;
                    }

                    if (curindex < newindex)
                    {
                        --newindex;
                    }

                    SelectedNode = null;
                    BeginUpdate();
                    parent.Nodes.RemoveAt(curindex);
                    parent.Nodes.Insert(newindex, node);
                    EndUpdate();
                }
            }
        }
 public int Compare(ScoreDoc i, ScoreDoc j)
 {
     System.String is_Renamed = index[i.doc];
     System.String js         = index[j.doc];
     if ((object)is_Renamed == (object)js)
     {
         return(0);
     }
     else if (is_Renamed == null)
     {
         return(-1);
     }
     else if (js == null)
     {
         return(1);
     }
     else
     {
         return(collator.Compare(is_Renamed.ToString(), js.ToString()));
     }
 }
Esempio n. 9
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 SHA256 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(String a, String 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.");
            }
Esempio n. 10
0
        static StackObject *Compare_0(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 3);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.String @string2 = (System.String) typeof(System.String).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            System.String @string1 = (System.String) typeof(System.String).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 3);
            System.Globalization.CompareInfo instance_of_this_method = (System.Globalization.CompareInfo) typeof(System.Globalization.CompareInfo).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            var result_of_this_method = instance_of_this_method.Compare(@string1, @string2);

            __ret->ObjectType = ObjectTypes.Integer;
            __ret->Value      = result_of_this_method;
            return(__ret + 1);
        }
 public int Compare(ScoreDoc i, ScoreDoc j)
 {
     return(collator.Compare(index[i.doc].ToString(), index[j.doc].ToString()));
 }
Esempio n. 12
0
        public override System.Collections.BitArray Bits(IndexReader reader)
        {
            System.Collections.BitArray bits = new System.Collections.BitArray(
                (reader.MaxDoc() % 64 == 0 ? reader.MaxDoc() / 64 : reader.MaxDoc() / 64 + 1) * 64);

            TermEnum enumerator = (null != lowerTerm && collator == null ?
                                   reader.Terms(new Term(fieldName, lowerTerm)) :
                                   reader.Terms(new Term(fieldName)));

            try
            {
                if (enumerator.Term() == null)
                {
                    return(bits);
                }

                TermDocs termDocs = reader.TermDocs();
                try
                {
                    if (collator != null)
                    {
                        do
                        {
                            Term term = enumerator.Term();
                            if (term != null && term.Field().Equals(fieldName))
                            {
                                if ((lowerTerm == null ||
                                     (includeLower ? collator.Compare(term.Text(), lowerTerm) >= 0 : collator.Compare(term.Text(), lowerTerm) > 0)) &&
                                    (upperTerm == null ||
                                     (includeUpper ? collator.Compare(term.Text(), upperTerm) <= 0 : collator.Compare(term.Text(), upperTerm) < 0)))
                                {
                                    // term in range, lookup docs
                                    termDocs.Seek(enumerator.Term());
                                    while (termDocs.Next())
                                    {
                                        bits.Set(termDocs.Doc(), true);
                                    }
                                }
                            }
                        }while (enumerator.Next());
                    }
                    else // null collator; using Unicode code point ordering
                    {
                        bool checkLower = false;
                        if (!includeLower) // make adjustments to set to exclusive
                        {
                            checkLower = true;
                        }
                        do
                        {
                            Term term = enumerator.Term();
                            if (term != null && term.Field().Equals(fieldName))
                            {
                                if (!checkLower || null == lowerTerm || String.CompareOrdinal(term.Text(), lowerTerm) > 0)
                                {
                                    checkLower = false;
                                    if (upperTerm != null)
                                    {
                                        int compare = String.CompareOrdinal(upperTerm, term.Text());

                                        /* if beyond the upper term, or is exclusive and
                                         * this is equal to the upper term, break out */
                                        if ((compare < 0) || (!includeUpper && compare == 0))
                                        {
                                            break;
                                        }
                                    }
                                    /* we have a good term, find the docs */

                                    termDocs.Seek(enumerator.Term());
                                    while (termDocs.Next())
                                    {
                                        bits.Set(termDocs.Doc(), true);
                                    }
                                }
                            }
                            else
                            {
                                break;
                            }
                        }while (enumerator.Next());
                    }
                }
                finally
                {
                    termDocs.Close();
                }
            }
            finally
            {
                enumerator.Close();
            }

            return(bits);
        }
Esempio n. 13
0
        public static int NumericCompare(string x, string y)
        {
            int px   = 0;
            int py   = 0;
            int lenx = x.Length;
            int leny = y.Length;

            while (px < lenx && py < leny)
            {
                if (isDigit(x[px]) && isDigit(y[py]))
                {
                    string nx = extractDigits(x, ref px);
                    string ny = extractDigits(y, ref py);

                    int d = 0;
                    try
                    {
                        d = Int32.Parse(nx.Normalize(NormalizationForm.FormKC)) - Int32.Parse(ny.Normalize(NormalizationForm.FormKC));
                        if (d != 0)
                        {
                            return(d);
                        }
                    }
                    catch { };

                    // AKB48とAKB0048のような例のために文字列でも比較する
                    d = String.Compare(nx, ny);
                    if (d != 0)
                    {
                        return(d);
                    }
                }
                else
                {
                    int ex = px;
                    int ey = py;
                    while (ex < lenx && ey < leny)
                    {
                        if (isDigit(x[ex]) && isDigit(y[ey]))
                        {
                            break;
                        }
                        ex++;
                        ey++;
                    }
                    string sx = x.Substring(px, ex - px);
                    string sy = y.Substring(py, ey - py);

                    // 大文字小文字カタカナひらがな全角半角を区別せずに比較
                    System.Globalization.CompareInfo ci = System.Globalization.CultureInfo.CurrentCulture.CompareInfo;
                    int result = ci.Compare(sx, sy, System.Globalization.CompareOptions.IgnoreCase | System.Globalization.CompareOptions.IgnoreKanaType | System.Globalization.CompareOptions.IgnoreWidth);
                    if (result != 0)
                    {
                        return(result);
                    }

                    // 優劣が付かなければ単純に比較 (実用上必要無い?)
                    result = String.Compare(sx, sy);
                    if (result != 0)
                    {
                        return(result);
                    }

                    px = ex;
                    py = ey;
                }
            }
            return((lenx - px) - (leny - py));
        }
 public bool Equals(string a, string b)
 {
     return(ci.Compare(a, b, options) == 0);
 }
Esempio n. 15
0
        public override Query Rewrite(IndexReader reader)
        {
            BooleanQuery query     = new BooleanQuery(true);
            string       testField = GetField();

            if (collator != null)
            {
                TermEnum enumerator    = reader.Terms(new Term(testField, ""));
                string   lowerTermText = lowerTerm != null?lowerTerm.Text() : null;

                string upperTermText = upperTerm != null?upperTerm.Text() : null;

                try
                {
                    do
                    {
                        Term term = enumerator.Term();
                        if (term != null && term.Field() == testField) // interned comparison
                        {
                            if ((lowerTermText == null ||
                                 (inclusive ? collator.Compare(term.Text(), lowerTermText) >= 0 : collator.Compare(term.Text(), lowerTermText) > 0))
                                &&
                                (upperTermText == null ||
                                 (inclusive ? collator.Compare(term.Text(), upperTermText) <= 0 : collator.Compare(term.Text(), upperTermText) < 0))
                                )
                            {
                                AddTermToQuery(term, query);
                            }
                        }
                    }while (enumerator.Next());
                }
                finally
                {
                    enumerator.Close();
                }
            }
            else
            {
                TermEnum enumerator = reader.Terms(lowerTerm);

                try
                {
                    bool checkLower = false;
                    if (!inclusive)
                    {
                        // make adjustments to set to exclusive
                        checkLower = true;
                    }

                    do
                    {
                        Term term = enumerator.Term();
                        if (term != null && term.Field() == testField)
                        {
                            // interned comparison
                            if (!checkLower || String.CompareOrdinal(term.Text(), lowerTerm.Text()) > 0)
                            {
                                checkLower = false;
                                if (upperTerm != null)
                                {
                                    int compare = String.CompareOrdinal(upperTerm.Text(), term.Text());

                                    /* if beyond the upper term, or is exclusive and
                                     * this is equal to the upper term, break out */
                                    if ((compare < 0) || (!inclusive && compare == 0))
                                    {
                                        break;
                                    }
                                }
                                AddTermToQuery(term, query); // Found a match
                            }
                        }
                        else
                        {
                            break;
                        }
                    }while (enumerator.Next());
                }
                finally
                {
                    enumerator.Close();
                }
            }
            return(query);
        }