Ejemplo n.º 1
0
        /// <summary>
        /// Compares whether two strings have equal placeholders.
        /// </summary>
        /// <param name="str1"></param>
        /// <param name="str2"></param>
        /// <returns></returns>
        static bool EqualPlaceholders(IString str1, IString str2)
        {
            if (str1 == null && str2 == null)
            {
                return(true);
            }
            if (str1 == null || str2 == null)
            {
                return(false);
            }
            if (str1.Placeholders.Length != str2.Placeholders.Length)
            {
                return(false);
            }
            int c = str1.Placeholders.Length;

            for (int i = 0; i < c; i++)
            {
                IPlaceholder ph1 = str1.Placeholders[i], ph2 = str2.Placeholders[i];
                if (!PlaceholderExpressionEquals.Equals(ph1.Expression, ph2.Expression))
                {
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Compare format strings for equality.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public bool Equals(IStringPart x, IStringPart y)
        {
            if (x == null && y == null)
            {
                return(true);
            }
            if (x == null || y == null)
            {
                return(false);
            }
            if (x == y)
            {
                return(true);
            }
            if (x.Kind != y.Kind)
            {
                return(false);
            }

            if (x.Kind == StringPartKind.Text)
            {
                if (x.Text != y.Text)
                {
                    return(false);
                }
            }

            if (x.Kind == StringPartKind.Placeholder)
            {
                var x_arg = x as IPlaceholder;
                var y_arg = y as IPlaceholder;
                if (x_arg.PlaceholderIndex != y_arg.PlaceholderIndex)
                {
                    return(false);
                }
                if (x_arg.PluralCategory != y_arg.PluralCategory)
                {
                    return(false);
                }
                if ((x_arg.Expression == null) != (y_arg.Expression == null))
                {
                    return(false);
                }
                if ((x_arg.Expression != null) && (y_arg.Expression != null))
                {
                    return(PlaceholderExpressionEquals.Equals(x_arg, y_arg));
                }
            }

            return(true);
        }