Example #1
0
        /// <summary>
        /// Reports the index of the first occurance of the specified
        /// ParserBlock in the instance of the provided input string.
        /// </summary>
        /// <remarks>
        /// Note that this overload is generally provided to enable less extensive
        /// parameter-bound overloads of this operation.
        /// <para>Q:
        /// Hey Tom, why not just use a Regular Expression?
        /// </para>
        /// <para>Tom: I hadn't thought of it yet.  This <oblique>might</oblique> be faster then a compiled regular expression.</para>
        /// <para>Note that this method still depends on <see cref="String.IndexOf(string,int,int,StringComparison)" />, so the
        /// Exceptions and <see cref="System.Globalization.CultureInfo" /> handles just the same.</para>
        /// </remarks>
        /// <returns>
        /// <para>
        /// The Zero based position of value if that ParserBlock is found, or -1
        /// if not. If input is String.Empty, the return value is 0.
        /// </para>
        /// <para>
        /// Note that if textRangePositionIsZero is TRUE then our result value will be relative
        /// to the TextRange's offset (this.Position is zero) within the input and not the input
        /// string's starting point.
        /// </para>
        /// </returns>
        /// <param name="value">ParserBlock providing 'Start' and 'End' criterium to index.</param>
        /// <param name="input">the string to seek.</param>
        /// <param name="startIndex">The search starting position.</param>
        /// <param name="count">the number of character positions to examine.</param>
        /// <param name="comparisonType">One of the <see cref="System.StringComparison" /> values.</param>
        /// <param name="textRangePositionIsZero">
        /// If TRUE, then <tt>Position = 0</tt> where Offset/Position of this textrange
        /// within the provided input String is treated as Zero.
        /// <para>
        /// A value of FALSE will provide the actual offsets with respect to the input string.
        /// </para>
        /// </param>
        /// <exception cref="System.ArgumentNullException">
        /// input is null.
        /// </exception>
        /// <exception cref="System.ArgumentOutOfRangeException">
        /// count or startIndex is negative. -or- count plus startIndex specify a position not within this instance.
        /// </exception>
        /// <exception cref="System.ArgumentException">
        /// comparisonType is not a valid System.StringComparison value.
        /// </exception>
        public int IndexOf(ParserBlock value, string input, int startIndex, int count, StringComparison comparisonType, bool textRangePositionIsZero)
        {
//			string toMatch = this.Substring(input);
            int indexOfA = input.IndexOf(value.BlockBegin, startIndex, count, comparisonType);
            int indexOfB = input.IndexOf(value.BlockEnd, startIndex, count, comparisonType);
//			toMatch = null;
            bool hasIndexA = indexOfA > -1, hasIndexB = indexOfB > -1;

            if (hasIndexA && hasIndexB)
            {
                if (indexOfA < indexOfB)
                {
                    return(textRangePositionIsZero ? indexOfA : indexOfA + this.Position32);
                }
                else
                {
                    return(textRangePositionIsZero ? indexOfB : indexOfB + this.Position32);
                }
            }
            else if (hasIndexA && !hasIndexB)
            {
                return(textRangePositionIsZero ? indexOfA : indexOfA + this.Position32);
            }
            else if (!hasIndexA && hasIndexB)
            {
                return(textRangePositionIsZero ? indexOfB : indexOfB + this.Position32);
            }
            return(-1);
        }
Example #2
0
 /// <summary>
 /// Reports the index of the first occurance of the specified
 /// ParserBlock in the instance of the provided input string.
 /// </summary>
 /// <remarks>
 /// Note that this overload is generally provided to enable less extensive
 /// parameter-bound overloads of this operation.
 /// <para>Q:
 /// Hey Tom, why not just use a Regular Expression?
 /// </para>
 /// <para>Tom: I hadn't thought of it yet.  This <oblique>might</oblique> be faster then a compiled regular expression.</para>
 /// <para>Note that this method still depends on <see cref="String.IndexOf(string,int,int,StringComparison)" />, so the
 /// Exceptions and <see cref="System.Globalization.CultureInfo" /> handles just the same.</para>
 /// </remarks>
 /// <returns>
 /// <para>
 /// The Zero based position of value if that ParserBlock is found, or -1
 /// if not. If input is String.Empty, the return value is 0.
 /// </para>
 /// <para>
 /// Note that if textRangePositionIsZero is TRUE then our result value will be relative
 /// to the TextRange's offset (this.Position is zero) within the input and not the input
 /// string's starting point.
 /// </para>
 /// </returns>
 /// <param name="value">ParserBlock providing 'Start' and 'End' criterium to index.</param>
 /// <param name="input">the string to seek.</param>
 /// <param name="comparisonType">One of the <see cref="System.StringComparison" /> values.</param>
 /// <param name="textRangePositionIsZero">
 /// If TRUE, then <tt>Position = 0</tt> where Offset/Position of this textrange
 /// within the provided input String is treated as Zero.
 /// <para>
 /// A value of FALSE will provide the actual offsets with respect to the input string.
 /// </para>
 /// </param>
 /// <exception cref="System.ArgumentNullException">
 /// input is null.
 /// </exception>
 /// <exception cref="System.ArgumentOutOfRangeException">startindex being provided by the TextRange.Position
 /// -count- being provided by TextRange.Length.
 /// Count or startIndex is negative. -or- count plus startIndex specify a position not within this instance.
 /// </exception>
 /// <exception cref="System.ArgumentException">
 /// comparisonType is not a valid System.StringComparison value.
 /// </exception>
 public int IndexOf(ParserBlock value, string input, StringComparison comparisonType, bool textRangePositionIsZero)
 {
     return(this.IndexOf(value, input, this.Position32, this.Length32, comparisonType, textRangePositionIsZero));
 }
Example #3
0
 /// <summary>
 /// See <see cref="IndexOf(ParserBlock,string,int,int,System.StringComparison,bool)" /> for documentation.
 /// </summary>
 /// <param name="value"></param>
 /// <param name="input"></param>
 /// <param name="startIndex"></param>
 /// <param name="count"></param>
 /// <param name="textRangePositionIsZero"></param>
 /// <returns></returns>
 public int IndexOf(ParserBlock value, string input, int startIndex, int count, bool textRangePositionIsZero)
 {
     return(this.IndexOf(value, input, startIndex, count, System.StringComparison.InvariantCulture, textRangePositionIsZero));
 }
Example #4
0
 /// <summary>
 /// See the main main <see cref="IndexOf(ParserBlock,string,int,int,System.StringComparison,bool)">IndexOf</see>
 /// overload for full reference.<br />
 /// <see cref="System.StringComparison" /> = StringComparison.InvarientCulture by default.
 /// </summary>
 /// <returns>
 /// <para>
 /// The Zero based position of value if that ParserBlock is found, or -1
 /// if not. If input is String.Empty, the return value is 0.
 /// </para>
 /// <para>
 /// Note that if textRangePositionIsZero is TRUE then our result value will be relative
 /// to the TextRange's offset (this.Position is zero) within the input and not the input
 /// string's starting point.
 /// </para>
 /// </returns>
 /// <param name="value"></param>
 /// <param name="input">The string being searched.
 /// Note that a section within the string is searched using this TextRange.Position, which is rarely zero.
 /// </param>
 /// <param name="textRangePositionIsZero">(To be used with caution) See overloads.</param>
 public int IndexOf(ParserBlock value, string input, bool textRangePositionIsZero)
 {
     return(this.IndexOf(value, input, this.Position32, this.Length32, System.StringComparison.InvariantCulture, textRangePositionIsZero));
 }