Exemple #1
0
        /// <summary>
        /// Joins the two given points.
        /// </summary>
        /// <param name="point1">The first point to join.</param>
        /// <param name="point2">The second point to join.</param>
        /// <returns>Returns the joined <see cref="CodePoint"/>.</returns>
        public static CodePoint Join(CodePoint point1, CodePoint point2)
        {
            if (point1.lineNumber == 0 && point1.indexOnLine == 0 && point1.index == 0)
            {
                return(point2);
            }

            if (point2.lineNumber == 0 && point2.indexOnLine == 0 && point2.index == 0)
            {
                return(point1);
            }

            // Figure out which IndexOnLine to use.
            int indexOnLine;

            if (point1.LineNumber == point2.LineNumber)
            {
                indexOnLine = Math.Min(point1.IndexOnLine, point2.IndexOnLine);
            }
            else if (point1.LineNumber < point2.LineNumber)
            {
                indexOnLine = point1.IndexOnLine;
            }
            else
            {
                indexOnLine = point2.IndexOnLine;
            }

            return(new CodePoint(Math.Min(point1.Index, point2.Index), indexOnLine, Math.Min(point1.LineNumber, point2.LineNumber)));
        }
Exemple #2
0
        public CodeLocation(int index, int endIndex, int indexOnLine, int endIndexOnLine, int lineNumber, int endLineNumber)
        {
            Param.RequireGreaterThanOrEqualToZero(index, "index");
            Param.RequireGreaterThanOrEqualTo(endIndex, index, "endIndex");
            Param.RequireGreaterThanOrEqualToZero(indexOnLine, "indexOnLine");
            Param.RequireGreaterThanOrEqualToZero(endIndexOnLine, "endIndexOnLine");
            Param.RequireGreaterThanZero(lineNumber, "lineNumber");
            Param.RequireGreaterThanOrEqualTo(endLineNumber, lineNumber, "endLineNumber");

#if DEBUG
            // If the entire segment is on the same line, make sure the end index is greater or equal to the start index.
            if (lineNumber == endLineNumber)
            {
                Debug.Assert(endIndexOnLine >= indexOnLine, "The end index must be greater than the start index, since they are both on the same line.");
            }
#endif

            this.startPoint = new CodePoint(index, indexOnLine, lineNumber);
            this.endPoint   = new CodePoint(endIndex, endIndexOnLine, endLineNumber);
        }
Exemple #3
0
        /// <summary>
        /// Joins the two given points.
        /// </summary>
        /// <param name="point1">The first point to join.</param>
        /// <param name="point2">The second point to join.</param>
        /// <returns>Returns the joined <see cref="CodePoint"/>.</returns>
        public static CodePoint Join(CodePoint point1, CodePoint point2)
        {
            if (point1.lineNumber == 0 && point1.indexOnLine == 0 && point1.index == 0)
            {
                return point2;
            }

            if (point2.lineNumber == 0 && point2.indexOnLine == 0 && point2.index == 0)
            {
                return point1;
            }

            // Figure out which IndexOnLine to use.
            int indexOnLine;
            if (point1.LineNumber == point2.LineNumber)
            {
                indexOnLine = Math.Min(point1.IndexOnLine, point2.IndexOnLine);
            }
            else if (point1.LineNumber < point2.LineNumber)
            {
                indexOnLine = point1.IndexOnLine;
            }
            else
            {
                indexOnLine = point2.IndexOnLine;
            }

            return new CodePoint(Math.Min(point1.Index, point2.Index), indexOnLine, Math.Min(point1.LineNumber, point2.LineNumber));
        }
        public CodeLocation(int index, int endIndex, int indexOnLine, int endIndexOnLine, int lineNumber, int endLineNumber)
        {
            Param.RequireGreaterThanOrEqualToZero(index, "index");
            Param.RequireGreaterThanOrEqualTo(endIndex, index, "endIndex");
            Param.RequireGreaterThanOrEqualToZero(indexOnLine, "indexOnLine");
            Param.RequireGreaterThanOrEqualToZero(endIndexOnLine, "endIndexOnLine");
            Param.RequireGreaterThanZero(lineNumber, "lineNumber");
            Param.RequireGreaterThanOrEqualTo(endLineNumber, lineNumber, "endLineNumber");

#if DEBUG
            // If the entire segment is on the same line, make sure the end index is greater or equal to the start index.
            if (lineNumber == endLineNumber)
            {
                Debug.Assert(endIndexOnLine >= indexOnLine, "The end index must be greater than the start index, since they are both on the same line.");
            }
#endif

            this.startPoint = new CodePoint(index, indexOnLine, lineNumber);
            this.endPoint = new CodePoint(endIndex, endIndexOnLine, endLineNumber);
        }