Beispiel #1
0
        /// <summary>
        /// Find out if it is a sql keyword.
        /// </summary>
        /// <param name="issql">The part to be check.</param>
        /// <param name="rtb">The richtextbox.</param>
        /// <param name="rtf">The rtf stream.</param>
        /// <param name="posstart">Position where the keyword starts in the richtextbox.</param>
        /// <param name="langsql">The sql language description.</param>
        /// <returns>The new rtf stream.</returns>
        private static string ValidatingSqlPart(string issql, RichTextBox rtb, string rtf, int posstart, HighlightLanguage langsql)
        {
            string sqlkeyword;
            bool   continufield = sqlfieldopen;

            if (issql.Length > 0)
            {
                for (int i = 0; i < issql.Length; i++)
                {
                    if (issql[i] == '`')
                    {
                        sqlfieldopen = !sqlfieldopen;
                        if (sqlfieldopen)
                        {
                            continufield = true;
                        }
                    }

                    if (continufield && !sqlfieldopen)
                    {
                        continufield = false;
                        rtf          = ColorText(rtb, rtf, posstart, i + 1, Settings.HighlightSQLColorField);
                    }
                }

                if (issql[0] == '"')
                {
                    if (issql.IndexOf('"', 1) > 0)
                    {
                        return(rtf);
                    }

                    sqlkeyword = issql.Substring(1, issql.Length - 1);
                }
                else
                {
                    sqlkeyword = issql;
                }
            }
            else
            {
                return(rtf);
            }

            // check if keyword is known SQL statement
            if (!string.IsNullOrEmpty(sqlkeyword))
            {
                if (langsql.FindKeyword(sqlkeyword.ToLower()))
                {
                    rtf = ColorText(rtb, rtf, posstart, issql.Length, Settings.HighlightSQLColorValidstatement);
                }
            }

            return(rtf);
        }
Beispiel #2
0
        /// <summary>
        /// Validate HTML attribute
        /// </summary>
        /// <param name="htmlattribute">Attribute of the HTML node to validate</param>
        /// <param name="rtb">Richtextbox with note content</param>
        /// <param name="rtf">The rtf stream.</param>
        /// <param name="attributestartpos">Startposition of the attribute within the htmlpart.</param>
        /// <param name="langhtml">The html language description.</param>
        /// <returns>The new rtf stream</returns>
        private static string ValidateHTMLAttribute(string htmlattribute, RichTextBox rtb, string rtf, int attributestartpos, HighlightLanguage langhtml)
        {
            if (htmlattribute == "/" || htmlattribute.Length < 1)
            {
                return(rtf);
            }

            char[]   chrs = new char[] { '=' };
            string[] attrsepnamevaleau = htmlattribute.Split(chrs, 2);
            bool     knowattr          = false;
            string   attrname          = attrsepnamevaleau[0];

            if (attrname.Length > 0)
            {
                if (attrname[0] == '/')
                {
                    attrname = attrname.Remove(0, 1);
                }
            }
            else
            {
                return(rtf);
            }

            if (langhtml.FindKeyword(attrname.ToLower()))
            {
                knowattr = true;
            }

            if (!knowattr)
            {
                // Wrong
                rtf = ColorText(rtb, rtf, attributestartpos, attrsepnamevaleau[0].Length, Settings.HighlightHTMLColorInvalid);
            }
            else
            {
                for (int i = 0; i < attrsepnamevaleau.Length; i++)
                {
                    if (i == 0)
                    {
                        if (knowattr)
                        {
                            // Good
                            rtf = ColorText(rtb, rtf, attributestartpos, attrsepnamevaleau[0].Length, Settings.HighlightHTMLColorValid);
                        }
                    }
                    else if (i == 1)
                    {
                        if (attrsepnamevaleau[1].StartsWith("\"") || attrsepnamevaleau[1].StartsWith("'"))
                        {
                            // is string
                            htmlstringpart = true;
                            int posstartstring = attributestartpos + attrsepnamevaleau[0].Length + 1; // +1 for '='
                            rtf = ColorText(rtb, rtf, posstartstring, attrsepnamevaleau[1].Length, Settings.HighlightHTMLColorString);
                            currentstringquote = attrsepnamevaleau[1][0];
                            int lastcharpos = attrsepnamevaleau[1].Length - 1;
                            if (attrsepnamevaleau[1][lastcharpos] == currentstringquote)
                            {
                                htmlstringpart = false;
                            }
                        }
                    }
                }
            }

            return(rtf);
        }
