Exemple #1
0
        public int CompareTo(UnicodeString str)
        {
            //int result = String.CompareTo(str.String);
            int result = string.Compare(String, str.String, StringComparison.CurrentCulture);

            //As per the Equals method lets do this in stages
            if (result != 0)
            {
                return(result);
            }

            //OK string appears to be equal but now lets compare formatting Runs
            if (field_4_format_runs == null)
            {
                //Strings are equal, and there are no formatting runs. -> 0
                //Strings are equal, but one or the other has formatting runs -> 1
                return((str.field_4_format_runs == null) ? 0 : 1);
            }
            else if (str.field_4_format_runs == null)
            {
                //Strings are equal, but one or the other has formatting runs
                return(-1);
            }

            //Strings are Equal, so now compare formatting Runs.
            int size = field_4_format_runs.Count;

            if (size != str.field_4_format_runs.Count)
            {
                return(size - str.field_4_format_runs.Count);
            }

            for (int i = 0; i < size; i++)
            {
                FormatRun Run1 = field_4_format_runs[(i)];
                FormatRun run2 = str.field_4_format_runs[(i)];

                result = Run1.CompareTo(run2);
                if (result != 0)
                {
                    return(result);
                }
            }

            //Well the format Runs are equal as well!, better check the ExtRst data
            if (field_5_ext_rst == null)
            {
                return((str.field_5_ext_rst == null) ? 0 : 1);
            }
            else if (str.field_5_ext_rst == null)
            {
                return(-1);
            }
            else
            {
                return(field_5_ext_rst.CompareTo(str.field_5_ext_rst));
            }
        }
Exemple #2
0
        /**
         * Our handling of Equals is inconsistent with CompareTo.  The trouble is because we don't truely understand
         * rich text fields yet it's difficult to make a sound comparison.
         *
         * @param o     The object to Compare.
         * @return      true if the object is actually Equal.
         */
        public override bool Equals(Object o)
        {
            if (!(o is UnicodeString))
            {
                return(false);
            }
            UnicodeString other = (UnicodeString)o;

            //OK lets do this in stages to return a quickly, first check the actual string
            bool eq = ((field_1_charCount == other.field_1_charCount) &&
                       (field_2_optionflags == other.field_2_optionflags) &&
                       field_3_string.Equals(other.field_3_string));

            if (!eq)
            {
                return(false);
            }

            //OK string appears to be equal but now lets compare formatting Runs
            if ((field_4_format_Runs == null) && (other.field_4_format_Runs == null))
            {
                //Strings are Equal, and there are not formatting Runs.
                return(true);
            }
            if (((field_4_format_Runs == null) && (other.field_4_format_Runs != null)) ||
                (field_4_format_Runs != null) && (other.field_4_format_Runs == null))
            {
                //Strings are Equal, but one or the other has formatting Runs
                return(false);
            }

            //Strings are Equal, so now compare formatting Runs.
            int size = field_4_format_Runs.Count;

            if (size != other.field_4_format_Runs.Count)
            {
                return(false);
            }

            for (int i = 0; i < size; i++)
            {
                FormatRun Run1 = field_4_format_Runs[(i)];
                FormatRun run2 = other.field_4_format_Runs[(i)];

                if (!Run1.Equals(run2))
                {
                    return(false);
                }
            }

            // Well the format Runs are equal as well!, better check the ExtRst data
            if (field_5_ext_rst == null && other.field_5_ext_rst == null)
            {
                // Good
            }
            else if (field_5_ext_rst != null && other.field_5_ext_rst != null)
            {
                int extCmp = field_5_ext_rst.CompareTo(other.field_5_ext_rst);
                if (extCmp == 0)
                {
                    // Good
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }

            //Phew!! After all of that we have finally worked out that the strings
            //are identical.
            return(true);
        }