예제 #1
0
        // Append a string to the output buffer
        public void Append(string val)
        {
            if (string.IsNullOrEmpty(val))
            {
                return;
            }

            // Check if we need to insert a space for NeedSpaceIf()
            if (m_chNeedSpaceIf != '\0')
            {
                if (val.Length > 0 && val[0] == m_chNeedSpaceIf)
                {
                    m_chNeedSpaceIf = '\0';
                    AppendInternal(" ");
                }
                else
                {
                    m_chNeedSpaceIf = '\0';
                }
            }

            // Do we need a space?
            if (Tokenizer.IsIdentifierChar(m_chLast) && Tokenizer.IsIdentifierChar(val[0]))
            {
                AppendInternal(" ");
            }

            // Track the line position and append the text
            AppendInternal(val);

            // Auto enable line breaks?
            if (m_bEnableLineBreaksAfterNextWrite)
            {
                m_bEnableLineBreaksAfterNextWrite = false;
                EnableLineBreaks();
            }
        }
예제 #2
0
        public bool Parse(StringScanner s)
        {
            // Can't be empty
            if (s.eof)
            {
                return(false);
            }

            // Regex?
            if (s.current == '/')
            {
                s.SkipForward(1);
                s.Mark();

                while (s.current != '/')
                {
                    if (s.eof)
                    {
                        return(false);
                    }

                    if (s.current == '\\')
                    {
                        s.SkipForward(2);
                    }
                    else
                    {
                        s.SkipForward(1);
                    }
                }

                try
                {
                    m_regex = new System.Text.RegularExpressions.Regex(s.Extract());
                    s.SkipForward(1);
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }

            // Wildcard or explicit
            bool bWildcard = false;
            bool bLeading  = true;

            s.Mark();
            while (!s.eof && s.current != '.')
            {
                // Wildcard?
                if (s.current == '?' || s.current == '*')
                {
                    bWildcard = true;
                    s.SkipForward(1);
                    bLeading = false;
                    continue;
                }

                // Valid identifier character?
                if (bLeading)
                {
                    if (!Tokenizer.IsIdentifierLeadChar(s.current))
                    {
                        return(false);
                    }
                }
                else
                {
                    if (!Tokenizer.IsIdentifierChar(s.current))
                    {
                        return(false);
                    }
                }

                // Next
                s.SkipForward(1);

                bLeading = false;
            }

            // Extract it
            string str = s.Extract();

            // If it ends with an asterix, it's a wildcard
            if (bWildcard)
            {
                str     = str.Replace("*", "(.*)");
                str     = str.Replace("?", "(.)");
                m_regex = new System.Text.RegularExpressions.Regex("^" + str + "$");
                return(true);
            }

            /// Store it
            m_identifier = str;
            return(true);
        }