예제 #1
0
        /// <summary>Vergleicht das aktuelle Objekt mit einem anderen Objekt desselben Typs.</summary>
        /// <returns>Ein Wert, der die relative Reihenfolge der verglichenen Objekte angibt. Der Rückgabewert hat folgende Bedeutung: Wert  Bedeutung  Kleiner als 0  Dieses Objekt ist kleiner als der <paramref name="other" />-Parameter. Zero  Dieses Objekt ist gleich <paramref name="other" />.  Größer als 0 (null)  Dieses Objekt ist größer als <paramref name="other" />.</returns>
        /// <param name="other">Ein Objekt, das mit diesem Objekt verglichen werden soll.</param>
        /// <param name="comparisonType">Art des Stringvergleiches</param>
        public int CompareTo(Path other, PathComparison comparisonType)
        {
            StringComparison stringComparison = comparisonType.ConvertToStringComparison().OrDefault(DefaultComparison);

            for (var i = 0; i < m_parts.Count && i < other.m_parts.Count; i++)
            {
                int result = string.Compare(m_parts[i], other.m_parts[i], stringComparison);
                if (result != 0)
                {
                    return(result);
                }
            }

            return(m_parts.Count.CompareTo(other.m_parts.Count));
        }
예제 #2
0
        public bool StartsWith(Path start, PathComparison comparison = PathComparison.Default)
        {
            if (start.Count > Count)
            {
                return(false);
            }
            StringComparison stringComparison = comparison.ConvertToStringComparison().OrDefault(DefaultComparison);

            for (var i = 0; i < start.Count; i++)
            {
                if (!string.Equals(this[i], start[i], stringComparison))
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #3
0
        public int IndexOf(string item, int index = 0, PathComparison comparison = PathComparison.Default)
        {
            StringComparison stringComparison = comparison.ConvertToStringComparison().OrDefault(DefaultComparison);

            return(m_parts.FindIndex(index, part => string.Equals(part, item, stringComparison)));
        }
예제 #4
0
        public Path Replace([NotNull] Path search, [NotNull] Path replace, PathComparison comparison = PathComparison.Default, int maxStartIndex = int.MaxValue)
        {
            if (search == null)
            {
                throw new ArgumentNullException(nameof(search));
            }
            if (replace == null)
            {
                throw new ArgumentNullException(nameof(replace));
            }

            if (Count < search.Count)
            {
                return(this);
            }
            int startIndex = IndexOf(search.m_parts[0], 0, comparison);

            if (startIndex > maxStartIndex)
            {
                return(this);
            }
            if (startIndex < 0)
            {
                return(this);
            }
            if (Count + startIndex < search.Count)
            {
                return(this);
            }

            StringComparison stringComparison = comparison.ConvertToStringComparison().OrDefault(DefaultComparison);

            while (startIndex > -1)
            {
                bool equal = true;
                for (var i = 0; i + startIndex < m_parts.Count && i < search.m_parts.Count; i++)
                {
                    if (!string.Equals(m_parts[i + startIndex], search.m_parts[i], stringComparison))
                    {
                        startIndex = IndexOf(search.m_parts[0], i + startIndex + 1);
                        if (startIndex > maxStartIndex)
                        {
                            return(this);
                        }
                        equal = false;
                        break;
                    }
                }

                if (equal)
                {
                    break;
                }
            }

            if (startIndex == -1)
            {
                return(this);
            }
            return(new Path(this.Take(startIndex).Concat(replace).Concat(this.Skip(startIndex + search.Count)), Separator, DefaultComparison));
        }