Beispiel #3
0
        /// <summary>
        /// Find out if it is a php keyword.
        /// </summary>
        /// <param name="isphp">A part to be check if this a php keyword.</param>
        /// <param name="rtb">The richtextbox.</param>
        /// <param name="rtf">The rtf stream.</param>
        /// <param name="posstart">The position in rtb where this keyword starts.</param>
        /// <param name="langphp">The PHP language description.</param>
        /// <returns>The new rtf stream.</returns>
        private static string ValidatingPhpPart(string isphp, RichTextBox rtb, string rtf, int posstart, HighlightLanguage langphp)
        {
            int posvar = -1;

            if (isphp.StartsWith(langphp.Commentstart))
            {
                comment = true;
            }

            if (commentline || comment)
            {
                rtf = ColorText(rtb, rtf, posstart, isphp.Length, Settings.HighlightPHPColorComment);
            }
            else
            {
                for (int curchr = 0; curchr < isphp.Length; curchr++)
                {
                    if (isphp[curchr] == '$')
                    {
                        // is variable
                        posvar = curchr;
                    }
                    else if (isphp[curchr] == '/')
                    {
                        if (curchr > 0)
                        {
                            if (isphp[curchr - 1] == '/')
                            {
                                // is commentline
                                commentline = true;
                                rtf         = ColorText(rtb, rtf, posstart + curchr - 1, isphp.Length - curchr + 1, Settings.HighlightPHPColorComment);
                            }
                        }
                    }
                    else if (isphp[curchr] == '"' || isphp[curchr] == '\'')
                    {
                        bool escaped = false;
                        if (curchr > 0)
                        {
                            if (isphp[curchr - 1] == '\\')
                            {
                                escaped = true;
                            }
                        }

                        if (!escaped)
                        {
                            phpstringpart = !phpstringpart;
                            if (!phpstringpart)
                            {
                                rtf = ColorText(rtb, rtf, posstart + curchr, 1, Settings.HighlightPHPColorString);
                                foreach (HighlightLanguage lng in langs)
                                {
                                    if (lng.Name == "sql")
                                    {
                                        lng.PosDocumentEnd = posstart + curchr + 1;
                                    }
                                }
                            }
                            else
                            {
                                foreach (HighlightLanguage lng in langs)
                                {
                                    if (lng.Name == "sql")
                                    {
                                        lng.PosDocumentStart = posstart;
                                    }
                                }
                            }
                        }
                    }
                    else if ((isphp[curchr] < 48 || isphp[curchr] > 57) && (isphp[curchr] < 65 || isphp[curchr] > 122))
                    {
                        if (isphp[curchr] != '\"' && isphp[curchr] != '\"')
                        {
                            if (posvar >= 0)
                            {
                                rtf    = ColorText(rtb, rtf, posstart + posvar, curchr - posvar, Settings.HighlightPHPColorDocumentstartend); // is variable
                                posvar = -1;
                            }
                        }
                    }
                    else if (curchr == isphp.Length - 1)
                    {
                        if (posvar >= 0)
                        {
                            // is variable
                            rtf = ColorText(rtb, rtf, posstart + posvar, isphp.Length, Settings.HighlightPHPColorDocumentstartend);
                        }
                    }

                    if (phpstringpart)
                    {
                        rtf = ColorText(rtb, rtf, posstart + curchr, 1, Settings.HighlightPHPColorString);
                    }
                }

                // check if keyword is known php function
                if (langphp.FindKeyword(isphp))
                {
                    rtf = ColorText(rtb, rtf, posstart, isphp.Length, Settings.HighlightPHPColorValidfunctions);
                }
            }

            if (isphp.EndsWith(langphp.Commentend))
            {
                comment = false;
            }

            return(rtf);
        }
