/// <summary> /// Reports the zero-based index of the next character which matches another specified character. The method supports classic escaping. /// Those matched characters are usually brackets, such as '(' and ')', '[' and ']', '{' and '}'. /// </summary> /// <param name="str">This string instance.</param> /// <param name="leftChar">The character that matches the character to search, typically a left bracket, such as '(', '[' or '{'.</param> /// <param name="rightChar">The next character to search, typically a right bracket, such as ')', ']' or '}'.</param> /// <param name="escape">The character that escapes the <paramref name="rightChar"/>, typically '\'. For example, suppose '\' is used for escaping, then the match for the first left square bracket in string "[abc\]abc]" is the last right square bracket, not the one in the middle because the '\' that precedes it escapes it.</param> /// <param name="startIndex">The search starting position. NOTE that this position should be right at the <paramref name="leftChar"/> you want to find a match for. For example, if it is intended to find a match of the first left square bracket at position 0 in string "[abc[de]fgh]", the <paramref name="startIndex" /> should be 0.</param> /// <param name="length">The number of characters to search. The parameter determines the search ending position along with <paramref name="startIndex" />.</param> /// <returns> /// The zero-based index position of <paramref name="rightChar" /> if that character is found and it matches <paramref name="leftChar" />, or -1 if it is not. /// </returns> public static int IndexOfNextMatch(this string str, char leftChar, char rightChar, char escape, int startIndex, int length) { var endIndex = ExceptionHelper.ForwardCheckStartIndexAndLength(startIndex, length, str.Length); _searchRightQuote(str, ref startIndex, endIndex, leftChar, rightChar, escape.Singleton()); return(startIndex); }
public static IEnumerator <StringSplitResult> GetSplitEnumeratorWithQuotesEx(this string str, Func <char, int> predicate, int startIndex, int length, char leftQuote = '{', char rightQuote = '}', bool removeEmptyEntries = false, bool trim = false, bool keepQuotes = true) { var endIndex = ExceptionHelper.ForwardCheckStartIndexAndLength(startIndex, length, str.Length); return(new _innerSplitWithQuotesEnumeratorEx01(str, predicate, startIndex, endIndex, leftQuote, rightQuote, removeEmptyEntries, trim, keepQuotes)); }
/// <summary> /// Gets an enumerator that traverse through all permutations of a sub-array (starting from the element at the specified <paramref name="startIndex" /> to the element at index <paramref name="startIndex" /> + <paramref name="length"/> - 1) 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 the element at this index to the element at index <paramref name="startIndex" /> + <paramref name="length"/> - 1.</param> /// <param name="length">The returned enumerator will go through all permutations of a sub-array starting from the element at <paramref name="startIndex" /> to the element at index <paramref name="startIndex" /> + <paramref name="length"/> - 1.</param> /// <returns> /// An enumerator that traverse through all permutations of a sub-array (starting from the specified <paramref name="startIndex" /> to the element at index <paramref name="startIndex" /> + <paramref name="length"/> - 1 of the current array. /// </returns> public static IEnumerator <T[]> GetPermutationEnumerator <T>(this T[] array, int startIndex, int length) { ExceptionHelper.ForwardCheckStartIndexAndLength(startIndex, length, array.Length); var innerIE = _perm <T>(array, startIndex, length); while (innerIE.MoveNext()) { yield return(innerIE.Current); } }
/// <summary> /// Gets an enumerator that traverse through k-combinations of elements in the current <see cref="System.Array"/>. A k-combination is a subset of the current array which contains k elements. For example, {1,2,3}, {2,3,4}, etc., are the 3-combinations of integer array {1,2,3,4,5}. /// </summary> /// <typeparam name="T">The type of elements in the current array.</typeparam> /// <param name="array">This array.</param> /// <param name="startIndex">The elements in the returned combinations will be limited to elements starting from this index and ending at <paramref name="startIndex"/> + <paramref name="length"/> - 1.</param> /// <param name="length">The elements in the returned combinations will be limited to elements starting from <paramref name="startIndex"/> and ending at <paramref name="startIndex"/> + <paramref name="length"/> - 1.</param> /// <param name="k">The number of elements of each combination returned by the enumerator.</param> /// <returns>An enumerator that traverse through k-combinations of elements in the current array.</returns> public static IEnumerator <T[]> GetCombinationEnumerator <T>(this T[] array, int startIndex, int length, int k) { var endIndex = ExceptionHelper.ForwardCheckStartIndexAndLength(startIndex, length, array.Length); ExceptionHelper.ArgumentRangeRequired <int>("k", k, 0, true, length, true); var innerIE = _combNonRecursive <T>(array, startIndex, endIndex, length, k); while (innerIE.MoveNext()) { yield return(innerIE.Current); } }
/// <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"/> and <paramref name="length"/>) 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="length">A positive value indicating the number of characters to search starting from the position specified by <paramref name="startIndex" />.</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, int length, char[] leftQuotes, char[] rightQuotes, bool removeEmptyEntries = false, bool removeEmptyGroups = false, bool trim = false, bool keepQuotes = true) { ExceptionHelper.ForwardCheckStartIndexAndLength(startIndex, length, str.Length); return(new _innerDoubleSplitEnumerator02(str, startIndex, str.Length, c1 => c1 == primarySeparator, c2 => c2 == secondarySeparator, leftQuotes, rightQuotes, removeEmptyEntries, removeEmptyGroups, trim, keepQuotes)); }
public static IEnumerator <StringDoubleSplitResult> GetDoubleSplitEnumeratorWithQuotesEx(string str, int startIndex, int length, Func <char, int> primaryPredicate, Func <char, int> secondaryPredicate, char[] leftQuotes, char[] rightQuotes, bool removeEmptyEntires = false, bool trim = false, bool keepQuotes = true) { var endIndex = ExceptionHelper.ForwardCheckStartIndexAndLength(startIndex, length, str.Length); return(_innerGetDoubleSplitEnumeratorWithQuotesEx(str, startIndex, endIndex, primaryPredicate, secondaryPredicate, leftQuotes, rightQuotes, removeEmptyEntires, trim, keepQuotes)); }
/// <summary> /// Reports the zero-based index of the first occurrence of any of the specified <paramref name="values" /> outside quotes in this string. /// </summary> /// <param name="str">This string instance.</param> /// <param name="values">The substrings to seek.</param> /// <param name="startIndex">The search starting position.</param> /// <param name="length">A positive value indicating the number of characters to search starting from the position specified by <paramref name="startIndex" />.</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="comparisonType">One of the enumeration values that specifies the rules for the search of <paramref name="values"/>.</param> /// <returns> /// The zero-based index position of the first occurrence of <paramref name="value" /> if it is found outside quotes, or -1 if it is not. /// </returns> /// <exception cref="System.FormatException">Occurs when there is quote mismatch in the string instance.</exception> public static StringSearchResult IndexOfAnyWithQuotes(this string str, string[] values, int startIndex, int length, char[] leftQuotes, char[] rightQuotes, StringComparison comparisonType = StringComparison.Ordinal) { var endIndex = ExceptionHelper.ForwardCheckStartIndexAndLength(startIndex, length, str.Length); return(_innerIndexOfWithQuotes(str, values, startIndex, endIndex, leftQuotes, rightQuotes, comparisonType)); }
/// <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"/> and <paramref name="length"/>) 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="length">A positive value indicating the number of characters to search starting from the position specified by <paramref name="startIndex" />.</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 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, int length, char[] leftQuotes, char[] rightQuotes, bool removeEmptyEntries = false, bool removeEmptyGroups = false, bool trim = false, bool keepQuotes = true) { var endIndex = ExceptionHelper.ForwardCheckStartIndexAndLength(startIndex, length, str.Length); return(new _innerDoubleSplitEnumerator02(str, startIndex, endIndex, primaryPredicate, secondaryPredicate, leftQuotes, rightQuotes, removeEmptyEntries, removeEmptyGroups, trim, keepQuotes)); }
/// <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 and contains the specified number of elements. /// </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="count">The number of elements in the section to search.</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"/> and contains the number of elements specified in <paramref name="count"/>, if found; otherwise, -1.</returns> public static int IndexOf(this string[] array, string value, int startIndex, int count, StringComparison comparisonType = StringComparison.Ordinal) { var endIndex = ExceptionHelper.ForwardCheckStartIndexAndLength(startIndex, count, array.Length); return(_innerIndexOf(array, value, startIndex, endIndex, comparisonType)); }
/// <summary> /// Reports the zero-based index of the first occurrence of the specified escapable Unicode character in this string. /// </summary> /// <param name="str">This string instance.</param> /// <param name="values">A unicode character to seek.</param> /// <param name="startIndex">The search starting position.</param> /// <param name="length">A positive value indicating the number of characters to search starting from the position specified by <paramref name="startIndex"/>.</param> /// <param name="escape">Specifies the Unicode character as the escape indicator. /// Use two consecutive escape characters to indicate the literal value of an escape character.</para> /// </param> /// <returns>The zero-based index position of the first occurrence of <paramref name="value"/> if it is found, or -1 if it is not.</returns> public static int IndexOfWithEscape(this string str, char value, int startIndex, int length, Func <char, bool> escapePredicate) { var endIndex = ExceptionHelper.ForwardCheckStartIndexAndLength(startIndex, length, str.Length); return(_innerIndexOfWithEscape(str, c => c == value, startIndex, endIndex, escapePredicate)); }
/// <summary> /// Reports the zero-based index of the first occurrence of the specified Unicode character outside quotes in this string. /// </summary> /// <param name="str">This string instance.</param> /// <param name="value">The Unicode character to seek.</param> /// <param name="startIndex">The search starting position.</param> /// <param name="length">A positive value indicating the number of characters to search starting from the position specified by <paramref name="startIndex" />.</param> /// <param name="leftQuote">Specifies the Unicode character as the left quote.</param> /// <param name="rightQuote">Specifies the Unicode character as the right quote.</param> /// <returns> /// The zero-based index position of the first occurrence of <paramref name="value" /> if it is found outside quotes, or -1 if it is not. /// </returns> public static int IndexOfWithQuotes(this string str, char value, int startIndex, int length, char leftQuote = '{', char rightQuote = '}') { var endIndex = ExceptionHelper.ForwardCheckStartIndexAndLength(startIndex, length, str.Length); return(_innerIndexOfWithQuotes(str, value, startIndex, endIndex, leftQuote, rightQuote)); }
/// <summary> /// Reports the zero-based index of the first occurrence in this instance of any character in a specified array of Unicode characters <paramref name="anyOf"/>. /// The search starts at a specified character position and examines a specified number of character positions. /// </summary> /// <param name="str">This string instance.</param> /// <param name="anyOf">A Unicode character array containing one or more characters to seek.</param> /// <param name="startIndex">The search starting position.</param> /// <param name="count">The number of character positions to examine.</param> /// <param name="hitIndex">Returns the index of the encountered character in the specified array of Unicode characters.</param> /// <returns>The zero-based index position of the first character in this instance satisfying the specified predicate.</returns> public static int IndexOfAny(this string str, char[] anyOf, int startIndex, int count, out int hitIndex) { var endIndex = ExceptionHelper.ForwardCheckStartIndexAndLength(startIndex, count, str.Length, "startIndex", "count"); return(_innerIndexOfAny(str, anyOf, startIndex, endIndex, out hitIndex)); }
/// <summary> /// Reports the zero-based index of the first occurrence of any of the specified Unicode characters outside quotes in this string. /// </summary> /// <param name="str">This string instance.</param> /// <param name="values">Unicode characters to seek.</param> /// <param name="startIndex">The search starting position.</param> /// <param name="length">A positive value indicating the number of characters to search starting from the position specified by <paramref name="startIndex" />.</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> /// <returns> /// The zero-based index position of the first occurrence of any value specified in <paramref name="values" /> if it is found outside quotes, or -1 if it is not. /// </returns> public static int IndexOfAnyWithQuotes(this string str, char[] values, int startIndex, int length, char[] leftQuotes, char[] rightQuotes) { var endIndex = ExceptionHelper.ForwardCheckStartIndexAndLength(startIndex, length, str.Length); return(_innerIndexOfWithQuotes(str, values, startIndex, endIndex, leftQuotes, rightQuotes)); }
/// <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" /> and <paramref name="length" />) /// that are delimited by Unicode characters satisfying the specified predicate. /// </summary> /// <param name="str">This string instance.</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="startIndex">The zero-based position indicating where the search for characters satisfying <paramref name="predicate" /> starts.</param> /// <param name="length">A positive value indicating the number of characters to search starting from the position specified by <paramref name="startIndex" />.</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 Unicode characters satisfying the specified predicate. /// </returns> public static IEnumerator <StringSplitResult> GetSplitEnumeratorEx(this string str, Func <char, int> predicate, int startIndex, int length, bool removeEmptyEntries = false, bool trim = false) { var endIndex = ExceptionHelper.ForwardCheckStartIndexAndLength(startIndex, length, str.Length); return(new _innerSplitEnumeratorEx01(str, predicate, startIndex, endIndex, removeEmptyEntries, trim)); }
/// <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 and contains the specified number of elements. /// </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="count">The number of elements in the section to search.</param> /// <param name="comparisonType">One of the enumeration values that specifies the rules for the search.</param> /// <returns>An <see cref="ElementSearchResult<TElement>"/> 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"/> and contains the number of elements specified in <paramref name="count"/>, if found; otherwise, <c>null</c>.</returns> public static ElementSearchResult <string> IndexOfAny(this string[] array, string[] values, int startIndex, int length, StringComparison comparisonType = StringComparison.Ordinal) { var endIndex = ExceptionHelper.ForwardCheckStartIndexAndLength(startIndex, length, array.Length); return(_innerIndexOfAny(array, values, startIndex, endIndex, comparisonType)); }
/// <summary> /// Gets an object that can iterate through substrings in this string (or a part of this string according to <paramref name="startIndex"/> and <paramref name="length"/>) 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="length">A positive value indicating the number of characters to search starting from the position specified by <paramref name="startIndex" />.</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, int length, bool removeEmptyEntries = false, bool trim = false, bool keepSeparator = false) { var endIndex = ExceptionHelper.ForwardCheckStartIndexAndLength(startIndex, length, str.Length); return(new _innerSplitEnumerator02(str, separator, startIndex, endIndex, removeEmptyEntries, trim, keepSeparator)); }
/// <summary> /// Reports the zero-based index of the first occurrence of the specified <paramref name="value" /> outside quotes in this string. /// </summary> /// <param name="str">This string instance.</param> /// <param name="value">The substring to seek.</param> /// <param name="startIndex">The search starting position.</param> /// <param name="length">A positive value indicating the number of characters to search starting from the position specified by <paramref name="startIndex" />.</param> /// <param name="primaryLeftQuotes">Specifies an array of Unicode characters as the primary 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="primaryRightQuotes" />.</param> /// <param name="primaryRightQuotes">Specifies an array of Unicode characters as the primary 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="primaryLeftQuotes" />.</param> /// <param name="secondaryLeftQuotes">Specifies an array of Unicode characters as the secondary 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="secondaryRightQuotes" />. Secondary quotes are escaped when they are inside a pair of primary quotes.</param> /// <param name="secondaryRightQuotes">Specifies an array of Unicode characters as the secondary 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="secondaryLeftQuotes" />. Secondary quotes are escaped when they are inside a pair of primary quotes.</param> /// <param name="comparisonType">One of the enumeration values that specifies the rules for the search of <paramref name="value" />.</param> /// <returns> /// The zero-based index position of the first occurrence of <paramref name="value" /> if it is found outside quotes, or -1 if it is not. /// </returns> /// <exception cref="System.FormatException">Occurs when there is quote mismatch in the string instance.</exception> public static int IndexOfWithQuotes(this string str, string value, int startIndex, int length, char[] primaryLeftQuotes, char[] primaryRightQuotes, char[] secondaryLeftQuotes, char[] secondaryRightQuotes, StringComparison comparisonType = StringComparison.Ordinal) { var endIndex = ExceptionHelper.ForwardCheckStartIndexAndLength(startIndex, length, str.Length); return(_innerIndexOfWithQuotes(str, value, startIndex, endIndex, primaryLeftQuotes, primaryRightQuotes, secondaryLeftQuotes, secondaryRightQuotes, comparisonType)); }
/// <summary> /// Reports the zero-based index of the first occurrence of a Unicode character outside quotes and satisfying the specified predicate. /// </summary> /// <param name="str">This string instance.</param> /// <param name="predicate">A function to test each Unicode character outside quotes of the current string.</param> /// <param name="startIndex">The zero-based position indicating where the search for characters satisfying <paramref name="predicate" /> starts.</param> /// <param name="length">A positive value indicating the number of characters to search starting from the position specified by <paramref name="startIndex" />.</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> /// <returns> /// The zero-based index position of the first occurrence of <paramref name="value" /> if it is found outside quotes, or -1 if it is not. /// </returns> /// <exception cref="System.FormatException">Occurs when there is a quote mismatch in the string instance.</exception> public static int IndexOfWithQuotes(this string str, Func <char, bool> predicate, int startIndex, int length, char[] leftQuotes, char[] rightQuotes) { var endIndex = ExceptionHelper.ForwardCheckStartIndexAndLength(startIndex, length, str.Length); return(_innerIndexOfWithQuotes(str, predicate, startIndex, endIndex, leftQuotes, rightQuotes)); }
/// <summary> /// Returns a new string instance, with all occurrences of the specified substrings outside quotes replaced by a new value. /// </summary> /// <param name="str">This string instance.</param> /// <param name="oldValues">All occurrences of these substrings are to be replaced.</param> /// <param name="newValue">The new value to replace occurrences of <paramref name="oldValues" />.</param> /// <param name="startIndex">The zero-based position indicating where the search for <paramref name="oldValues" /> starts.</param> /// <param name="length">A positive value indicating the number of characters to search starting from the position specified by <paramref name="startIndex" />.</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="comparisonType">One of the enumeration values that specifies the rules for the search of <paramref name="oldValue"/>.</param> /// <returns> /// A new string instance with substrings replaced. /// </returns> /// <exception cref="System.FormatException">Occurs when there is a quote mismatch in the string instance.</exception> public static string ReplaceWithQuotes(this string str, string[] oldValues, string newValue, int startIndex, int length, char[] leftQuotes, char[] rightQuotes, StringComparison comparisonType = StringComparison.Ordinal) { var endIndex = ExceptionHelper.ForwardCheckStartIndexAndLength(startIndex, length, str.Length); return(_innerReplaceWithQuotes(str, oldValues, newValue, startIndex, endIndex, leftQuotes, rightQuotes, comparisonType)); }
/// <summary> /// Reports the index of the first character satisfying the specified predicate. /// The search starts at a specified character position and examines a specified number of character positions toward the end of this string instance. /// </summary> /// <param name="str">This string instance.</param> /// <param name="predicate">A function to test each character of the current string.</param> /// <param name="startIndex">The search starting position. The search proceeds from <paramref name="startIndex" /> toward the end of this instance.</param> /// <param name="count">The number of character positions to examine.</param> /// <returns> /// The zero-based index position of the first character in this instance satisfying the specified predicate. /// </returns> public static int IndexOf(this string str, Func <char, bool> predicate, int startIndex, int count) { var endIndex = ExceptionHelper.ForwardCheckStartIndexAndLength(startIndex, count, str.Length, "startIndex", "count"); return(_innerIndexOf(str, predicate, startIndex, endIndex)); }
/// <summary> /// Returns a new string instance, with all Unicode characters, which are outside quotes and satisfy the specified predicate, replaced by a new character. /// </summary> /// <param name="str">This string instance.</param> /// <param name="predicate">A function to test each Unicode character outside quotes of the current string.</param> /// <param name="newChar">The new character to replace those satisfying the predicate.</param> /// <param name="startIndex">The zero-based position indicating where the search for characters satisfying <paramref name="predicate" /> starts.</param> /// <param name="length">A positive value indicating the number of characters to search starting from the position specified by <paramref name="startIndex" />.</param> /// <param name="leftQuote">Specifies the Unicode character as the left quote.</param> /// <param name="rightQuote">Specifies the Unicode character as the right quote.</param> /// <returns> /// A new string instance with characters replaced. /// </returns> /// <exception cref="System.FormatException">Occurs when there is a quote mismatch in the string instance.</exception> public static string ReplaceWithQuotes(this string str, Func <char, bool> predicate, char newChar, int startIndex, int length, char leftQuote = '{', char rightQuote = '}') { var endIndex = ExceptionHelper.ForwardCheckStartIndexAndLength(startIndex, length, str.Length); return(_innerReplaceWithQuotes(str, predicate, newChar, startIndex, endIndex, leftQuote, rightQuote)); }
/// <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 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="length">A positive value indicating the number of characters to search starting from the position specified by <paramref name="startIndex" />.</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, int length, bool removeEmptyEntries = false, bool trim = false) { var endIndex = ExceptionHelper.ForwardCheckStartIndexAndLength(startIndex, length, str.Length); return(_innerGetSplitEnumerator(str, separators, startIndex, endIndex, removeEmptyEntries, trim)); }
/// <summary> /// Returns a new string instance, with all Unicode characters, which are outside quotes and satisfy the specified predicate, replaced by a new character. /// </summary> /// <param name="str">This string instance.</param> /// <param name="predicate">A function to test each Unicode character outside quotes of the current string.</param> /// <param name="newChar">The new character to replace those satisfying the predicate.</param> /// <param name="startIndex">The zero-based position indicating where the search for characters satisfying <paramref name="predicate" /> starts.</param> /// <param name="length">A positive value indicating the number of characters to search starting from the position specified by <paramref name="startIndex" />.</param> /// <param name="primaryLeftQuote">Specifies the Unicode character as the primary left quote.</param> /// <param name="primaryRightQuote">Specifies the Unicode character as the primary right quote.</param> /// <param name="secondaryLeftQuotes">Specifies an array of Unicode characters as the secondary 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="secondaryRightQuotes" />. Secondary quotes are escaped when they are inside a pair of primary quotes.</param> /// <param name="secondaryRightQuotes">Specifies an array of Unicode characters as the secondary 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="secondaryLeftQuotes" />. Secondary quotes are escaped when they are inside a pair of primary quotes.</param> /// <returns> /// A new string instance with characters replaced. /// </returns> /// <exception cref="System.FormatException">Occurs when there is a quote mismatch in the string instance.</exception> public static string ReplaceWithQuotes(this string str, Func <char, bool> predicate, char newChar, int startIndex, int length, char primaryLeftQuote, char primaryRightQuote, char[] secondaryLeftQuotes, char[] secondaryRightQuotes) { var endIndex = ExceptionHelper.ForwardCheckStartIndexAndLength(startIndex, length, str.Length); return(_innerReplaceWithQuotes(str, predicate, newChar, startIndex, endIndex, primaryLeftQuote, primaryRightQuote, secondaryLeftQuotes, secondaryRightQuotes)); }
/// <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"/> and <paramref name="length"/>) 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="length">A positive value indicating the number of characters to search starting from the position specified by <paramref name="startIndex" />.</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, int length, bool removeEmptyEntries = false, bool trim = false) { var endIndex = ExceptionHelper.ForwardCheckStartIndexAndLength(startIndex, length, str.Length); return(_innerGetDoubleSplitEnumerator(str, startIndex, endIndex, primaryPredicate, secondaryPredicate, removeEmptyEntries, trim)); }
/// <summary> /// Reports the zero-based index of the first occurrence of the specified <paramref name="value" /> outside quotes in this string. /// </summary> /// <param name="str">This string instance.</param> /// <param name="value">The substring to seek.</param> /// <param name="startIndex">The search starting position.</param> /// <param name="length">A positive value indicating the number of characters to search starting from the position specified by <paramref name="startIndex" />.</param> /// <param name="leftQuote">Specifies the Unicode character as the left quote.</param> /// <param name="rightQuote">Specifies the Unicode character as the right quote.</param> /// <param name="comparisonType">One of the enumeration values that specifies the rules for the search of <paramref name="value"/>.</param> /// <returns> /// The zero-based index position of the first occurrence of <paramref name="value" /> if it is found outside quotes, or -1 if it is not. /// </returns> /// <exception cref="System.FormatException">Occurs when there is quote mismatch in the string instance.</exception> public static int IndexOfWithQuotes(this string str, string value, int startIndex, int length, char leftQuote = '{', char rightQuote = '}', StringComparison comparisonType = StringComparison.Ordinal) { var endIndex = ExceptionHelper.ForwardCheckStartIndexAndLength(startIndex, length, str.Length); return(_innerIndexOfWithQuotes(str, value, startIndex, endIndex, leftQuote, rightQuote, comparisonType)); }