Beispiel #1
0
        /// <summary>
        /// Gets an enumerator that traverse through all permutations of a sub-array (starting from the specified <paramref name="startIndex"/> to the end) of the current <see cref="System.Array" />.
        /// </summary>
        /// <typeparam name="T">The type of elements in the current array.</typeparam>
        /// <param name="array">This <see cref="System.Array" />.</param>
        /// <param name="startIndex">The returned enumerator will go through all permutations of a sub-array starting from this index.</param>
        /// <returns>
        /// An enumerator that traverse through all permutations of a sub-array (starting from the element at the specified <paramref name="startIndex"/> to the end) of the current array.
        /// </returns>
        public static IEnumerator <T[]> GetPermutationEnumerator <T>(this T[] array, int startIndex)
        {
            ExceptionHelper.NonNegativeArgumentRequired("startIndex", startIndex);
            var innerIE = _perm <T>(array, startIndex, array.Length - startIndex);

            while (innerIE.MoveNext())
            {
                yield return(innerIE.Current);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Gets an object that can iterate through groups of substrings in this string instance (or a part of the current string instance according to <paramref name="startIndex" />) that are delimited by Unicode characters satisfying the specified primary predicate and secondary predicate.
 /// </summary>
 /// <param name="str">This string instance.</param>
 /// <param name="primaryPredicate">A function used to test each Unicode character of the current string. If a character passes this predicate, it returns a non-negative integer as the separator's index; otherwise, this function must return -1. Any character satisfying this predicate will be used as the primary separator. A primary spearator delimits substring arrays, for example, in "123,456;abc,def" which represent substring arrays { {"123", "456"}, {"abc", "def"} }, the semi-comma ';' is the primary separator.</param>
 /// <param name="secondaryPredicate">A function used to test each Unicode character of the current string. If a character passes this predicate, it returns a non-negative integer as the separator's index; otherwise, this function must return -1. Any character satisfying this predicate will be used as the secondary separator. A secondary separator delimits substrings in an array, for example, in "123,456;abc,def" which represent substring arrays { {"123", "456"}, {"abc", "def"} }, the comma ',' is the secondary separator.</param>
 /// <param name="startIndex">The zero-based position indicating where the search for separators starts.</param>
 /// <param name="removeEmptyEntries"><c>true</c> if the returned enumerator should ignore empty substrings; otherwise <c>false</c>.</param>
 /// <param name="trim">Indicates whether the returned substrings are trimmed.
 /// <para>NOTE that if <paramref name="removeEmptyEntries" /> is set <c>true</c>, then a substring containing only white spaces will be ignored by the returned enumerator;
 /// for example, in this case "123,   ,456;abc,def" split by comma ';' (primary separator) and ',' (secondary separator) is { {"123", "456"}, {"abc", "def"} }.</para></param>
 /// <returns>An object that can iterate through groups of substrings in this string instance (or a part of the current string instance) that are delimited by Unicode characters satisfying the specified two predicates.</returns>
 public static IEnumerator <string[]> GetDoubleSplitEnumerator(this string str, Func <char, bool> primaryPredicate, Func <char, bool> secondaryPredicate, int startIndex = 0, bool removeEmptyEntries = false, bool trim = false)
 {
     ExceptionHelper.NonNegativeArgumentRequired("startIndex", startIndex);
     return(_innerGetDoubleSplitEnumerator(str, startIndex, str.Length, primaryPredicate, secondaryPredicate, removeEmptyEntries, trim));
 }
Beispiel #3
0
 /// <summary>
 /// Searches for the specified string and returns the index of the first occurrence within the range of string elements in this one-dimensional string array that starts at the specified index.
 /// </summary>
 /// <param name="array">The one-dimensional string array to search.</param>
 /// <param name="value">The string to locate in this array.</param>
 /// <param name="startIndex">The starting index of the search. 0 (zero) is valid in an empty array.</param>
 /// <param name="comparisonType">One of the enumeration values that specifies the rules for the search.</param>
 /// <returns>The index of the first occurrence of <paramref name="value"/> within the range of elements in array that starts at <paramref name="startIndex"/>, if found; otherwise, -1.</returns>
 public static int IndexOf(this string[] array, string value, int startIndex, StringComparison comparisonType = StringComparison.Ordinal)
 {
     ExceptionHelper.NonNegativeArgumentRequired("startIndex", startIndex);
     return(_innerIndexOf(array, value, startIndex, array.Length, comparisonType));
 }
 /// <summary>
 /// Gets an object that can iterate through substrings in this string (or a part of this string)
 /// that are delimited by the specified separators.
 /// </summary>
 /// <param name="str">This string instance.</param>
 /// <param name="separators">String instances that delimit the substrings in the current string instance.</param>
 /// <param name="startIndex">The zero-based position indicating where the search for separators starts.</param>
 /// <param name="removeEmptyEntries"><c>true</c> if the returned enumerator should ignore empty substrings; otherwise <c>false</c>.</param>
 /// <param name="trim">Indicates whether the returned substrings are trimmed.
 /// <para>NOTE that if <paramref name="removeEmptyEntries" /> is set <c>true</c>, then a substring containing only white spaces will not be returned;
 /// for example, in this case "ab||   **  cd" split by "||" and "**" is "ab" and "cd".</para></param>
 /// <returns>
 /// An object that can iterate through substrings in the current string instance (or a part of the current string instance)
 /// that are delimited by the specified separators.
 /// </returns>
 public static IEnumerator <string> GetSplitEnumerator(this string str, string[] separators, int startIndex = 0, bool removeEmptyEntries = false, bool trim = false)
 {
     ExceptionHelper.NonNegativeArgumentRequired("startIndex", startIndex);
     return(_innerGetSplitEnumerator(str, separators, startIndex, str.Length, removeEmptyEntries, trim));
 }
Beispiel #5
0
 /// <summary>
 /// Gets an object that can iterate through groups of substrings in this string instance (or a part of the current string instance according to <paramref name="startIndex"/>) that are delimited by the primary and secondary Unicode separators outside quotes.
 /// </summary>
 /// <param name="str">This string instance.</param>
 /// <param name="primarySeparator">A primary spearator delimits substring groups, for example, in "123,456;abc,def" which represent substring arrays { {"123", "456"}, {"abc", "def"} }, the semi-comma ';' is the primary separator.</param>
 /// <param name="secondarySeparator">A secondary separator delimits substrings in a group, for example, in "123,456;abc,def" which represent substring arrays { {"123", "456"}, {"abc", "def"} }, the comma ',' is the secondary separator.</param>
 /// <param name="startIndex">The zero-based position indicating where the search for separators starts.</param>
 /// <param name="leftQuotes">Specifies an array of Unicode characters as the left quotes.
 /// A left quote of an index of this array corresponds to the right quote of that index of the array specified by <paramref name="rightQuotes" />.</param>
 /// <param name="rightQuotes">Specifies an array of Unicode characters as the right quotes.
 /// A right quote of an index of this array corresponds to the left quote of that index of the array specified by <paramref name="leftQuotes" />.</param>
 /// <param name="removeEmptyEntries"><c>true</c> if empty strings should be ignored; otherwise <c>false</c>.</param>
 /// <param name="removeEmptyGroups"><c>true</c> if empty substring groups should be ignored by the returned enumerator; otherwise, <c>false</c>.</param>
 /// <param name="trim">Indicates whether the returned substrings are trimmed.
 /// <para>NOTE that if <paramref name="removeEmptyEntries" /> is set <c>true</c>, then a substring containing only white spaces will be ignored by the returned enumerator;
 /// for example, in this case "ab,   ,cd" split by comma ',' is "ab" and "cd".</para></param>
 /// <param name="keepQuotes"><c>true</c> if the quotes should be included in each returned substring; otherwise, <c>false</c>.</param>
 /// <returns>An object that can iterate through groups of substrings in this string instance (or a part of the current string instance) that are delimited by the primary and secondary separators.</returns>
 public static IEnumerator <string[]> GetDoubleSplitEnumeratorWithQuotes(this string str, char primarySeparator, char secondarySeparator, int startIndex, char[] leftQuotes, char[] rightQuotes, bool removeEmptyEntries = false, bool removeEmptyGroups = false, bool trim = false, bool keepQuotes = true)
 {
     ExceptionHelper.NonNegativeArgumentRequired("startIndex", startIndex);
     return(new _innerDoubleSplitEnumerator02(str, startIndex, str.Length, c1 => c1 == primarySeparator, c2 => c2 == secondarySeparator, leftQuotes, rightQuotes, removeEmptyEntries, removeEmptyGroups, trim, keepQuotes));
 }
Beispiel #6
0
 /// <summary>
 /// Gets an object that can iterate through groups of substrings in this string instance (or a part of the current string instance according to <paramref name="startIndex"/>) that are delimited by Unicode characters outside quotes and satisfying the specified primary predicate and secondary predicate.
 /// </summary>
 /// <param name="str">This string instance.</param>
 /// <param name="primaryPredicate">A function used to test each Unicode character of the current string. If a character passes this predicate, it returns a non-negative integer as the separator's index; otherwise, this function must return -1. Any character satisfying this predicate will be used as the primary separator. A primary spearator delimits substring arrays, for example, in "123,456;abc,def" which represent substring arrays { {"123", "456"}, {"abc", "def"} }, the semi-comma ';' is the primary separator.</param>
 /// <param name="secondaryPredicate">A function used to test each Unicode character of the current string. If a character passes this predicate, it returns a non-negative integer as the separator's index; otherwise, this function must return -1. Any character satisfying this predicate will be used as the secondary separator. A secondary separator delimits substrings in an array, for example, in "123,456;abc,def" which represent substring arrays { {"123", "456"}, {"abc", "def"} }, the comma ',' is the secondary separator.</param>
 /// <param name="startIndex">The zero-based position indicating where the search for separators starts.</param>
 /// <param name="leftQuote">The left quote paired by <paramref name="rightQuote"/> to escape separators.</param>
 /// <param name="rightQuote">The right quote paired by <paramref name="leftQuote"/> to escape separators.</param>
 /// <param name="removeEmptyEntries"><c>true</c> if empty strings should be ignored; otherwise <c>false</c>.</param>
 /// <param name="removeEmptyGroups"><c>true</c> if empty substring groups should be ignored by the returned enumerator; otherwise, <c>false</c>.</param>
 /// <param name="trim">Indicates whether the returned substrings are trimmed.
 /// <para>NOTE that if <paramref name="removeEmptyEntries" /> is set <c>true</c>, then a substring containing only white spaces will be ignored by the returned enumerator;
 /// for example, in this case "ab,   ,cd" split by comma ',' is "ab" and "cd".</para></param>
 /// <param name="keepQuotes"><c>true</c> if the quotes should be included in each returned substring; otherwise, <c>false</c>.</param>
 /// <returns>An object that can iterate through groups of substrings in this string instance (or a part of the current string instance) that are delimited by Unicode characters satisfying the specified two predicates.</returns>
 public static IEnumerator <string[]> GetDoubleSplitEnumeratorWithQuotes(this string str, Func <char, bool> primaryPredicate, Func <char, bool> secondaryPredicate, int startIndex, char leftQuote = '{', char rightQuote = '}', bool removeEmptyEntries = false, bool removeEmptyGroups = false, bool trim = false, bool keepQuotes = true)
 {
     ExceptionHelper.NonNegativeArgumentRequired("startIndex", startIndex);
     return(new _innerDoubleSplitEnumerator01(str, startIndex, str.Length, primaryPredicate, secondaryPredicate, leftQuote, rightQuote, removeEmptyEntries, removeEmptyGroups, trim, keepQuotes));
 }
Beispiel #7
0
 /// <summary>
 /// Gets an object that can iterate through <see cref="StringSplitResult"/> objects that represent substring information in this string (or a part of the current string instance according to <paramref name="startIndex" />)
 /// that are delimited by specified Unicode characters.
 /// </summary>
 /// <param name="str">This string instance.</param>
 /// <param name="separators">A non-empty array of Unicode characters that delimit the substrings in the current string instance.</param>
 /// <param name="startIndex">The zero-based position indicating where the search for separators starts.</param>
 /// <param name="removeEmptyEntries"><c>true</c> if the returned enumerator should ignore empty substrings; otherwise <c>false</c>.</param>
 /// <param name="trim">Indicates whether the returned substrings are trimmed.
 /// <para>NOTE that if <paramref name="removeEmptyEntries" /> is set <c>true</c>, then a substring containing only white spaces will not be returned;
 /// for example, in this case "ab,   ,cd" split by comma ',' is "ab" and "cd".</para></param>
 /// <returns>
 /// An object that can iterate through information about substrings in the current string instance (or a part of the current string instance) that are delimited by the specified Unicode characters.
 /// </returns>
 public static IEnumerator <StringSplitResult> GetSplitEnumeratorEx(this string str, char[] separators, int startIndex, bool removeEmptyEntries = false, bool trim = true)
 {
     ExceptionHelper.NonNegativeArgumentRequired("startIndex", startIndex);
     return(new _innerSplitEnumeratorEx02(str, separators, startIndex, str.Length, removeEmptyEntries, trim));
 }
Beispiel #8
0
 /// <summary>
 /// Gets an object that can iterate through information about substrings in this string instance (or a part of the current string instance according to <paramref name="startIndex" />)
 /// that are delimited by Unicode characters satisfying the specified predicate.
 /// </summary>
 /// <param name="str">This string instance.</param>
 /// <param name="startIndex">The zero-based position indicating where the search for characters satisfying <paramref name="predicate" /> starts.</param>
 /// <param name="predicate">A function used to test each Unicode character of the current string. If a character passes this predicate, it returns a non-negative integer as the separator's index; otherwise, this function must return -1. Any character satisfying this predicate will be used as the separator.</param>
 /// <param name="removeEmptyEntries"><c>true</c> if the returned enumerator should ignore empty substrings; otherwise <c>false</c>.</param>
 /// <param name="trim">Indicates whether the returned substrings are trimmed.
 /// <para>NOTE that if <paramref name="removeEmptyEntries" /> is set <c>true</c>, then a substring containing only white spaces will not be returned;
 /// for example, in this case "ab,   ,cd" split by comma ',' is "ab" and "cd".</para></param>
 /// <returns>
 /// An object that can iterate through information about substrings in the current string instance that are delimited by Unicode characters satisfying the specified predicate.
 /// </returns>
 public static IEnumerator <StringSplitResult> GetSplitEnumeratorEx(this string str, Func <char, int> predicate, int startIndex, bool removeEmptyEntries = false, bool trim = false)
 {
     ExceptionHelper.NonNegativeArgumentRequired("startIndex", startIndex);
     return(new _innerSplitEnumeratorEx01(str, predicate, startIndex, str.Length, removeEmptyEntries, trim));
 }
 /// <summary>
 /// Gets an object that can iterate through substrings in this string (or a part of this string according to <paramref name="startIndex"/>) that are delimited by the specified Unicode character.
 /// </summary>
 /// <param name="str">This string instance.</param>
 /// <param name="separator">A Unicode character that delimits the substrings in the current string instance.</param>
 /// <param name="startIndex">The zero-based position indicating where the search for separators starts.</param>
 /// <param name="removeEmptyEntries"><c>true</c> if the returned enumerator should ignore empty substrings; otherwise <c>false</c>.</param>
 /// <param name="trim">Indicates whether the returned substrings are trimmed.
 /// <para>NOTE if <paramref name="removeEmptyEntries" /> is set <c>true</c>, then a substring containing only white spaces will be ignored by the returned enumerator;
 /// for example, in this case "ab,   ,cd" split by comma ',' is "ab" and "cd".</para></param>
 /// <param name="keepSeparator"><c>true</c> if the separator should be included in each substring returned by the enumerator; otherwise, <c>false</c>.</param>
 /// <returns>
 /// An object that can iterate through substrings in the current string instance (or a part of the current string instance)
 /// that are delimited by the specified Unicode character.
 /// </returns>
 public static IEnumerator <string> GetSplitEnumerator(this string str, char separator, int startIndex, bool removeEmptyEntries = false, bool trim = false, bool keepSeparator = false)
 {
     ExceptionHelper.NonNegativeArgumentRequired("startIndex", startIndex);
     return(new _innerSplitEnumerator02(str, separator, startIndex, str.Length, removeEmptyEntries, trim, keepSeparator));
 }
 /// <summary>
 /// Searches for any of the specified strings and returns the index of the first occurrence within the range of string elements in this one-dimensional string array that starts at the specified index.
 /// </summary>
 /// <param name="array">The one-dimensional string array to search.</param>
 /// <param name="values">The strings to locate in this array.</param>
 /// <param name="startIndex">The starting index of the search. 0 (zero) is valid in an empty array.</param>
 /// <param name="comparisonType">One of the enumeration values that specifies the rules for the search.</param>
 /// <returns>An <see cref="ElementSearchResult&lt;TElement&gt;"/> object that stores the index of the first occurrence of any of the <paramref name="values"/> within the range of elements in array that starts at <paramref name="startIndex"/>, if found; otherwise, <c>null</c>.</returns>
 public static ElementSearchResult <string> IndexOfAny(this string[] array, string[] values, int startIndex, StringComparison comparisonType = StringComparison.Ordinal)
 {
     ExceptionHelper.NonNegativeArgumentRequired("startIndex", startIndex);
     return(_innerIndexOfAny(array, values, startIndex, array.Length, comparisonType));
 }
Beispiel #11
0
 public static IEnumerator <StringSplitResult> GetSplitEnumeratorWithQuotesEx(this string str, Func <char, int> predicate, int startIndex,
                                                                              char leftQuote = '{', char rightQuote = '}', bool removeEmptyEntries = false, bool trim = false, bool keepQuotes = true, bool keepSeparator = false)
 {
     ExceptionHelper.NonNegativeArgumentRequired("startIndex", startIndex);
     return(new _innerSplitWithQuotesEnumeratorEx01(str, predicate, startIndex, str.Length, leftQuote, rightQuote, removeEmptyEntries, trim, keepQuotes));
 }