/// <summary>
        /// Parses the string and updates the state accordingly.
        /// </summary>
        /// <param name="input">The text to process.</param>
        /// <returns>The text, ready for formatting.</returns>
        /// This method modifies the text because it removes some
        /// syntax stuff. Maybe the states themselves should handle
        /// their own syntax and remove it?
        private string HandleFormattingState(string input, string inputLookAhead)
        {
            // Find an appropriate formatter state.
            Match match;
            Match lookAheadMatch;
            Type  type = GetCandidateFormatterStateType(input, inputLookAhead, out match, out lookAheadMatch);

            // Got it! Apply it.
            if (type != null)
            {
                FormatterState formatterState = (FormatterState)Activator.CreateInstance(type);
                formatterState.Formatter = this;
                FormatterStateConsumeContext context = new FormatterStateConsumeContext(input, inputLookAhead, match, lookAheadMatch);
                return(formatterState.Consume(context));    // This may or may not change the current state.
            }

            // Default, when no block is specified, we ask the current state, or
            // use the default state.
            if (CurrentState != null)
            {
                if (CurrentState.FallbackFormattingState != null)
                {
                    ChangeState(CurrentState.FallbackFormattingState);
                }
                // else, the current state doesn't want to be superceded by
                // a new one. We'll leave him be.
            }
            else
            {
                ChangeState(m_defaultFormatterStateType);
            }
            return(input);
        }
Esempio n. 2
0
        /// <summary>
        /// Parses the string and updates the state accordingly.
        /// </summary>
        /// <param name="input">The text to process.</param>
        /// <returns>The text, ready for formatting.</returns>
        /// This method modifies the text because it removes some
        /// syntax stuff. Maybe the states themselves should handle
        /// their own syntax and remove it?
        private string HandleFormattingState(string input, string inputLookAhead)
        {
            // Find an appropriate formatter state.
            Match match;
            Match lookAheadMatch;
            Type  type = GetCandidateFormatterStateType(input, inputLookAhead, out match, out lookAheadMatch);

            // Got it! Apply it.
            if (type != null)
            {
                FormatterState formatterState = (FormatterState)Activator.CreateInstance(type);
                formatterState.Formatter = this;
                FormatterStateConsumeContext context = new FormatterStateConsumeContext(input, inputLookAhead, match, lookAheadMatch);
                return(formatterState.Consume(context));    // This may or may not change the current state.
            }

            StateManager.Fallback();

            return(input);
        }
Esempio n. 3
0
 public abstract string Consume(FormatterStateConsumeContext context);