コード例 #1
0
        private static bool IsValidAbbreviation(string match, StringSlice content, int matchIndex)
        {
            // The word matched must be embraced by punctuation or whitespace or \0.
            var index = matchIndex - 1;

            while (index >= content.Start)
            {
                var c = content.PeekCharAbsolute(index);
                if (!(c == '\0' || c.IsAsciiPunctuation() || c.IsWhitespace()))
                {
                    return(false);
                }
                if (!c.IsAsciiPunctuation())
                {
                    break;
                }
                index--;
            }
            index = matchIndex + match.Length;
            while (index <= content.End)
            {
                var c = content.PeekCharAbsolute(index);
                if (!(c == '\0' || c.IsAsciiPunctuation() || c.IsWhitespace()))
                {
                    return(false);
                }
                if (!c.IsAsciiPunctuation())
                {
                    break;
                }
                index++;
            }
            return(true);
        }
コード例 #2
0
        private static bool IsValidAbbreviation(string match, StringSlice content, int matchIndex)
        {
            // The word matched must be embraced by punctuation or whitespace or \0.
            var index = matchIndex - 1;

            while (index >= content.Start)
            {
                var c = content.PeekCharAbsolute(index);
                if (!(c == '\0' || c.IsWhitespace() || c.IsAsciiPunctuation()))
                {
                    return(false);
                }

                if (c.IsAlphaNumeric())
                {
                    return(false);
                }

                if (!c.IsAsciiPunctuation() || c.IsWhitespace())
                {
                    break;
                }
                index--;
            }

            // This will check if the next char at the end of the StringSlice is whitespace, punctuation or \0.
            var contentNew = content;

            contentNew.End = content.End + 1;
            index          = matchIndex + match.Length;
            while (index <= contentNew.End)
            {
                var c = contentNew.PeekCharAbsolute(index);
                if (!(c == '\0' || c.IsWhitespace() || c.IsAsciiPunctuation()))
                {
                    return(false);
                }

                if (c.IsAlphaNumeric())
                {
                    return(false);
                }

                if (c.IsWhitespace())
                {
                    break;
                }
                index++;
            }
            return(true);
        }
コード例 #3
0
        /// <summary>
        /// Unwind any previous indent from the current character back to the first space.
        /// </summary>
        public void UnwindAllIndents()
        {
            // Find the previous first space on the current line
            var previousStart = Line.Start;

            for (; Line.Start > originalLineStart; Line.Start--)
            {
                var c = Line.PeekCharAbsolute(Line.Start - 1);

                // don't unwind all the way next to a '>', but one space right of the '>' if there is a space
                if (TrackTrivia && SkipFirstUnwindSpace && Line.Start == TriviaStart)
                {
                    break;
                }
                if (c == 0)
                {
                    break;
                }
                if (!c.IsSpaceOrTab())
                {
                    break;
                }
            }
            var targetStart = Line.Start;

            // Nothing changed? Early exit
            if (previousStart == targetStart)
            {
                return;
            }

            // TODO: factorize the following code with what is done with GoToColumn

            // If we have found the first space, we need to recalculate the correct column
            Line.Start         = originalLineStart;
            Column             = 0;
            ColumnBeforeIndent = 0;
            StartBeforeIndent  = originalLineStart;

            for (; Line.Start < targetStart; Line.Start++)
            {
                var c = Line.Text[Line.Start];
                if (c == '\t')
                {
                    Column = CharHelper.AddTab(Column);
                }
                else
                {
                    if (!c.IsSpaceOrTab())
                    {
                        ColumnBeforeIndent = Column + 1;
                        StartBeforeIndent  = Line.Start + 1;
                    }

                    Column++;
                }
            }

            // Reset the indent
            ColumnBeforeIndent = Column;
            StartBeforeIndent  = Start;
        }