public static int GetLineIndex( this LinePosition linePosition, LineBuffer lineBuffer, LinePositionOptions options = LinePositionOptions.None) { int lineIndex = linePosition.GetLineIndex(lineBuffer.LineCount, options); return(lineIndex); }
/// <summary> /// Translates the magic values (End, Beginning) into actual values based /// on the given count. /// </summary> /// <param name="count">The number of items in the current collection.</param> /// <returns>The normalized index.</returns> /// <exception cref="System.IndexOutOfRangeException">Encountered an invalid index: + Index</exception> public int GetLineIndex( int count, LinePositionOptions options = LinePositionOptions.None) { // All the magic values are negative, so if we don't have one, there is // nothing to do. if (Index >= 0) { // If we are beyond the string, throw an exception. if (Index >= count) { // If we aren't doing bound checking, then we just return // the end of the buffer. if (options.HasFlag(LinePositionOptions.NoBoundsChecking)) { return(count - 1); } // We have bounds checking, so throw an exception. throw new IndexOutOfRangeException( string.Format("Line position {0} is beyond line count {1}.", Index, count)); } return(Index); } // If we have the end magic number, then the index is equal to the end // of the text line. if (Index == End.Index) { return(count - 1); } // If we got this far, then we have an invalid value. if (options.HasFlag(LinePositionOptions.NoBoundsChecking)) { return(0); } // We don't know how to process this, so throw an exception. throw new IndexOutOfRangeException("Encountered an invalid index: " + Index); }