Пример #1
0
        /* Function: FindTokensBetween
         * Attempts to find the passed string between the two iterators, and sets a <TokenIterator> at its position if successful.  This
         * function can cross token boundaries, so you can search for "<<" even though that would normally be two tokens.  The result
         * must match complete tokens though, so "<< some" will not match "<< something".
         */
        public bool FindTokensBetween(string text, bool ignoreCase, TokenIterator start, TokenIterator end, out TokenIterator result)
        {
            if (!start.IsInBounds || start > end)
            {
                result = end;
                return(false);
            }

            int resultIndex = rawText.IndexOf(text, start.RawTextIndex, end.RawTextIndex - start.RawTextIndex,
                                              (ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal));

            if (resultIndex == -1)
            {
                result = end;
                return(false);
            }

            result = start;

            // Do this instead of NextByCharacters() so we don't cause an exception if it's not on a token boundary.
            while (result.RawTextIndex < resultIndex)
            {
                result.Next();
            }

            if (result.RawTextIndex != resultIndex)
            {
                result = end;
                return(false);
            }

            return(true);
        }
Пример #2
0
        /* Function: FindAcrossTokens
         * Attempts to find the passed string in the line, and sets a <TokenIterator> at its position if successful.  This function
         * can cross token boundaries, so you can search for "<<" even though that would normally be two tokens.  The result
         * must match complete tokens though, so "<< some" will not match "<< something".
         */
        public bool FindAcrossTokens(string text, bool ignoreCase, LineBoundsMode boundsMode, out TokenIterator result)
        {
            if (!IsInBounds)
            {
                result = new TokenIterator();
                return(false);
            }

            int rawTextStart, rawTextEnd, tokenStart, tokenEnd;

            CalculateBounds(boundsMode, out rawTextStart, out rawTextEnd, out tokenStart, out tokenEnd);

            int resultIndex = tokenizer.RawText.IndexOf(text, rawTextStart, rawTextEnd - rawTextStart,
                                                        (ignoreCase ? StringComparison.CurrentCultureIgnoreCase :
                                                         StringComparison.CurrentCulture));

            if (resultIndex == -1)
            {
                result = new TokenIterator();
                return(false);
            }

            result = new TokenIterator(tokenizer, tokenStart, rawTextStart, LineNumber);

            // Do this instead of NextByCharacters() so we don't cause an exception if it's not on a token boundary.
            while (result.RawTextIndex < resultIndex)
            {
                result.Next();
            }

            if (result.RawTextIndex != resultIndex)
            {
                result = new TokenIterator();
                return(false);
            }

            return(true);
        }
Пример #3
0
        /* Function: SetClassPrototypeParsingTypeByCharacters
         *
         * Changes the <ClassPrototypeParsingType> of the tokens encompassed by the passed number of characters.
         *
         * This throws an exception if the number of characters does not evenly fall on a token boundary.  It
         * is assumed that this function will primarily be used after a positive result from <MatchesAcrossTokens()>
         * or <TokensInCharacters()> which would cause this to not be an issue.
         */
        public void SetClassPrototypeParsingTypeByCharacters(ClassPrototypeParsingType newType, int characters)
        {
            int tokenCount = TokensInCharacters(characters);

            if (tokenCount == -1)
            {
                throw new InvalidOperationException();
            }
            else if (tokenCount == 1)
            {
                ClassPrototypeParsingType = newType;
            }
            else
            {
                TokenIterator iterator = this;

                while (tokenCount > 0)
                {
                    iterator.ClassPrototypeParsingType = newType;
                    iterator.Next();
                    tokenCount--;
                }
            }
        }
Пример #4
0
        /* Function: SetSyntaxHighlightingTypeByCharacters
         *
         * Changes the <SyntaxHighlightingType> of the tokens encompassed by the passed number of characters.
         *
         * This throws an exception if the number of characters does not evenly fall on a token boundary.  It
         * is assumed that this function will primarily be used after a positive result from <MatchesAcrossTokens()>
         * or <TokensInCharacters()> which would cause this to not be an issue.
         */
        public void SetSyntaxHighlightingTypeByCharacters(SyntaxHighlightingType newType, int characters)
        {
            int tokenCount = TokensInCharacters(characters);

            if (tokenCount == -1)
            {
                throw new InvalidOperationException();
            }
            else if (tokenCount == 1)
            {
                SyntaxHighlightingType = newType;
            }
            else
            {
                TokenIterator iterator = this;

                while (tokenCount > 0)
                {
                    iterator.SyntaxHighlightingType = newType;
                    iterator.Next();
                    tokenCount--;
                }
            }
        }