Exemplo n.º 1
0
        public MediaQuerySegment(IProcessCharacters characterProcessorToReturnTo)
        {
            if (characterProcessorToReturnTo == null)
            {
                throw new ArgumentNullException("characterProcessorToReturnTo");
            }

            _characterProcessorToReturnTo = characterProcessorToReturnTo;
        }
Exemplo n.º 2
0
        /// <summary>
        /// If this next work from the current point in the given string navigator appears to be a recognised pseudo class then this will return a result that
        /// will ensure that the current character is identified as a selector-or-property-name content rather than a property-name-value-separator colon (the
        /// string navigator passed here will be for the position directly after the colon, which is what is currently being negotiated). Any whitespace at
        /// the current position will be moved over when looking for pseudo class content. If the content does not appear to be for a pseudo class then null
        /// will be returned and the caller may continue with whatever logic it wants to.
        /// </summary>
        private CharacterProcessorResult GetPseudoClassHandlingProcessResultIfApplicable(IWalkThroughStrings stringNavigatorAtStartOfPotentialPseudoClass)
        {
            if (stringNavigatorAtStartOfPotentialPseudoClass == null)
            {
                throw new ArgumentNullException("stringNavigator");
            }

            // If the first character of the possible-psuedo-class content is a ":" then it means that we've encountered a "::" (since the first ":" triggered
            // this method to be called with the content after it) and that means that it's definitely a psuedo class and not a property name / value pair. As
            // such we'll return a process that swallows this second ":" and then processes the next content as selector-or-style-content (and not as property
            // name content)
            if (stringNavigatorAtStartOfPotentialPseudoClass.CurrentCharacter == ':')
            {
                var contentProcessor = GetSelectorOrStyleCharacterProcessor();
                return(new CharacterProcessorResult(
                           CharacterCategorisationOptions.SelectorOrStyleProperty,
                           new SkipCharactersSegment(CharacterCategorisationOptions.SelectorOrStyleProperty, 1, GetSelectorOrStyleCharacterProcessor())
                           ));
            }

            // Skip over any whitespace to find the start of the next content
            var whiteSpaceCharactersToSkipOver = 0;

            while (true)
            {
                var character = stringNavigatorAtStartOfPotentialPseudoClass.CurrentCharacter;
                if ((character == null) || !char.IsWhiteSpace(character.Value))
                {
                    break;
                }
                stringNavigatorAtStartOfPotentialPseudoClass = stringNavigatorAtStartOfPotentialPseudoClass.Next;
                whiteSpaceCharactersToSkipOver++;
            }

            // Determine whether that content (if there is any) matches any of the pseudo classes
            if (PseudoClasses.Any(c => stringNavigatorAtStartOfPotentialPseudoClass.DoesCurrentContentMatch(c)))
            {
                IProcessCharacters contentProcessor = GetSelectorOrStyleCharacterProcessor();
                if (whiteSpaceCharactersToSkipOver > 0)
                {
                    contentProcessor = new SkipCharactersSegment(CharacterCategorisationOptions.Whitespace, whiteSpaceCharactersToSkipOver, contentProcessor);
                }
                return(new CharacterProcessorResult(
                           CharacterCategorisationOptions.SelectorOrStyleProperty,
                           contentProcessor
                           ));
            }

            return(null);
        }
Exemplo n.º 3
0
        public MultiLineCommentSegment(IProcessCharacters characterProcessorToReturnTo, IGenerateCharacterProcessors processorFactory)
        {
            if (processorFactory == null)
            {
                throw new ArgumentNullException("processorFactory");
            }
            if (characterProcessorToReturnTo == null)
            {
                throw new ArgumentNullException("characterProcessorToReturnTo");
            }

            _processorFactory             = processorFactory;
            _characterProcessorToReturnTo = characterProcessorToReturnTo;
        }
Exemplo n.º 4
0
 public BracketedSelectorSegment(
     SingleLineCommentsSupportOptions singleLineCommentsSupportOptions,
     char closeBracketCharacter,
     IProcessCharacters characterProcessorToReturnTo,
     IGenerateCharacterProcessors processorFactory)
     : base(
         ProcessingTypeOptions.StyleOrSelector,
         singleLineCommentsSupportOptions,
         new CharacterCategorisationBehaviourOverride(
             closeBracketCharacter,
             CharacterCategorisationOptions.SelectorOrStyleProperty,
             characterProcessorToReturnTo
             ),
         processorFactory
         )
 {
 }
