コード例 #1
0
        /// <summary>
        /// Returns the last non-whitespace position on the given line, or null if
        /// the line is empty or contains only whitespace.
        /// </summary>
        public static int?GetLastNonWhitespacePosition(this ITextSnapshotLine line)
        {
            var startPosition = line.Start;
            var text          = line.ToString();

            for (var i = text.Length - 1; i >= 0; i--)
            {
                if (!char.IsWhiteSpace(text[i]))
                {
                    return(startPosition + i);
                }
            }

            return(null);
        }