Beispiel #4
0
        /// <summary>
        /// Highlight some text part on html split by spaces.
        /// </summary>
        /// <param name="ishtml">String without spaces. length needs to be >0</param>
        /// <param name="rtb">The richtextbox.</param>
        /// <param name="rtf">The rtf stream.</param>
        /// <param name="posstartpart">The start position in the richtextbox.</param>
        /// <param name="langhtml">The html language description.</param>
        /// <returns>The new rtf stream</returns>
        private static string ValidatingHtmlPart(string ishtml, RichTextBox rtb, string rtf, int posstartpart, HighlightLanguage langhtml)
        {
            ishtml = ishtml.ToLowerInvariant();
            List <string> attributes         = new List <string>(); // these attributes are within this part.
            List <int>    attributesstartpos = new List <int>();
            int           attrstartpos       = posstartpart;
            int           attrlen            = 0;
            bool          attrstartposset    = false;

            if (ishtml.StartsWith(langhtml.Commentstart, StringComparison.Ordinal))
            {
                comment = true;
            }
            ////else if (ishtml.Equals(langhtml.Commentline))
            ////{
            ////    commentline = true;
            ////}

            if (!comment)
            {
                for (int c = 0; c < ishtml.Length; ++c)
                {
                    if (htmlstringpart)
                    {
                        if (ishtml[c] == currentstringquote)
                        {
                            rtf            = ColorText(rtb, rtf, posstartpart, c + 1, Settings.HighlightHTMLColorString); // +1 for '"' or '\'' itself too.
                            htmlstringpart = false;
                        }
                        else if (c == ishtml.Length - 1)
                        {
                            rtf = ColorText(rtb, rtf, posstartpart, c + 1, Settings.HighlightHTMLColorString); // +1 for space/enter
                        }
                    }
                    else
                    {
                        if (ishtml[c] == '<')
                        {
                            if (!attrstartposset)
                            {
                                attrstartpos = posstartpart + c + 1; // without <
                                attributesstartpos.Add(attrstartpos);
                                attrstartposset = true;
                            }

                            outerhtml = false;
                        }
                        else if (ishtml[c] == '>')
                        {
                            if (!outerhtml)
                            {
                                if (attrlen > 0)
                                {
                                    attributes.Add(rtb.Text.Substring(attrstartpos, attrlen));
                                    attrlen = 0;
                                }

                                attrstartposset = false;
                            }

                            outerhtml = true;
                        }
                        else
                        {
                            if (!outerhtml)
                            {
                                if (!attrstartposset)
                                {
                                    attrstartpos = posstartpart + c;
                                    attributesstartpos.Add(attrstartpos);
                                    attrstartposset = true;
                                }

                                attrlen++;
                                if (c == ishtml.Length - 1)
                                {
                                    attributes.Add(rtb.Text.Substring(attrstartpos, attrlen));
                                    attrlen = 0;
                                }
                            }
                        }
                    }
                }

                for (int nattr = 0; nattr < attributes.Count; nattr++)
                {
                    for (int i = 0; i < nattr; ++i)
                    {
                        attrstartpos += attributes[i].Length;
                    }

                    if (nattr < attributesstartpos.Count)
                    {
                        rtf = ValidateHTMLAttribute(attributes[nattr], rtb, rtf, attributesstartpos[nattr], langhtml);
                    }
                }
            }
            else
            {
                // is comment
                rtf = ColorText(rtb, rtf, posstartpart, ishtml.Length, Settings.HighlightHTMLColorComment);
            }

            if (ishtml.EndsWith(langhtml.Commentend, StringComparison.Ordinal))
            {
                comment = false;
            }

            return(rtf);
        }