Exemplo n.º 5
0
            public CharacterCategorisationBehaviourOverride(
                char endOfBehaviourOverrideCharacter,
                CharacterCategorisationOptions characterCategorisation,
                IProcessCharacters characterProcessorToReturnTo)
            {
                if (!Enum.IsDefined(typeof(CharacterCategorisationOptions), characterCategorisation))
                {
                    throw new ArgumentOutOfRangeException("characterCategorisation");
                }
                if (characterProcessorToReturnTo == null)
                {
                    throw new ArgumentNullException("characterProcessorToReturnTo");
                }

                EndOfBehaviourOverrideCharacter = endOfBehaviourOverrideCharacter;
                CharacterCategorisation         = characterCategorisation;
                CharacterProcessorToReturnTo    = characterProcessorToReturnTo;
            }
        public CharacterProcessorResult(CharacterCategorisationOptions characterCategorisation, IProcessCharacters nextProcessor)
        {
            if ((characterCategorisation != CharacterCategorisationOptions.CloseBrace) &&
                (characterCategorisation != CharacterCategorisationOptions.Comment) &&
                (characterCategorisation != CharacterCategorisationOptions.OpenBrace) &&
                (characterCategorisation != CharacterCategorisationOptions.SemiColon) &&
                (characterCategorisation != CharacterCategorisationOptions.SelectorOrStyleProperty) &&
                (characterCategorisation != CharacterCategorisationOptions.StylePropertyColon) &&
                (characterCategorisation != CharacterCategorisationOptions.Value) &&
                (characterCategorisation != CharacterCategorisationOptions.Whitespace))
            {
                throw new ArgumentOutOfRangeException("characterCategorisation");
            }
            if (nextProcessor == null)
            {
                throw new ArgumentNullException("nextProcessor");
            }

            CharacterCategorisation = characterCategorisation;
            NextProcessor           = nextProcessor;
        }
Exemplo n.º 7
0
        public SkipCharactersSegment(
            CharacterCategorisationOptions characterCategorisation,
            int numberOfCharactersToSkip,
            IProcessCharacters characterProcessorToReturnTo)
        {
            if (!Enum.IsDefined(typeof(CharacterCategorisationOptions), characterCategorisation))
            {
                throw new ArgumentOutOfRangeException("characterCategorisation");
            }
            if (numberOfCharactersToSkip <= 0)
            {
                throw new ArgumentOutOfRangeException("numberOfCharactersToSkip", "must be greater than zero");
            }
            if (characterProcessorToReturnTo == null)
            {
                throw new ArgumentNullException("characterProcessorToReturnTo");
            }

            CharacterCategorisation       = characterCategorisation;
            NumberOfCharactersToSkip      = numberOfCharactersToSkip;
            _characterProcessorToReturnTo = characterProcessorToReturnTo;
        }
Exemplo n.º 8
0
        public QuotedSegment(
            char quoteCharacter,
            CharacterCategorisationOptions characterCategorisation,
            IProcessCharacters characterProcessorToReturnTo,
            IGenerateCharacterProcessors processorFactory)
        {
            if (characterProcessorToReturnTo == null)
            {
                throw new ArgumentNullException("characterProcessorToReturnTo");
            }
            if (!Enum.IsDefined(typeof(CharacterCategorisationOptions), characterCategorisation))
            {
                throw new ArgumentOutOfRangeException("characterCategorisation");
            }
            if (processorFactory == null)
            {
                throw new ArgumentNullException("processorFactory");
            }

            _quoteCharacter               = quoteCharacter;
            _characterCategorisation      = characterCategorisation;
            _characterProcessorToReturnTo = characterProcessorToReturnTo;
            _processorFactory             = processorFactory;
        }
Exemplo n.º 9
0
        /// <summary>
        /// This will never return null nor a set containing any null references. It will throw an exception for null contentWalker or contentProcessor
        /// references or it the processing failed.
        /// </summary>
        public IEnumerable <CategorisedCharacterString> GetStrings(IWalkThroughStrings contentWalker, IProcessCharacters contentProcessor)
        {
            if (contentWalker == null)
            {
                throw new ArgumentNullException("contentWalker");
            }
            if (contentProcessor == null)
            {
                throw new ArgumentNullException("contentProcessor");
            }

            // It doesn'actually matter what the initial value of currentCharacterType is since it won't be used until there is string content
            // to record, and by that point it will have been assigned a value
            var currentCharacterType  = CharacterCategorisationOptions.SelectorOrStyleProperty;
            var stringBuilder         = new StringBuilder();
            var currentCharacterIndex = 0;

            while (true)
            {
                var character = contentWalker.CurrentCharacter;
                if (character == null)
                {
                    break;
                }

                // CloseBrace, OpenBrace and SemiColons constitute "CharacterTypesToNotGroup"
                var processResult = contentProcessor.Process(contentWalker);
                if ((processResult.CharacterCategorisation != currentCharacterType) ||
                    (processResult.CharacterCategorisation == CharacterCategorisationOptions.CloseBrace) ||
                    (processResult.CharacterCategorisation == CharacterCategorisationOptions.OpenBrace) ||
                    (processResult.CharacterCategorisation == CharacterCategorisationOptions.SemiColon))
                {
                    if (stringBuilder.Length > 0)
                    {
                        var value = stringBuilder.ToString();
                        yield return(new CategorisedCharacterString(value, currentCharacterIndex - value.Length, currentCharacterType));

                        stringBuilder.Clear();
                    }
                    currentCharacterType = processResult.CharacterCategorisation;
                }
                stringBuilder.Append(character);

                contentProcessor = processResult.NextProcessor;
                contentWalker    = contentWalker.Next;
                currentCharacterIndex++;
            }
            if (stringBuilder.Length > 0)
            {
                var value = stringBuilder.ToString();
                yield return(new CategorisedCharacterString(value, currentCharacterIndex - value.Length, currentCharacterType));
            }
        }