Пример #1
0
        /* Function: SetClassPrototypeParsingTypeBetween
         * Changes the <ClassPrototypeParsingType> of all the tokens between the two passed iterators.  The
         * token at the ending iterator will not be changed.
         */
        public void SetClassPrototypeParsingTypeBetween(TokenIterator startingIterator, TokenIterator endingIterator,
                                                        ClassPrototypeParsingType type)
        {
            if (startingIterator.Tokenizer != this || endingIterator.Tokenizer != this)
            {
                throw new InvalidOperationException();
            }

            SetClassPrototypeParsingTypeBetween(startingIterator.TokenIndex, endingIterator.TokenIndex, type);
        }
Пример #2
0
 /* Function: MatchesToken
  * Returns whether the current token matches the one at the passed iterator.  Returns false if either iterator
  * is out of bounds.
  */
 public bool MatchesToken(TokenIterator other, bool ignoreCase = false)
 {
     return(other.MatchesToken(this, ignoreCase));
 }
Пример #3
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.CurrentCultureIgnoreCase :
                                               StringComparison.CurrentCulture));

            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);
        }
Пример #4
0
        /* Function: FindTokenBetween
         * Attempts to find the passed string as a token between the two iterators, and set a <TokenIterator> at its position if successful.
         * The string must match the entire token, so "some" will not match "something".
         */
        public bool FindTokenBetween(string text, bool ignoreCase, TokenIterator start, TokenIterator end, out TokenIterator result)
        {
            TokenIterator findTokensBetweenResult;

            if (FindTokensBetween(text, ignoreCase, start, end, out findTokensBetweenResult) == false ||
                findTokensBetweenResult.RawTextLength != text.Length)
            {
                result = end;
                return(false);
            }
            else
            {
                result = findTokensBetweenResult;
                return(true);
            }
        }
Пример #5
0
        /* Function: EqualsTextBetween
         * Returns whether the text between the two iterators matches the passed string exactly.
         */
        public bool EqualsTextBetween(string searchText, bool ignoreCase, TokenIterator start, TokenIterator end)
        {
                        #if DEBUG
            if (start.Tokenizer != this || end.Tokenizer != this)
            {
                throw new InvalidOperationException();
            }
            if (!start.IsInBounds || start > end)
            {
                throw new ArgumentOutOfRangeException();
            }
                        #endif

            if (end.RawTextIndex - start.RawTextIndex != searchText.Length)
            {
                return(false);
            }

            StringComparison compareMode = (ignoreCase ? StringComparison.CurrentCultureIgnoreCase : StringComparison.CurrentCulture);
            return(rawText.IndexOf(searchText, start.RawTextIndex, end.RawTextIndex - start.RawTextIndex, compareMode) == start.RawTextIndex);
        }
Пример #6
0
        /* Function: MatchTextBetween
         * Runs the passed regular expression on the text between the two iterators and returns the result.
         */
        public Match MatchTextBetween(System.Text.RegularExpressions.Regex regex, TokenIterator start, TokenIterator end)
        {
                        #if DEBUG
            if (start.Tokenizer != this || end.Tokenizer != this)
            {
                throw new InvalidOperationException();
            }
            if (!start.IsInBounds || start > end)
            {
                throw new ArgumentOutOfRangeException();
            }
                        #endif

            return(regex.Match(rawText, start.RawTextIndex, end.RawTextIndex - start.RawTextIndex));
        }
Пример #7
0
        /* Function: ContainsTextBetween
         * Returns whether the text between the two iterators contains the passed string.
         */
        public bool ContainsTextBetween(string searchText, bool ignoreCase, TokenIterator start, TokenIterator end)
        {
                        #if DEBUG
            if (start.Tokenizer != this || end.Tokenizer != this)
            {
                throw new InvalidOperationException();
            }
            if (!start.IsInBounds || start > end)
            {
                throw new ArgumentOutOfRangeException();
            }
                        #endif

            StringComparison compareMode = (ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal);
            return(rawText.IndexOf(searchText, start.RawTextIndex, end.RawTextIndex - start.RawTextIndex, compareMode) != -1);
        }